Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Computer Science SML. Please write this in SML, no other language will be accepted. Do not copy and paste from another answer. Problem The goal

image text in transcribed

Computer Science SML. Please write this in SML, no other language will be accepted. Do not copy and paste from another 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 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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago