Question: To be done in C++ Exercise 2: Designing and Implementing Algorithms Design and implement an algorithm that, when given a collection of integers in an

To be done in C++

Exercise 2: Designing and Implementing Algorithms

Design and implement an algorithm that, when given a collection of integers in an unsorted array, determines the third smallest number (or third minimum). For example, if the array consists of the values 21, 3, 25, 1, 12, and 6 the algorithm should report the value 6, because it is the third smallest number in the array. Do not sort the array.

To implement your algorithm, compose a function thirdSmallest that receives an array as a parameter and returns the third-smallest number. To test your function, compose a program that populates an array with random numbers and then calls your function.

Exercise 3: Recursion

The following problem is a variation of Exercise C-4.27 in the Exercises section of Chapter 4 in our textbook.

Implement a recursive function for computing the n-th Harmonic number:

Exercise 4: Sorting

In this week's lesson, the algorithms quicksort and bubblesort are described. In Sorting Algorithms (Links to an external site.) you can find the class ArrayList, where these sorting algorithms are implemented. Design a program that times both of them for various list lengths, filling the array lists with random numbers. Use at least 10 different list lengths, and be sure to include both small values and large values for the list lengths (it might be convenient to add a parameterized constructor to the class ArrayList so the size of the list can be set at the moment an ArrayList object is declared).

Design a table to record the times as follows.

List LengthBubblesort Time

(seconds)Quicksort Time

(seconds)

Regarding the efficiency of both sorting methods, what are your conclusions? In addition to the source code and a screenshot of the execution window, please submit a separate document with the table and your conclusions about the experiment.

Note: To time a section of your source code, this is it.

#include  using namespace std; int main() { start = chrono::steady_clock::now(); //add code to time here end = chrono::steady_clock::now(); chrono::duration timeElapsed = chrono::duration_cast>(end-start); cout << "Code duration: " << timeElapsed.count() << " seconds" << endl; }

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!