Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will design and implement a (n) algorithm that will simultaneously find the largest and second largest elements (integers) in an array.

image text in transcribed

In this assignment, you will design and implement a (n) algorithm that will simultaneously find the largest and second largest elements (integers) in an array. Note that the second largest element should be distinctly smaller than the largest element. You should also adhere to the following restrictions. (1) You should traverse through the array ONLY ONCE. (2) The array could have both positive and negative elements. So, you should NOT initialize any temporary variables to very small negative values as part of your algorithm. (3) You should NOT make any assumption regarding the values of the elements and their distribution in the array. Note: Failure to adhere to the above restrictions and/or designing an algorithm whose time complexity is greater than (n) will result in a score of ZERO. Submission (Canvas) Submit items 1, 2, 3, 4 and 6 together as one PDF file Submit the C++ code (item 5) as a separate file 1) (10 pts) A pseudo code of the algorithm 2) (10 pts) Explain the working of the algorithm on your own in at least 150 words. 3) (10 pts) Analyze the time complexity of the algorithm and show that it is (n). 4) (15 pts) Show the working of the algorithm with the following two types of example arrays: (a) An example array of 10 integers that need to have the largest integer appearing at least twice. (b) An example array with the largest integer and second largest integer as respectively the first and last element in the array. 5) (50 pts) A C++ code of the algorithm with the array of size 10 and range: 1 to 50) randomly generated using the srand(NULL) and rand(% max Value functions. 6) (5 pts) Two screenshots of the execution of your C++ code

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

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago

Question

6. Have you used solid reasoning in your argument?

Answered: 1 week ago