Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following algorithm is proposed by Bob to find the medium number among all numbers in an integer array. Answer the following questions: (1) Is

image text in transcribedThe following algorithm is proposed by Bob to find the medium number among all numbers in an integer array. Answer the following questions: (1) Is the algorithm correct? If not which line or lines should be corrected and how? (2) How many operations in terms of size N does this algorithm execute in the worst case and the best case? Show your logic and steps on how to get your answers. Assume each basic operation costs one time unit. a.k.a., A=C=E=1

9. (20 pts) The following algorithm is proposed by Bob to find the medium number among all numbers in an integer array. Answer the following questions: (1) Is the algorithm correct? If not which line or lines should be corrected and how? (2) How many opera- tions in terms of size N does this algorithm execute in the worst case and the best case? Show your logic and steps on how to get your answers. Assume each basic operation costs one time unit. a.k.a., A=C=E=1. Algorithm 1 Find the medium number in an integer array 1: procedure MEDIUM(A[1,2,...,N]) The array is the input 2: //This algorithm returns the medium number among all the numbers in an array. Out- put is the medium number found at position [N/2] after sorted increasingly. 3: i=1 4: for (; i A[j] then m- A[i] A[i] - A[i] A[j- m Swap end if end for 12: end for return A[i] 13: end procedure (bonus 10 pts) Explain why the statement, "The running time of algorithm A is at least O(n)," is meaningless

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_2

Step: 3

blur-text-image_3

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

Intelligent Image Databases Towards Advanced Image Retrieval

Authors: Yihong Gong

1st Edition

1461375037, 978-1461375036

More Books

Students also viewed these Databases questions

Question

Show Theorem 3.3. Hint: Show that x1 f (x j r ) 1 r2 f (x j r 2).

Answered: 1 week ago