subject

Modify the quicksort function (found in the file testquicksort. py), so that it calls insertionSort (found in the file algorithms. py) 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 5000 items. Then, adjust the threshold for using the insertion sort to determine an optimal setting File: testquicksort. py
Tests the quicksort algorithm
def quicksort(lyst):
quicksortHelper(lyst, 0, len(lyst) - 1)
def quicksortHelper(lyst, left, right):
if left < right:
pivotLocation = partition(lyst, left, right)
quicksortHelper(lyst, left, pivotLocation - 1)
quicksortHelper(lyst, pivotLocation + 1, right)
def partition(lyst, left, right):
# Find the pivot and exchange it with the last item
middle = (left + right) // 2
pivot = lyst[middle]
lyst[middle] = lyst[right]
lyst[right] = pivot
# Set boundary point to first position
boundary = left
# Move items less than pivot to the left
for index in range(left, right):
if lyst[index] < pivot:
swap(lyst, index, boundary)
boundary += 1
# Exchange the pivot item and the boundary item
swap (lyst, right, boundary)
return boundary
def swap(lyst, i, j):
"""Exchanges the items at positions i and j."""
# You could say lyst[i], lyst[j] = lyst[j], lyst[i]
# but the following code shows what is really going on
temp = lyst[i]
lyst[i] = lyst[j]
lyst[j] = temp
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()

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:00
I'm taking a class on how to make a movie, and it offers some apps that would be in the process. the thing is, i don't have any of those ha. if you have any tips on some apps i could use, that would be awesome. i don't have an iphone, so don't suggest any apps like imovie. i know that this is a weird question, but it would be super for me. : )
Answers: 2
question
Computers and Technology, 23.06.2019 03:00
What are the different parts of computer
Answers: 2
question
Computers and Technology, 24.06.2019 00:40
To maintain clarity and focus lighting might be needed
Answers: 2
question
Computers and Technology, 24.06.2019 02:10
Consider the usual algorithm to convert an infix expression to a postfix expression. suppose that you have read 10 input characters during a conversion and that the stack now contains these symbols: (5 points) | | | + | | ( | bottom |_*_| now, suppose that you read and process the 11th symbol of the input. draw the stack for the case where the 11th symbol is
Answers: 2
You know the right answer?
Modify the quicksort function (found in the file testquicksort. py), so that it calls insertionSort...
Questions
question
Biology, 10.11.2019 22:31
question
Mathematics, 10.11.2019 22:31
question
Computers and Technology, 10.11.2019 22:31
question
Mathematics, 10.11.2019 22:31
Questions on the website: 13722367