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
A heat engine operates between a source at 477°C and a sink at 27°C. If heat is supplied to the heat engine at a steady rate of
lara [203]

Answer:

T_C = 27+273.15 = 300.15 K

T_H = 477+273.15 = 750.15 K

And replacing in the Carnot efficiency we got:

e= 1- \frac{300.15}{750.15}= 0.59988 = 59.98 \%

W_{max}= e* Q_H = 0.59988 * 65000 \frac{KJ}{min}= 38992.2 \frac{KJ}{min}

Explanation:

For this case we can use the fact that the maximum thermal efficiency for a heat engine between two temperatures are given by the Carnot efficiency:

e = 1 -frac{T_C}{T_H}

We have on this case after convert the temperatures in kelvin this:

T_C = 27+273.15 = 300.15 K

T_H = 477+273.15 = 750.15 K

And replacing in the Carnot efficiency we got:

e= 1- \frac{300.15}{750.15}= 0.59988 = 59.98 \%

And the maximum power output on this case would be defined as:

W_{max}= e* Q_H = 0.59988 * 65000 \frac{KJ}{min}= 38992.2 \frac{KJ}{min}

Where Q_H represent the heat associated to the deposit with higher temperature.

4 0
3 years ago
Inspection with considering a variable uses gages to determine if the product is good or bad. True or False?
irina1246 [14]

Answer:A. 40% B.50% C. 60% Od 70%

Explanation:A. True B. False

4 0
3 years ago
Read 2 more answers
A solid cylindrical workpiece made of 304 stainless steel is 150 mm in diameter and 100 mm is high. It is reduced in height by 5
goblinko [34]

Answer:

45.3 MN

Explanation:

The forging force at the end of the stroke is given by

F = Y.π.r².[1 + (2μr/3h)]

The final height, h is given as h = 100/2

h = 50 mm

Next, we find the final radius by applying the volume constancy law

volumes before deformation = volumes after deformation

π * 75² * 2 * 100 = π * r² * 2 * 50

75² * 2 = r²

r² = 11250

r = √11250

r = 106 mm

E = In(100/50)

E = 0.69

From the graph flow, we find that Y = 1000 MPa, and thus, we apply the formula

F = Y.π.r².[1 + (2μr/3h)]

F = 1000 * 3.142 * 0.106² * [1 + (2 * 0.2 * 0.106/ 3 * 0.05)]

F = 35.3 * [1 + 0.2826]

F = 35.3 * 1.2826

F = 45.3 MN

7 0
3 years ago
Which type of modeling can create virtual designs that can save clients thousands of dollars?
swat32

Answer:

VR Prototyping

VR Prototyping Can Save you Thousands of Dollars.

Explanation:

there you go lad

8 0
3 years ago
In a CNC machining operation, the has to be moved from point (5, 4) to point(7, 2)along a circular path with center at (7,2). Be
notka56 [123]

Answer: hello your question is incomplete below is the complete question

answer:

N010 GO2 X7.0 Y2.0 15.0 J2.0  ( option 1 )

Explanation:

Given that the NC machining has to be moved from point ( 5,4 ) to point ( 7,2 ) along a circular path

GO2 = circular interpolation in a clockwise path

G91 = incremental dimension

<em>hence the correct option is </em>:

N010 GO2 X7.0 Y2.0 15.0 J2.0  

6 0
3 years ago
Other questions:
  • Water flows down a rectangular channel that is 1.2 m wide and 1 m deep. The flow rate is 0.95 m/s. Estimate the Froude number of
    15·1 answer
  • By efficiency, we generally mean the ratio of the desired output to the required input. That is, efficiency is a measure of what
    7·1 answer
  • A turboprop engine consists of a diffuser, compressor, combustor, turbine, and nozzle. The turbine drives a propeller as well as
    12·1 answer
  • Fuel Combustion and CO2 Sequestration [2016 Midterm Problem] Long-term storage of carbon dioxide in underground aquifers or old
    5·1 answer
  • What does it mean to wire solar cells in parallel vs. wiring them in series? I always get these switched around.​
    10·1 answer
  • Describe three parts of a fluid power system and the roles played by each to make the device work.
    8·1 answer
  • A lighthouse built at sea level is 170ft high from its top , the angle of depression of a buoy is 29 degrees . Find the distance
    10·1 answer
  • What can you add to a seatbelt ??<br> HELP ASAP
    15·1 answer
  • In order to lift a lighter object on the other side, a boy placed 155 N of
    6·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
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!