Question: Consider the following sorting algorithm for an Array A[1..n]: Algorithm 2: BubbleSort(A) 1 for i:=1 ... n do 2 3 4 for j =

Consider the following sorting algorithm for an Array A[1..n]: Algorithm 2: BubbleSort(A) 1 for i:=1 ... n do

Consider the following sorting algorithm for an Array A[1..n]: Algorithm 2: BubbleSort(A) 1 for i:=1 ... n do 2 3 4 for j = 1... n-i do if A[i] > A[j] swap(A[i],A[i+1]) 1. Give an example execution of the algorithm. Use it to visualise yourself how the algo- rithm works. 2. Now show that the algorithm indeed sorts the array. 3. Analyse the algorithm's worst case running time. 4. What is the best-case running time of the algorithm? 5. Does the algorithm follow one of your already known design conepts? If yes, which one? 6. Find a simple way to improve/optimise the running time.

Step by Step Solution

3.32 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 Example Execution Lets consider an array A 42719 Pass 1 2 4 1 7 9 Comparison 4 2 swap 2 1 4 7 9 Co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!