Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem The goal of this lab is to implement quicksort in SML. The idea of quicksort was to pick a pivot element p, partition the

image text in transcribed

Problem The goal of this lab is to implement quicksort in SML. The idea of quicksort was to pick a pivot element p, partition the input in elements smaller than p and elements larger than p, and then recursively sort both parts. As pivot element, we will pick the median of the first, the middle, and the last element in a given list. To implement quicksort, implement the following functions. - A function last (1st) of type 'a list -> 'a which returns the last element of a given list. - A function middle (1st) of type 'a list -> 'a which returns the middle element of a given list. Hint: One way implement this functions is to create a helper function which recursively call itself with one list reduced by one item and the other reduced by two item until the smaller list is empty. - A function median(a, b, c) of type int * int * int -> int which returns the median of the given three elements. - A function partition(1st, p) of type int list * int -> int list * int list that partitions the given list into a list containing all elements smaller than or equal to p and a list p containing all elements larger than p. - A function quicksort(1st) of type int list -> int list which sorts a given list using quicksort and a pivot element as defined above. Do not use any pre-implemented functions of the form List.xyz(...)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago