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 gas turbine operates with a regenerator and two stages of reheating and intercooling. Air enters this engine at 14 psia and 60
Rzqust [24]

Answer:

flow(m) = 7.941 lbm/s

Q_in = 90.5184 Btu/lbm

Q_out = 56.01856 Btu/lbm

Explanation:

Given:

- T_1 = 60 F = 520 R

- T_6 = 940 = 1400 R

- Heat ratio for air k = 1.4

- Compression ratio r = 3

- W_net,out = 1000 hp

Find:

mass flow rate of the air

rates of heat addition and rejection

Solution:

- Using ideal gas relation compute T_2, T_4, T_10:

                     T_2 = T_1 * r^(k-1/k)

                     T_2 = T_4 = T_10 = 520*3^(.4/1.4) = 711.744 R

- Using ideal gas relation compute T_7, T_5, T_9:

                     T_7 = T_6 * r^(-k-1/k)

                     T_7 = T_5 = T_9 = 1400*3^(-.4/1.4) = 1022.84 R

- The mass flow rate is obtained by:

                     flow(m) = W_net,out / 2*c_p*(1400-1022.84-711.744+520)

                     flow(m) = 1000*.7068 / 2*0.24*(1400-1022.84-711.744+520)

                     flow(m) = 7.941 lbm/s

- The heat input is as follows:

                     Q_in = c_p*(T_6 - T_5)

                     Q_in = 0.24*(1400 - 1022.84)

                     Q_in = 90.5184 Btu/lbm

- The heat output is as follows:

                     Q_out = c_p*(T_10 - T_1)

                     Q_out = 0.24*(711.744 - 520)

                    Q_out = 56.01856 Btu/lbm

                                           

                     

5 0
3 years ago
How are speed and acceleration related
erica [24]
R = distance

dr/dt speed or with a direction, velocity

d(dr/dt)/dt = the time derivative of the velocity is called acceleration.

Speed is a scalar. Acceleration is a vector.
6 0
3 years ago
Read 2 more answers
Which view of an architectural design displays the complex interior features of an object concealed by hidden lines
Klio2033 [76]

Answer:

Cutting-plane View

Explanation:

5 0
2 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
3 years ago
technician a uses a current output test to check ac generator output. technician b uses a voltage output test to check output. w
expeople1 [14]

Answer:

both

Explanation:

Both the technician are correct, ac generator output can be tested in both ways. The two ways are  current output test to check ac generator output. and  voltage output test to check output.

7 0
3 years ago
Other questions:
  • The statement that is NOT true about the difference between laminar and turbulent boundary layers is:1.the Reynolds number for a
    8·1 answer
  • A silicon carbide plate fractured in bending when a blunt load was applied to the plate center. The distance between the fractur
    11·1 answer
  • A circuit contains four 100 ohm resistors connected in series. If you test the circuit with a DMM you should read a total resist
    14·1 answer
  • Complete the following sentence.
    10·1 answer
  • What else will change, if you change the point of view
    10·1 answer
  • calculate force and moment reactions at bolted base O of overhead traffic signal assembly. each traffic signal has a mass 36kg,
    6·1 answer
  • How do you explain the application of regulations in locations containing baths, showers and electric floor heating, including t
    10·1 answer
  • Planetary gears require the armature to be offset via a gear housing that holds the starter drive.
    12·2 answers
  • Whats viruses c liver?
    14·2 answers
  • Describe the greatest power in design according to Aravena?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!