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 tool chest has 950 N weight that acts through the midpoint of the chest. The chest is supported by feet at A and rollers at B.
Mazyrski [523]

Answer:

P > 142.5 N  (→)

the motion sliding

Explanation:

Given

W = 959 N

μs = 0.3

If we apply

∑ Fy = 0 (+↑)

Ay + By = W

If  Ay = By

2*By = W

By = W / 2

By = 950 N / 2

By = 475 N (↑)

Then  we can get F (the force of friction) as follows

F = μs*N = μs*By

F = 0.3*475 N

F = 142.5 N (←)

we can apply

P - F  > 0

P  > 142.5 N (→)

the motion sliding

6 0
3 years ago
Most of the world’s mixed economies are a combination of a __________ economy and a __________ economy.
Elena L [17]

Answer:

The correct option is;

D. Market...Command

Explanation:

In a mixed economy, socialism and capitalism are combined in the economic policy, such the economy allows ownership of and offers protection for private property as well as provision of certain degree of allowance of capital utilization by the private sector. The government of a country with a mixed economic system can disrupt, obstruct, or restrict the activities taking place in the economy in order to meet the social objectives of the country's.

5 0
3 years ago
Read 2 more answers
For each topic, find the total number of blurts that were analyzed as being related to the topic. Order the result by topic id.
photoshop1234 [79]

Answer:

Explanation: see attachment below

8 0
3 years ago
An L2 steel strap having a thickness of 0.125 in. and a width of 2 in. is bent into a circular arc of radius 600 in. Determine t
lesya692 [45]

Answer:

the maximum bending stress in the strap is 3.02 ksi

Explanation:

Given the data in the question;

steel strap thickness = 0.125 in

width = 2 in

circular arc radius = 600 in

we know that, standard value of modulus of elasticity of L2 steel is; E = 29 × 10³ ksi;

Now, using simple theory of bending

1/p = M/EI

solve for M

Mp = EI

M = EI / p ----- let this be equation 1

The maximum bending stress in the strap is;

σ = Mc / I -------let this be equation 2

substitute equation 1 into 2

σ = ( EI / p)c / I

σ = ( c/p )E

so we substitute in our values

σ = ( (0.125/2) / 600 )29 × 10³

σ = 0.00010416666 × 29 × 10³

σ = 3.02 ksi

Therefore, the maximum bending stress in the strap is 3.02 ksi

3 0
3 years ago
Which of the following has led to a safer and more prosperous global community within the last century? the Bronze Age composite
sattari [20]

Answer:

The bronze age

4 0
3 years ago
Read 2 more answers
Other questions:
  • The denominator of a fraction is 4 more than the numenator. If 4 is added to the numenator and 7 is added to the denominator, th
    15·1 answer
  • This is a blueprint drawing of the stage area at Millennium Park. The length of one square on the grid is equal to 5 feet. Accor
    14·1 answer
  • Pennfoster Trades Safety test. Would appreciate the help. Thank you in advance. Check the screenshots below for the questions I'
    8·1 answer
  • What is a shearing stress? Is there a force resulting from two solids in contact to which is it similar?
    6·1 answer
  • An air-conditioning system operates at a total pressure of 1 atm and consists of a heating section and a humidifier that supplie
    15·1 answer
  • The AGC control voltage: ___________
    6·1 answer
  • A motor vehicle has a mass of 1200kg and the road wheels have a radius of 360mm. The engine rotating parts have a moment of iner
    5·1 answer
  • PLEASE HELP!<br> I'm in the middle of a test and the teacher didn't go over the material!
    10·1 answer
  • Which cod is the best whoever has the best awnser gets brainliest​
    12·1 answer
  • A spherical metal ball of radius r_0 is heated in an oven to a temperature of T_1 throughout and is then taken out of the oven a
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!