Question: 2. Consider the following algorithm. Array A[0..n-1] contains n integers. Algorithm arrange (A) { n = A.last } for (i = 0 to n-2)
2. Consider the following algorithm. Array A[0..n-1] contains n integers. Algorithm arrange (A) { n = A.last } for (i = 0 to n-2) { for (j = 0 to n-2-i) { if (A[j+1] < A[j]) { swap (A, j, j+1) } } } a) What does this algorithm compute? Describe the strategy of the algorithm. b) Trace the steps of the algorithm on the following array: 71 59 28 23 30 8 c) Use the big-Oh notation to express its computational complexity. (30 marks)
Step by Step Solution
3.45 Rating (165 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
