Please I want a detailed complete answers for each part.Then make sure you provide clear
picture(s) of soultions that I can read. Try making all numbers and letters clrearly readable easy
to recognize. You also can type it which I prefer so I can copy all later, paste them in Microsoft
Word to enlarge & edit if needed. Thanks for all :) 1. Sort the record 9, 34,17,6, 15, 3:8 by using
the following sorting techniques, respectively, 1) QuickSort with a good call for the first pivot
value 2) MergeSort 3) HeapSort (including the details for building 1st Heap, and all 6 heaps) 4)
Binsort (Choose Bins as: 0-9; 10-19, 20-29, 30-39) 5) Radix sort The details of each sorting step
should be ncluded The details of each sorting step should be included
Solution
QuickSort:
QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the
given array around the picked pivot. There are many different versions of quickSort that pick
pivot in different ways.
The key process in quickSort is partition(). Target of partitions is, given an array and an element
x of array as pivot, put x at its correct position in sorted array and put all smaller elements
(smaller than x) before x, and put all greater elements (greater than x) after x. All this should be
done in linear time
elements:
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 34 17 6 15 38
9 6 17 34 15 38
swapping 15 and 34
15 is choosing pivot
compare with i-1 value
Program
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first= 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 = [9,34,17,6,15,8]
quickSort(alist)
print(alist)
Mergesort:
MergeSort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for
the two halves and then merges the two sorted halves. The merge() function is used for merging
two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are
sorted and merges the two sorted sub-arrays into one. See following C implementation for
details.
9 34 17 6 15 38
divide two parts
9 34 17 6 15 38
divide separate parts
9 34 17 6 15 38
compare two elements in each section
9 34 17 6 15 38
compare section to section
9 17 34 6 15 38
compare two section
6 9 15 17 34 38
Merges two subarrays of arr[].
# First subarray is arr[l..m]
# Second subarray is arr[m+1..r]
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m
# create temp arrays
L = [0] * (n1)
R = [0] * (n2)
# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]
for j in range(0 , n2):
R[j] = arr[m + 1 + j]
# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second subarray
k = l # Initial index of merged subarray
while i < n1 and j < n2 :
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1
# Copy the remaining elements of L[], if there
# are any
while i < n1:
arr[k] = L[i]
i += 1
k += 1
# Copy the remaining elements of R[], if there
# are any
while j < n2:
arr[k] = R[j]
j += 1
k += 1
# l is for left index and r is right index of the
# sub-array of arr to be sorted
def mergeSort(arr,l,r):
if l < r:
# Same as (l+r)/2, but avoids overflow for
# large l and h
m = (l+(r-1))/2
# Sort first and second halves
mergeSort(arr, l, m)
mergeSort(arr, m+1, r)
merge(arr, l, m, r)
Output:
Heapsort:
def heapsort( aList ):
# convert aList to heap
length = len( aList ) - 1
leastParent = length / 2
for i in range ( leastParent, -1, -1 ):
moveDown( aList, i, length )
# flatten heap into sorted array
for i in range ( length, 0, -1 ):
if aList[0] > aList[i]:
swap( aList, 0, i )
moveDown( aList, 0, i - 1 )
def moveDown( aList, first, last ):
largest = 2 * first + 1
while largest <= last:
# right child exists and is larger than left child
if ( largest < last ) and ( aList[largest] < aList[largest + 1] ):
largest += 1
# right child is larger than parent
if aList[largest] > aList[first]:
swap( aList, largest, first )
# move down to largest child
first = largest;
largest = 2 * first + 1
else:
return # force exit
def swap( A, x, y ):
tmp = A[x]
A[x] = A[y]
A[y] = tmp
BinSort:
Time Complexity of

Please I want a detailed complete answers for each part.Then make.pdf

  • 1.
    Please I wanta detailed complete answers for each part.Then make sure you provide clear picture(s) of soultions that I can read. Try making all numbers and letters clrearly readable easy to recognize. You also can type it which I prefer so I can copy all later, paste them in Microsoft Word to enlarge & edit if needed. Thanks for all :) 1. Sort the record 9, 34,17,6, 15, 3:8 by using the following sorting techniques, respectively, 1) QuickSort with a good call for the first pivot value 2) MergeSort 3) HeapSort (including the details for building 1st Heap, and all 6 heaps) 4) Binsort (Choose Bins as: 0-9; 10-19, 20-29, 30-39) 5) Radix sort The details of each sorting step should be ncluded The details of each sorting step should be included Solution QuickSort: QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways. The key process in quickSort is partition(). Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. All this should be done in linear time elements: 9 34 17 6 15 38 9 34 17 6 15 38 9 34 17 6 15 38 9 34 17 6 15 38 9 34 17 6 15 38 9 34 17 6 15 38 9 6 17 34 15 38 swapping 15 and 34 15 is choosing pivot compare with i-1 value Program def quickSort(alist): quickSortHelper(alist,0,len(alist)-1) def quickSortHelper(alist,first,last):
  • 2.
    if first= pivotvalueand 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 = [9,34,17,6,15,8] quickSort(alist) print(alist) Mergesort: MergeSort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one. See following C implementation for details. 9 34 17 6 15 38 divide two parts 9 34 17 6 15 38 divide separate parts 9 34 17 6 15 38 compare two elements in each section 9 34 17 6 15 38 compare section to section 9 17 34 6 15 38 compare two section 6 9 15 17 34 38 Merges two subarrays of arr[]. # First subarray is arr[l..m] # Second subarray is arr[m+1..r]
  • 3.
    def merge(arr, l,m, r): n1 = m - l + 1 n2 = r- m # create temp arrays L = [0] * (n1) R = [0] * (n2) # Copy data to temp arrays L[] and R[] for i in range(0 , n1): L[i] = arr[l + i] for j in range(0 , n2): R[j] = arr[m + 1 + j] # Merge the temp arrays back into arr[l..r] i = 0 # Initial index of first subarray j = 0 # Initial index of second subarray k = l # Initial index of merged subarray while i < n1 and j < n2 : if L[i] <= R[j]: arr[k] = L[i] i += 1 else: arr[k] = R[j] j += 1 k += 1 # Copy the remaining elements of L[], if there # are any while i < n1: arr[k] = L[i] i += 1 k += 1 # Copy the remaining elements of R[], if there # are any while j < n2: arr[k] = R[j] j += 1 k += 1 # l is for left index and r is right index of the
  • 4.
    # sub-array ofarr to be sorted def mergeSort(arr,l,r): if l < r: # Same as (l+r)/2, but avoids overflow for # large l and h m = (l+(r-1))/2 # Sort first and second halves mergeSort(arr, l, m) mergeSort(arr, m+1, r) merge(arr, l, m, r) Output: Heapsort: def heapsort( aList ): # convert aList to heap length = len( aList ) - 1 leastParent = length / 2 for i in range ( leastParent, -1, -1 ): moveDown( aList, i, length ) # flatten heap into sorted array for i in range ( length, 0, -1 ): if aList[0] > aList[i]: swap( aList, 0, i ) moveDown( aList, 0, i - 1 ) def moveDown( aList, first, last ): largest = 2 * first + 1 while largest <= last: # right child exists and is larger than left child if ( largest < last ) and ( aList[largest] < aList[largest + 1] ): largest += 1 # right child is larger than parent if aList[largest] > aList[first]: swap( aList, largest, first ) # move down to largest child first = largest; largest = 2 * first + 1 else:
  • 5.
    return # forceexit def swap( A, x, y ): tmp = A[x] A[x] = A[y] A[y] = tmp BinSort: Time Complexity of