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
If the 1550-lb boom AB, the 190-lb cage BCD, and the 169-lb man have centers of gravity located at points G1, G2 and G3, respect
Natasha2012 [34]

Answer:

hello the required diagram is missing attached to the answer is the required diagram

7.9954 kip.ft

Explanation:

AB = 1550-Ib ( weight acting on AB )

BCD = 190 - Ib ( weight of cage )

169-Ib = weight of man inside cage

Attached is the free hand diagram of the question

calculate distance x!

= cos 75⁰ = \frac{x^!}{10ft}

    x! = 10 * cos 75^{o} = 2.59 ft

calculate distance x

= cos 75⁰ = \frac{x}{30ft}

x = 30 * cos 75⁰ = 7.765 ft

The resultant moment  produced by all the weights about point A

∑ Ma = 0

Ma = 1550 * x! + 190 ( x + 2.5 ) + 169 ( x + 2.5 + 1.75 )

Ma = 1550 * 2.59 + 190 ( 7.765 + 2.5 ) + 169 ( 7.765 + 2.5 + 1.75 )

      = 4014.5 + 1950.35 + 2030.535

      = 7995.385 ft. Ib ≈ 7.9954 kip.ft

6 0
3 years ago
Looking back, I was sure that I was going to die that November afternoon. Tornado watches in Alabama are as common as eggs are f
yKpoI14uk [10]
The author uses forshawdow in this passage
4 0
3 years ago
Read 2 more answers
What have you learned about designing solutions? How does this apply to engineering? Think of some engineering solutions that st
Andrew [12]

Answer:

In engineering design, failure is expected. It helps you find the best solutions before implementing them in the “real world”. Having a prototype fail is a GOOD thing, because that means you have learned something new about the problem and potential solutions.

Explanation:

4 0
2 years ago
A series circuit has 4 identical lamps. The potential difference of the energy source is 60V. The total resistance of the lamps
Alexxx [7]

Answer:

I=3A

Explanation:

From the question we are told that:

Number of lamps N=4

Potential difference V=60v

Total Resistance of the lamp is R= 20ohms

Generally the equation for Current I is mathematically given by

 I=\frac{V}{R}

 I=\frac{60}{20}

 I=3A

8 0
3 years ago
According to the amortization table, Demarco and Tanya will pay a total of in interest over the life of their loan.
Ymorist [56]

Answer:

(Interest rate/number of payments)*$170000= interest for the first month.

Interest amounts for all the months of repayment plus $170000=Total loan cost

Explanation:

Interest is the amount you pay for taking a loan from a bank on top of the original amount borrowed.

Factors affecting how much interest is paid are; the principal amount, the loan terms, repayment schedule, the repayment amount and the rate of interest.

The interest paid=(rate of interest/number of payments to make)*principal amount borrowed.

You divide the interest with number of payments done in a year where monthly are divided by 12.Multiplying it by loan balance in the first month which is your principal amount gives the interest rate to pay for that month.

You new loan balance will be= Principal -(repayment-interest)

Do this for the period the loan should take.

Add all the interest amount to original borrowed amount to get total cost of the loan after the period of time.

8 0
3 years ago
Read 2 more answers
Other questions:
  • A type 3 wind turbine has rated wind speed of 13 m/s. Coefficient of performance of this turbine is 0.3. Calculate the rated pow
    12·1 answer
  • A certain metal has a resistivity of 1.68 × 10-8 Ω ∙ m. You have a long spool of wire made from this metal. If this wire has a d
    14·1 answer
  • As an employee, who is supposed to provide training on the chemicals you are handling or come in contact with at work?
    5·2 answers
  • A misfire code is a type ____ DTC<br> A) 1 or 2<br> B) a or b<br> C) c or d<br> D l or ll
    15·1 answer
  • The diameter of a cylindrical water tank is Do and its height is H. The tank is filled with water, which is open to the atmosphe
    11·1 answer
  • When does someone's work on the Internet become copyrighted?
    15·1 answer
  • 8. Find the volume of the figure shown below: * V=L x W x H 7 cm 2 cm 2 cm​
    9·1 answer
  • What is the best way to collaborate with your team when publishing Instagram Stories from Hootsuite?
    14·1 answer
  • A conceptual issue can be resolved by which of the following?
    11·1 answer
  • Which of following is not malicious ?<br> Worm<br> Trogan Horse<br> Driver<br> Virus
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!