Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Assume we have this problem: Given a value n >= 2 and a list containing exactly n unique numbers called A,,A,, A find and

image text in transcribed
image text in transcribed
3. Assume we have this problem: "Given a value n >= 2 and a list containing exactly n unique numbers called A,,A,, A find and print out both the largest value in the list and the position in the list where that largest value occurred". The following is a sample algorithm to solve it: (figure 2.14 form your textbook). FIGURE 2.14 Get a value for n the size of the list Get values for A, A..., A, the list to be searched Set the value of largest so far to A Set the value of location to 1 Set the value of ito 2 While (is n) do If A > largest so far then Set largest so far to A Set location to i Add 1 to the value of i End of the loop Print out the values of largest so far and location Stop Algorithm to find the largest value in a list If the numbers in the list were not unique, would the algorithm report the first or the last occurrence of the largest number if it occurred several times? Explain your answer. (For example assume the list of numbers is: 2,5,6,20,2,5,7,8,10,20,9,10, you can see the largest number is 20 and it appears twice)

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions