Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions