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
Why is it important to follow the engineering design process before building a prototype
Nataly [62]

Answer:

learn from their mistakes

Explanation:

and so u could do better next time

4 0
2 years ago
Two technicians are discussing the intake air temperature (IAT) sensor. Technician A says that the computer uses the IAT sensor
mart [117]

Both the technicians are correct.

Explanation

Intake air temperature sensor is used in engines of vehicles to monitor the temperature of air entering the engine.

They are basically made of thermistors whose electrical resistance changes according to temperature.

Depending upon the reading and accuracy of intake air temperature sensor, the power-train control module (PCM) will decide about the air and fuel mixture ratio in the engine.

The hot air in engine requires less fuel to operate the engine parts while cold air requires more fuel to operate the engine.

The ratio of air and fuel mixture should be maintained in the engine and it is done by PCM only after getting the input from IAT. So technician B is saying correct.

Also the IAT works as a backup to support the engine coolant temperature sensor by the computer.

As the IAT checks the temperature of outside air, it will help to change the coolant temperature of the engine based on the environment.

Thus technician A is also correct. So both the technicians are correct.

6 0
3 years ago
A cylindrical specimen of a titanium alloy having an elastic modulus of 107 GPa (15.5 × 106 psi) and an original diameter of 3.7
Keith_Richards [23]

Answer:

the maximum length of specimen before deformation is found to be 235.6 mm

Explanation:

First, we need to find the stress on the cylinder.

Stress = σ = P/A

where,

P = Load = 2000 N

A = Cross-sectional area = πd²/4 = π(0.0037 m)²/4

A = 1.0752 x 10^-5 m²

σ = 2000 N/1.0752 x 10^-5 m²

σ = 186 MPa

Now, we find the strain (∈):

Elastic Modulus = Stress / Strain

E = σ / ∈

∈ = σ / E

∈ = 186 x 10^6 Pa/107 x 10^9 Pa

∈ = 1.74 x 10^-3 mm/mm

Now, we find the original length.

∈ = Elongation/Original Length

Original Length = Elongation/∈

Original Length = 0.41 mm/1.74 x 10^-3

<u>Original Length = 235.6 mm</u>

5 0
3 years ago
Your study space does not need to be quiet as long as you can ignore any noise coming from the space true or false?
Makovka662 [10]

Answer:

False

Explanation:

When you're studying, you need to make sure that you can focus properly. This means that you shouldn't be hungry or too full and that you should be well-rested, in a quiet room with good lighting and no distractions. Noise is never good when you need to memorize something. Some people can partially ignore it as long as it isn't too loud, but it will begin to bother them eventually. That's why it's better to study in a quiet room.

3 0
2 years ago
Read 2 more answers
On a piece of paper, sketch the x-y stress state and the properly oriented principal stress state. Use the resulting sketch to a
stealth61 [152]

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step and very detailed solution of the given problem

6 0
3 years ago
Other questions:
  • 6. PVC boxes are primarily used in new construction because it is simple to
    11·1 answer
  • In a diesel engine, the fuel is ignited by (a) spark (c) heat resulting from compressing air that is supplied for combustion (d)
    14·1 answer
  • Describe the make-up of an internal combustion engine.<br> Pls answer quickly.
    5·1 answer
  • A manager who focuses on the employees who enable a company to do business is human resource management. True True False False
    7·1 answer
  • An aircraft component is fabricated from an aluminum alloy that has a plane strain fracture toughness of 30 . It has been determ
    5·1 answer
  • If an elevator repairer observes that cables begin to fray after 15 years, what process might he or she use to create a maintena
    11·1 answer
  • Coving is a curved edge between a floor and a wall.<br> O True<br> O False
    13·2 answers
  • Why dose bob not let humans touch him one and only Ivan
    8·1 answer
  • Which - type of service shop is least likely to provide service to all
    9·1 answer
  • Nec ________ covers selection of time-delay fuses for motor- overload protection.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!