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 driver counts 21 other vehicles using 3 EB lanes on one section of I-80 between her rented car and an overpass ahead. It turne
SVEN [57.7K]

Answer:

vehicle density =  28.205 veh/mile

flow rate =  0.909 veh/hr

Explanation:

given data

count n = 21

distance = 0.78 miles

speed = 52 mph

solution

we get here vehicle density that is express as

vehicle density = n ÷ distance    ...............1

vehicle density = ( 21 + 1 )  ÷ 0.78

vehicle density  k =  28.205 veh/mile

and

now we get here flow rate that is express as

flow rate = k × vs    .................2

flow rate = 28.205 × ( 52 × 0.00062 ÷ 1m )

flow rate =  0.909 veh/hr

6 0
3 years ago
If a signal is transmitted at a power of 250 mWatts (mW) and the noise in the channel is 10 uWatts (uW), if the signal BW is 20M
Bess [88]

Answer:

C = 292 Mbps

Explanation:

Given:

- Signal Transmitted Power P = 250mW

- The noise in channel N = 10 uW

- The signal bandwidth W = 20 MHz

Find:

what is the maximum capacity of the channel?

Solution:

-The capacity of the channel is given by Shannon's Formula:

                            C = W*log_2 ( 1 + P/N)

- Plug the values in:

                            C = (20*10^6)*log_2 ( 1 + 250*10^-3/10)

                            C = (20*10^6)*log_2 (25001)

                            C = (20*10^6)*14.6096

                           C = 292 Mbps

3 0
3 years ago
Stirrups are used in a concrete beam:_______
VMariaS [17]
The answer is E to increase the shear strength of the beam beyond that provided by the concrete
5 0
3 years ago
A cylindrical specimen of a hypothetical metal alloy is stressed in compression. If its original and final diameters are 19.636
luda_lava [24]

Answer:

The original length of the specimen is found to be 76.093 mm.

Explanation:

From the conservation of mass principal, we know that the volume of the specimen must remain constant. Therefore, comparing the volumes of both initial and final state as state 1 and state 2:

Initial Volume = Final Volume

πd1²L1/4 = πd2²L2/4

d1²L1 = d2²L2

L1 = d2²L2/d1²

where,

d1 = initial diameter = 19.636 mm

d2 = final diameter = 19.661 mm

L1 = Initial Length = Original Length = ?

L2 = Final Length = 75.9 mm

Therefore, using values:

L1 = (19.661 mm)²(75.9 mm)/(19.636 mm)²

<u>L1 = 76.093 mm</u>

5 0
3 years ago
What is the power system?
Inessa [10]

Answer: An electric power system is a network of electrical components deployed to supply, transfer, and use electric power.

Explanation:

4 0
4 years ago
Other questions:
  • List different types of Gears, Explain the fundamental law of Gearing, Explain the Spur Gear Terminology.
    13·1 answer
  • What are pneumatic tools powered by?
    9·1 answer
  • Assume you have a beam that is 15 feet long and carries a concentrated load of 900 pounds at a distance of 4 feet from R . React
    15·1 answer
  • A 75 ! coaxial transmission line has a length of 2.0 cm and is terminated with a load impedance of 37.5 j75 !. If the relative p
    9·1 answer
  • Suppose a student rubs a Teflon rod with wool and then briefly touches it to an initially neutral aluminum rod suspended by insu
    6·1 answer
  • ITS FOR DRIVERS ED!!
    13·2 answers
  • Two rods, with masses MA and MB having a coefficient of restitution, e, move along a common line on a surface, figure 2. a) Find
    8·1 answer
  • Any one be my sister​
    15·2 answers
  • Who do you contact to get your credit report?
    13·1 answer
  • From the top of a vertical cliff 80m high, the angles of depression of 2 buoys lying due west of the cliff are 23° and 15° respe
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!