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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started