Question: Instructions The following is the code for the none optimized bubble sort: def bubbleSort(x): number_of_steps=0 for j in range(1,len(x)): for i in range(1,len(x)): number_of_steps +=

 Instructions The following is the code for the none optimized bubble
sort: def bubbleSort(x): number_of_steps=0 for j in range(1,len(x)): for i in range(1,len(x)):
number_of_steps += 1 if (x[i-1] > x[i]): x[i-1], x[i] = x[i], x[i-1]
return x, number_of_steps When doing the following run: > > > a
= [5, 4, 2, 1, 10, 3, 7, 6, 70, 8] >>>
a, steps = bubbleSort(a) >>> a [1, 2, 3, 4, 5, 6,
7, 8, 10, 70] >> > steps 81 Update the bubbleSort function

Instructions The following is the code for the none optimized bubble sort: def bubbleSort(x): number_of_steps=0 for j in range(1,len(x)): for i in range(1,len(x)): number_of_steps += 1 if (x[i-1] > x[i]): x[i-1], x[i] = x[i], x[i-1] return x, number_of_steps When doing the following run: > > > a = [5, 4, 2, 1, 10, 3, 7, 6, 70, 8] >>> a, steps = bubbleSort(a) >>> a [1, 2, 3, 4, 5, 6, 7, 8, 10, 70] >> > steps 81 Update the bubbleSort function so that it is optimized and runs in 30 steps for the above provided example 1 Use Bubble sort to sort the following Data 17, 2, 30,5 step 0: 17, 2, 30, 5 step 1: 2, 17, 30, 5 (compare [O] and [1], swap happens) step 2: Step 1 has been filled in for you. continue all the steps until the data is sorted. In each step mention what two indices have been compared and if a swap occurred or not. In the first case, a swap happens (6 Points) Enter your answer N What is the Big-O of: n^11 log(n) + n^3 + n^10 log(n^20) (3 Points) Enter your answer 3 What is the Big-O of the following code block: For(i=1; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!