Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**in python please** Modify the quicksort function so that it calls insertion sort to sort any sublist whose size is less than 50 items. Compare

**in python please**

Modify the quicksort function so that it calls insertion sort to sort any sublist whose size is less than 50 items. Compare the performance of this version with that of the original one, using data sets of 50, 500, and 5,000 items. Then adjust the threshold for using the insertion sort to determine an optimal setting.

Use pythons time module to calculate the duration of the original quicksort version and the modified version. Do this for 3 different data sets of 50, 500, and 5000 items. These datasets are not going to be provided, so you have to come up with them. You can use pythons random module to help come up with the random item. Experiment with a different threshold value for the size of the sublist that indicates a switch to insertion sort, and report which value was optimal.

Here is quicksort function, with indents and copyable:

Thank you!!

image text in transcribedimage text in transcribed

def quicksort(lyst): quicksortHelper(lyst, 0, len(lyst) - 1) def quicksortHelper(lyst, left, right): if left

# Earlier definition of the swap function goes here import random def main(size = 20, sort = quicksort): lyst = [] for count in range(size): lyst.append(random.randint(1, size + 1)) print(lyst) sort(lyst) print(lyst) if name == " main ": main()

\#Earlier definition of the swap function goes here import random def main(size =20, sort = quicksort): lyst=[] for count in range(size): lyst.append(random. randint(1, size +1 )) print(lyst) sort(lyst) print(lyst) if name =" main ": main()

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions