Question: Consider the following pseudocode: Algorithm moveDown (a) a is an array of numbers int i =1 n = a. length while (a[i] > a[2i] II
Consider the following pseudocode: Algorithm moveDown (a) a is an array of numbers
int i =1 n = a. length while (a[i] > a[2"i] II > a[2"i+1]) && 2'i+1 < n if a[2'il >= a(2'i +1] largest = 2"i else largest = 2"i + 1 temp = a[i] a[i] = a[largest] a[largest] = temp i = largest (a) (2 points) Determine the exact number of statements (i.e. use the statement counting approach) that are executed during one iteration of the while loop in the worst case. Your answer should be expressed in terms of fl (the length of the array) Show all calculations. (b) (5 points) Determine the exact number of times the while loop executes in the worst case. (c) (3 points) Determine the exact number of statements executed in the worst case by the whole algorithm. (d) (1 point) Identify an Active Operation (e) (2 points) Determine the exact number of times the active operation is executed. (f) (2 points) Express the answers to parts c) and e) in big-0 notation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
