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
What did August Comte contribute to sociology including positivism
Travka [436]

Answer:

Auguste Comte was the first to develop the concept of "sociology." He defined sociology as a positive science. Positivism is the search for "invariant laws of the natural and social world." Comte identified three basic methods for discovering these invariant laws, observation, experimentation, and comparison.

Explanation:

I hope it's help u :)

4 0
3 years ago
While discussing what affects the amount of pressure exerted by the brakes: Technician A says that the shorter the line, the mor
harina [27]

Answer:

Only Technician B is right.

Explanation:

The cylindrical braking system for a car works through the mode of pressure transmission, that is, the pressure applied to the brake pedals, is transmitted to the brake pad through the cylindrical piston.

Pressure applied on the pedal, P(pedal) = P(pad)

And the Pressure is the applied force/area for either pad or pedal. That is, P(pad) = Force(pad)/A(pad) & P(pedal) = F(pedal)/A(pedal)

If the area of piston increases, A(pad) increases and the P(pad) drops, Meaning, the pressure transmitted to the pad reduces. And for most cars, there's a pressure limit for the braking system to work.

If the A(pad) increases, P(pad) decreases and the braking force applied has to increase, to counter balance the dropping pressure and raise it.

This whole setup does not depend on the length of the braking lines; it only depends on the applied force and cross sectional Area (size) of the piston.

5 0
3 years ago
Can u say what’s this
tatuchka [14]

Answer:

particles of a solid object packed together

7 0
3 years ago
Read 2 more answers
Motor oil is responsible for
Lelechka [254]

Answer:

lubricating all moving parts in the engine

Explanation:

like the pistons, pushrods, and the crank

5 0
3 years ago
How do I get my son to do his work?
valentinak56 [21]

Answer:

Explanation:

Reward him if he does his homework/work

If he doesnt do his homework, take things that he loves off of him. and tell him if he does his homework/work he will get them things back

8 0
3 years ago
Other questions:
  • Which pendulum will.mobe faster​
    13·1 answer
  • You have designed a treatment system for contaminant Z. The treatment system consists of a pipe that feeds into a CSTR. The pipe
    8·1 answer
  • A long homogeneous resistance wire of radius ro = 5 mm is being used to heat the air in a room by the passage of electric curren
    15·1 answer
  • How can endurance athletes best delay muscle fatigue during training? a. By avoiding sports drinks during exercise b. By eating
    6·2 answers
  • What is a shearing stress? Is there a force resulting from two solids in contact to which is it similar?
    6·1 answer
  • How does an engine convert fuel into a useful form of energy
    6·1 answer
  • A logic chip used in a computer dissipates 3 W of power in an environment at 120°F, and has a heat transfer surface area of 0.08
    11·1 answer
  • The driver _______
    9·2 answers
  • Which Finance jobs can someone pursue with only a high school diploma? Check all that apply.
    10·2 answers
  • An earth fill, when compacted will occupy a net volume of 187,000 cy. The borrow material that will be used to construct this fi
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!