Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2: (10 marks) Consider the following code and answer the below questions def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1); for i in range(passnum): if alist[i]>alist[i+1]:

image text in transcribed
Question 2: (10 marks) Consider the following code and answer the below questions def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1); for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp alist = [35, 25, 42, 15, 38, 30,50] bubbleSort(alist) print(alist) a) What are the best, and worst case complexities of the Bubble-Sort algorithm? [2 marks] b) Explain why the complexity of the best case will be as similar as the worst case in the above implementation even if the input list is already ordered. [2 marks] c) List two disadvantage of the bubble-sort algorithm [2 marks] d) Write down the output of this code after 2 iterations. [4 marks]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago