Can someone please help me identify the number of basic operations in this algor
ID: 3708315 • Letter: C
Question
Can someone please help me identify the number of basic operations in this algorith? And also average-case efficiency, aggregate efficiency and order of growth would be very helpful.
ALGORITHM MaxMin2(A[0.. , MaValue, MinValue) // Finds the maximum and minimum numbers in an array // Input parameter: An array A of n numbers, where n 21 I/ Output parameters: The largest and smallest numbers in the given 5 Max Value ? A[0] Min Value ? A[0] for i? l to n-1 do array, MaxValue and MinValue, respectively if Al> MaxValue Marl alue ? A[i] else if AMExplanation / Answer
In this algorithm we are trying to find maximum and minimum value in the array.
First initialize the max and min value with first element of array that is A[0].
Then loop will run from 1 to the length of array.
Compare each element of the array with the max and min value, If the current element of array is greater than max, then update max value with the array element. Similarly is the currrent array element is less than the min, then update the min value with array element.
Here linear traversal of array is being done, and for each element comparison is done. So number of basic oprations are n (size of array).
Here all the elements will be compared one by one, no matter what the case is. So best case, worst case and hence the average case efficiency will be O(n).