1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andrew11 [14]
3 years ago
10

(40 points) Program the following sorting algorithms: InsertionSort, MergeSort, and QuickSort. There are 9 test les uploaded for

you on D2L (under the same folder as the assignment), each containing a list of numbers. There are 3 les for each of the input sizes 10, 100, and 1000, and for each input size, there are 3 les that contain the same numbers, but arranged in di erent orders: sorted, sorted in reverse order, and random. Your program should read the input from the test les, sort the numbers in the le using each of the above sorting algorithms, and output the sorted numbers to the screen. You can use any standard programming language such as C, C++, Visual C++, C#, Java, Python.
Engineering
1 answer:
babunello [35]3 years ago
3 0

Answer:

Explanation:

MERGE SORT

#include<stdlib.h>

#include<stdio.h>

#include<string.h>

void merge(int arr[], int l, int m, int r)

{

int i, j, k;

int n1 = m - l + 1;

int n2 = r - m;

 

int L[n1], R[n2];

for (i = 0; i < n1; i++)

L[i] = arr[l + i];

for (j = 0; j < n2; j++)

R[j] = arr[m + 1+ j];

i = 0;

j = 0;

k = l;

while (i < n1 && j < n2)

{

if (L[i] <= R[j])

{

arr[k] = L[i];

i++;

}

else

{

arr[k] = R[j];

j++;

}

k++;

}

while (i < n1)

{

arr[k] = L[i];

i++;

k++;

}

while (j < n2)

{

arr[k] = R[j];

j++;

k++;

}

}

void mergeSort(int arr[], int l, int r)

{

if (l < r)

{

int m = l+(r-l)/2;

mergeSort(arr, l, m);

mergeSort(arr, m+1, r);

merge(arr, l, m, r);

}

}

void printArray(int A[], int size)

{

int i;

for (i=0; i < size; i++)

printf("%d ", A[i]);

printf("\n");

}

int main()

{

int arr[1000] = {0};

int arr_size =0;

int data;

char file1[20];

strcpy(file1,"data.txt");

FILE *fp;

fp = fopen(file1,"r+");

if (fp == NULL) // if file not opened return error

{

perror("Unable to open file");

return -1;

}

else

{

fscanf (fp, "%d", &data);    

arr[arr_size]=data;

arr_size++;

while (!feof (fp))

{  

fscanf (fp, "%d", &data);  

arr[arr_size]=data;

arr_size++;    

}

}

printf("Given array is \n");

printArray(arr, arr_size);

mergeSort(arr, 0, arr_size - 1);

printf("\nSorted array Using MERGE SORT is \n");

printArray(arr, arr_size);

return 0;

}

You might be interested in
An aluminum bar 125 mm long with a square cross section 16 mm on an edge is pulled in tension with a load of 66,700 N and experi
AfilCa [17]

Answer: the modulus of elasticity of the aluminum is 75740.37 MPa

Explanation:

Given that;

Length of Aluminum bar L = 125 mm

square cross section s = 16 mm

so area of cross section of the aluminum bar is;

A = s² = 16² = 256 mm²

Tensile load acting the bar p = 66,700 N

elongation produced Δ = 0.43

so

Δ = PL / AE

we substitute

0.43 = (66,700 × 125) / (256 × E)

0.43(256 × E) = (66,700 × 125)

110.08E = 8337500

E = 8337500 / 110.08

E = 75740.37 MPa

Therefore, the modulus of elasticity of the aluminum is 75740.37 MPa

4 0
2 years ago
⚠️Answer needed quick!!⚠️
Allisa [31]

Answer:

A

Explanation:

3 gifts

gift cost = x

$150 total to spend

$60 left after spending

5 0
3 years ago
Which option distinguishes the members of a software deployment process team most likely involved in the following scenario?
Alchen [17]

Answer:

A local bank, with several branches in three cities, requests changes to its mortgage calculation software.

5 0
3 years ago
What is the maximum thermal efficiency possible for a power cycle operating between 600P'c and 110°C? a). 47% b). 56% c). 63% d)
Anastasy [175]

Answer:

(b) 56%

Explanation:

the maximum thermal efficiency is possible only when power cycle is reversible in nature and when power cycle is reversible in nature the thermal efficiency depends on the temperature

here we have given T₁ (Higher temperature)= 600+273=873

lower temperature T₂=110+273=383

Efficiency of power cycle is given by =1-\frac{T2}{T1}

=1-\frac{383}{873}

=1-0.43871

=.56

=56%

5 0
3 years ago
In normal operation, a paper mill generates excess steam at 20 bar and 400◦C. It is planned to use this steam as the feed to a t
Keith_Richards [23]

Answer:

The maximum power that can be generated is 127.788 kW

Explanation:

Using the steam table

Enthalpy at 20 bar = 2799 kJ/kg

Enthalpy at 2 bar = 2707 kJ/kg

Change in enthalpy = 2799 - 2707 = 92 kJ/kg

Mass flow rate of steam = 5000 kg/hr = 5000 kJ/hr × 1 hr/3600 s = 1.389 kg/s

Maximum power generated = change in enthalpy × mass flow rate = 92 kJ/kg × 1.389 kg/s = 127.788 kJ/s = 127.788 kW

6 0
3 years ago
Other questions:
  • A rod is 2m long at temperature of 10oC. Find the expansion of the rod, when the temperature is raised to 80oC. If this expansio
    7·1 answer
  • A process involves the removal of oil and other liquid contaminants from metal parts using a heat-treat oven, which has a volume
    10·1 answer
  • A Carnot engine has a piston displacement volume of 7.5 liters. The volume at the beginning of heat addition is 1.0 liters, the
    14·1 answer
  • An air-conditioning system operates at a total pressure of 1 atm and consists of a heating section and a humidifier that supplie
    15·1 answer
  • Example 12: Write an algorithm and draw a flowchart to calculate
    12·1 answer
  • Work to be performed can come from the work package level of the work breakdown structure as well as other sources. Which of the
    11·1 answer
  • 1. Làm thế nào để đảm bảo tính khả thi của văn bản hành chính ?
    12·1 answer
  • Conclude from the scenario below which type of documentation Holly should use, and explain why this would be the best choice
    15·2 answers
  • How could angela use the puzzle to model semiconductors? as an n-type semiconductor with the pegs representing electrons and the
    14·1 answer
  • Can someone help me LA project pls :((
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!