Question: 1)Write a C++ program that implement the following three algorithms A, B, C, and times them for various values of n. The program should display

1)Write a C++ program that implement the following three algorithms A, B, C, and times them for various values of n. The program should display a table of the run times of each algorithm for various value of n.

// Algorithm A

sum = 0

for i = 1 to n

Sum = sum + i

// Algorithm B

sum = 0

for i = 1 to n

{

for j = 1 to i

sum = sum + i

}

// Algorithm C

sum = n*(n+1)/2

2) Write a program to display the running time of Selection Sort and Merge Sort.

Search and download a C++ code of Selection Sort and Merge Sort from an online source.

Modify and test these sorts on arrays of various sizes. Arrays of the same size should contain identical entries to test each sort solution.

Use the function clock from to calculate the run time of each of the two sorts.

Include best / worst cases for each sort. (randomized data is preferable to test a big number of items)

Display a table of the overall run time, along with the number of comparisons and the number of swaps of each sort solution for an array of size n.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!