Question: ( 2 0 points ) Quick Sort is a sub - quadratic sorting algorithm that inputs a list of comparable objects, picks an element from

(20 points) Quick Sort is a sub-quadratic sorting algorithm that inputs a list of comparable objects, picks an element from the list as the "pivot", partitions the list into two separate sub-lists (values less than pivot and values greater than pivot), and finally does this procedure recursively for each sub-list. The following function implements quick sort in F#:
let rec qsort:int list -> int list = function
|[]->[]
| x::xs -> let smaller =[for a in xs do if a<=x then yield a]
let larger =[for b in xs do if b>x then yield b]
qsort smaller @ [x] @ qsort larger
a.(2 points) Identify the base case of this recursive function.
b.(3 points) Which element of the input list is considered to be the pivot in each recursive call?
c.(8 points) Write the input list of every recursive call to qsort function when we want to sort the list of integers [5; 3; 7; 1; 10]
d.(7 points) Manipulate this function so that it sort a given list in decreasing order.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!