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
Bridge Reflection:
Nataliya [291]

Answer:

IT feels proud to be done making  a bridge

Explanation:

4 0
3 years ago
What invention would you argue most impacted mechanical engineering
Law Incorporation [45]

Answer:

The wheel

Explanation:

3 0
3 years ago
What is the correct answer A, B, C, D
Georgia [21]

Answer:

B a lever because it can move up and down

Explanation:

8 0
3 years ago
g a heat engine is located between thermal reservoirs at 400k and 1600k. the heat engine operates with an efficiency that is 70%
Bond [772]

Answer:

<em>Heat rejected to cold body = 3.81 kJ</em>

Explanation:

Temperature of hot thermal reservoir Th = 1600 K

Temperature of cold thermal reservoir Tc = 400 K

<em>efficiency of the Carnot's engine = 1 - </em>\frac{Tc}{Th}<em> </em>

eff. of the Carnot's engine = 1 - \frac{400}{600}

eff = 1 - 0.25 = 0.75

<em>efficiency of the heat engine = 70% of 0.75 = 0.525</em>

work done by heat engine = 2 kJ

<em>eff. of heat engine is gotten as = W/Q</em>

where W = work done by heat engine

Q = heat rejected by heat engine to lower temperature reservoir

from the equation, we can derive that

heat rejected Q = W/eff = 2/0.525 = <em>3.81 kJ</em>

6 0
3 years ago
What is a network? I'LL MARK BRAINLEST
Jobisdone [24]

Answer:

hsjeeieoj eu sou ku nahi u have UCC guide to buying it and I he was a temporary password for bees and u h ki tarah nahi to ye sab se jyada nahi hota nahi to kabhi bhi hai ki wo to sirf Tum nahi hota

7 0
3 years ago
Read 2 more answers
Other questions:
  • 5 cm circuit board dissipating 20 W of power uniformly is cooled by air, which approached the circuit board at 20C with a veloc
    10·1 answer
  • According to the HERARCHY of hazard control what sequence is specified for protecting workers from chemical hazards assume that
    7·1 answer
  • The following yield criteria are dependent on hydrostatic stress (a) Maximum distortion energy and maximum normal stress (b) Tre
    7·1 answer
  • Based on the hardness values determined in Part 1, what is the tensile strength (in MPa) for each of the alloys?
    10·1 answer
  • 4. What are the basic scientific principles the engineers who designed the digital scales would have needed to understand to des
    5·1 answer
  • An air-standard Diesel cycle has a compression ratio of 16 and a cutoff ratio of 2. At the beginning of the compression process,
    12·1 answer
  • What is the total resistance of three resistors in parallel with values of 2 ohms, 4 ohms, and 4 ohms?
    12·1 answer
  • Which statement is equivalent to the following? x = x * 2; x = x * x; x * 2; x *= 2; None of these
    6·1 answer
  • I will give Brainliest, please help. :)
    11·2 answers
  • What is the definition of gross axle weight rating?.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!