Answered step by step
Verified Expert Solution
Question
1 Approved Answer
To receive full credit for this lab, you need to use the cons operator, multiple function bodies, and let expressions. Each of the two problems
To receive full credit for this lab, you need to use the cons operator, multiple function bodies, and let expressions. Each of the two problems will:
Have function bodies
Use letinend in one function body
Be recursive in the letinend function body
Note that you will use the function that you write in the first problem to solve the second problem.
Write a function named split that takes as an argument a twotuple that consists of a list and a pivot value and returns a twotuple that contains two lists. The first list is composed of all the elements in the original list that are strictly less than the pivot value. The second list returned is composed of all the elements that are greater than or equal to the pivot value. The type of this function is : int list int int list int list
Hints:
What is the base case?
an empty list
What is the recursive case?
If you remove the first element, and recursively split the remaining elements according to the pivot, you can then use an if statement to place that removed item into the correct list.
Write a function named quicksort that takes a list as an argument. This function uses the quicksort algorithm to sort the list, and returns the sorted list. This function is of the following type: fn : int list int list.
a Remember that the quicksort algorithm works as follows:
i First, a pivot is chosen. For this problem, always choose the first element in the list as the pivot.
ii Then, the list without the pivot is split into two halves as described in problem so you can use that function here! iii. Then, those two haves are each recursively sorted, and recombined into a list, with the pivot in the middle. Hint: you can use the @ concatenation operator here.
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