Answered step by step
Verified Expert Solution
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
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 lines should be corrected and how?
(2) How many operations in terms of N does this algorithm execute in the worst case and the best case? 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, ,M) 2: I/This algorithm returns the medium number among all the numbers in an array. Out- > The array is the input put is the medium number found-the number at position [N/2] after sorting increasingly. 3: 4: for( ; -N/21; i++) do for (j=i+1 ; j=N; j++) do 5: 6: 7: 8: 9: 10: if A[il Swap end if end for 12:end for return A[i] 13: end procedureStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started