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
The metal control joints used to relieve stresses caused by expansion and contraction in large ceiling or wall expenses in inter
timurjin [86]

Answer:

It’s called Expansion Joints

6 0
3 years ago
A constant-head permeability test gives the following information: - Water flows horizontally through the soil sample. - The hei
Marysya12 [62]

Answer:

Complete answer to the question is explained in the attached files.please have a look on it.

Explanation:

5 0
3 years ago
I need ideas of usernames for a 2021 Jeep Wrangler Rubicon!!
rjkz [21]

Answer:

2021 super star wagon master

6 0
3 years ago
Argue the importance to society of incorporating green building into an engineer’s designs, with at least two examples.
klio [65]
It is important because now a days we all need help from engineers
3 0
3 years ago
__________ affect(s) the amount of air conditioning required.
Grace [21]

Answer:

Option D

All the above

Explanation:

Depending with the number of occupants in a building, the number of air conditioners required can either be increased or reduced. For instance, if the building is to be a classroom of over 50 students, 1 air-conditioner can't serve effectively. Similarly, the activity of occupants also dictate the amount of air conditioners required since if it's a gym room where occupants exercise often then the air conditioners required is different from if the room was to serve as a  lounge. The appliances that also operate in a room require that air conditioners be installed as per the heat that may be generated by the appliances.

5 0
4 years ago
Other questions:
  • What is the difference between a job and a profession
    9·1 answer
  • A minor road intersects a major 4-lane divided road with a design speed of 55mph and a median width of 8 feet. The intersection
    11·1 answer
  • A cast-iron tube is used to support a compressive load. Knowing that E 5 10 3 106 psi and that the maximum allowable change in l
    11·1 answer
  • A horizontal channel of height H has two fluids of different viscosities and densities flowing because of a pressure gradient dp
    5·1 answer
  • Early American rockets used an RC circuit to set the time for the rocket to begin re-entry after launch (true story). Assume the
    5·1 answer
  • The ventilating fan of the bathroom of a building has a volume flow rate of 32 L/s and runs continuously. If the density of air
    7·1 answer
  • What are the equipment requirements for windshields and side windows?
    13·1 answer
  • On July 23, 1983, Air Canada Flight 143 required 22,300 kg of jet fuel to fly from Montreal to Edmonton. The density of jet fuel
    8·1 answer
  • Is microwave man made
    5·2 answers
  • What is acid mine drainage
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!