Question
**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!!
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started