1. The quick sort uses _____________ to gain the same advantages as the merge sort, while not using additional storage
2. A quick sort first selects a value, which is called the ________. Although there are many different ways to choose the pivot value,we often just use the first item in the list.
3. The role of the pivot value is to assist The role of the pivot value is to ___________________-
4. Read the excerpt below on 'partitioning' and fill in the blanks
5. In the code shown below, it invokes a ________________________ quickSortHelper. quickSortHelper begins with the same base case as the merge sort.
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first<last:
splitpoint = partition(alist,first,last)
quickSortHelper(alist,first,splitpoint-1)
quickSortHelper(alist,splitpoint+1,last)
def partition(alist,first,last):
pivotvalue = alist[first]
leftmark = first+1
rightmark = last
done = False
while not done:
while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
leftmark = leftmark + 1
while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
rightmark = rightmark -1
if rightmark < leftmark:
done = True
else:
temp = alist[leftmark]
alist[leftmark] = alist[rightmark]
alist[rightmark] = temp
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
alist = [54,26,93,17,77,31,44,55,20]
quickSort(alist)
print(alist)
base function
binary function
recursive function
iterative function
6. Given the following list of numbers [14, 17, 13, 15, 19, 10, 3, 16, 9, 12] which answer shows the contents of the list after the second partitioning according to the quicksort algorithm?
[9, 3, 10, 13, 12, 14, 19, 16, 15, 17]
[9, 3, 10, 13, 12]
[9, 3, 10, 13, 12, 14]
[9, 3, 10, 13, 12, 14, 17, 16, 15, 19]
7. Given the following list of numbers [1, 20, 11, 5, 2, 9, 16, 14, 13, 19] what would be the first pivot value using the median of 3 method?
8. Which of the following sort algorithms are guaranteed to be O(n log n) even in the worst case?
9. The best case for quick sort occurs when the partition process always picks the middle element as pivot.
10. In the worst case, QuickSort recursively calls one subproblem with size 0 and other subproblem with size _____________