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]
2 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]2 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
Con una tasa de interés de 8% por año, ¿a cuánto equivalen $10 000 de hoy, a) dentro de un año, y b) hace un año?
Contact [7]

Answer:

que hces en eeuua

Explanation:

8 0
2 years ago
The pressure rise Ap associated with wind hitting a win- dow of a building can be estimated using the formula Ap-p(12/2), where
Harrizon [31]

Answer:

a. 430.944 pascal

b. 0.0625psi

c. 1.73008inH20

Explanation:

The pressure rise Ap associated with wind hitting a win- dow of a building can be estimated using the formula Ap-p(12/2), where p is density of air and V is the speed of the wind. Apply the grid method to calculate pressure rise for P-1.2 kg/m and V-60 mph. a. Express your answer in pascals. b. Express your answer in pounds-force per square inch (psi). c. Express your answer in inches of water column

checking the dimensional consistency

Dp=\frac{kg}{m^3} (\frac{m^2}{s^2} \\\frac{x}{y} \\\\\frac{kg}{ms^2} \\which s the same as\\ \frac{N}{m^2}

Dp=∈(\frac{v^2}{2} )

convert 1 mile to meter

1mile=1609m

1h=3600s

60mile/h=26.8m/s

slotting intpo the relation

Dp=1.2kg/m^3(\frac{26.8^2}{2} )

430.944kg/(ms^2)

which is the same as 430.944N/m^2

expressing in pascal.

We know that

1 pascal=1 N/m^2

430.944 pascal

2. 1 pascal=0.000145psi

answer=0.0625psi

3.1 pascal=0.00401inH20

answer=430.944*0.0040146

1.73008inH20

5 0
3 years ago
Satellite systems are not affected by atmospheric disturbances such as fog, smoke, electrical storms, precipitation, and clouds.
mamaluj [8]

The statement " Satellite systems are not affected by atmospheric disturbances such as fog, smoke, electrical storms, precipitation, and clouds" is <u>False</u>.

Define a satellite system.

A satellite system is a collection of gravitationally bound objects orbiting a planet, minor planet, sub-brown dwarf, rogue planet, or its barycenter. In general, it is a group of naturally occurring satellites (moons), though such systems can also include objects like circumplanetary disks, ring systems, moonlets, minor planet moons, and artificial satellites, any of which may also have their own satellite systems.

To learn more about a satellite system, use the link given
brainly.com/question/14156927
#SPJ4

6 0
8 months ago
The equilibrium fraction of lattice sites that are vacant in electrum (a silver gold alloy) at 300K C is 9.93 x 10-8. There are
IrinaK [193]

Answer:

the density of the electrum is 14.30 g/cm³

Explanation:

Given that:

The equilibrium fraction of lattice sites that are vacant in electrum  = 9.93*10^{-8}

Number of vacant atoms = 5.854 * 10^{15} \ vacancies/cm^3

the atomic mass of the electrum = 146.08 g/mol

Avogadro's number = 6.022*10^{23

The Number of vacant atoms = Fraction of lattice sites × Total number of sites(N)

5.854*10^{15} = 9.93*10^{-8}  × Total number of sites(N)

Total number of sites (N) = \dfrac{5.854*10^{15}}{9.93*10^{-8}}

Total number of sites (N) = 5.895*10^{22}

From the expression of the total number of sites; we can determine the density of the electrum;

N = \dfrac{N_A \rho _{electrum}}{A_{electrum}}

where ;

N_A = Avogadro's Number

\rho_{electrum} = density of the electrum

A_{electrum} = Atomic mass

5.895*10^{22} = \dfrac{6.022*10^{23}* \rho _{electrum}}{146.08}

5.895*10^{22} *146.08}= 6.022*10^{23}* \rho _{electrum}

8.611416*10^{24}= 6.022*10^{23}* \rho _{electrum}

\rho _{electrum}=\dfrac{8.611416*10^{24}}{6.022*10^{23}}}

\mathbf{  \rho _{electrum}=14.30 \ g/cm^3}

Thus; the density of the electrum is 14.30 g/cm³

7 0
3 years ago
Calculate moments about points A,B,C,D
poizon [28]

Answer:

24cm sureeeereereeeeee

3 0
2 years ago
Other questions:
  • A commercial refrigerator with refrigerant -134a as the working fluid is used to keep the refrigerated space at -30C by rejectin
    10·3 answers
  • The lift on a spinning circular cylinder in a freestream with a velocity of 30 m/s and at standard sea level conditions is 6 N/m
    7·1 answer
  • Please what is the name of this tool​
    9·2 answers
  • A 200 W vacuum cleaner is powered by an electric motor whose efficiency is 70%. (Note that the electric motor delivers 200 W of
    13·1 answer
  • 3. (20 points) Suppose we wish to search a linked list of length n, where each element contains a key k along with a hash value
    7·1 answer
  • Yall know what this is called?​
    15·1 answer
  • What are the specifications state that all work shall be done?
    10·1 answer
  • 6
    10·2 answers
  • If a 9V battery produces a current of 3 A through a load, what is the resistance of the load
    9·2 answers
  • Suppose a manager of a certain mining company wants to determine the weekly food expenditure of the company’s employees. if ther
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!