Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write bubble_sort(a) function to execute bubble sort algorithm, which is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements

 

1. Write bubble_sort(a) function to execute bubble sort algorithm, which is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements and swaps them if they are in the wrong order, until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. (10 marks) 2. Write optimized_bubble_sort(a) function which is an optimized version bubble sort algorithm that reduce the number of swaps and comparisons. (10 marks) 3. Write generate_unsorted_list(n) function which generates random unsorted list (an array) with 10,000 elements to test above mentioned algorithms. (5 marks) 4. Write code to calculate: (i) The Execution time for each algorithm, (ii) The saved execution time using optimized bubble sort algorithm in comparison to the bubble sort algorithm. (5 marks) For example, executing your entire program should return the following: Bubble Sort Algorithm execution time = 8.794462203979492 seconds. Optimized Bubble Sort Algorithm execution time = 0.0011148452758789062 seconds. Execution time saved using Optimized Bubble Sort Algorithm = 8.793347358703613 seconds. Hint: you can use the random integer "randint" and "time" modules in your solution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import random import time Bubble Sort Algorithm def bubblesorta n lena for i in rangen for j in rang... 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_2

Step: 3

blur-text-image_3

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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Algorithms questions

Question

Modify the proto-vEB structure to support duplicate keys.

Answered: 1 week ago

Question

Contrast efficiency and utilization.

Answered: 1 week ago

Question

How can long-term capacity requirements be determined?

Answered: 1 week ago