Question: Write Code (and explain your code) in ML programming Language Recall that mergesort sorts a list by splitting it in two, sorting each half, then
Write Code (and explain your code) in ML programming Language Recall that mergesort sorts a list by splitting it in two, sorting each half, then merging the two sorted halves into one sorted whole. Here are some functions that do that. merge(x, y) merges the two sorted lists into one split(x) splits an unsorted list into a pair of unsorted lists, each half the size mergesort (x) sorts the list x Please finish following program by replacing??? with proper code. fun merge ([], y) = y merge (x, []) = x merge(a::x, b::y) = if a int list merge ([1, 4, 5], [2, 3, 4]); val it = [1, 2, 3, 4, 5] int list fun split ([1]) = ([], ()) split (a::[]) = ([a], []) split [a::b::y) (a::fst (split (y)), b:: snd (split (y))); val split = fn:'a list -- rightarrow 'a list split 'a list split ([7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7]); val it = ([7, 5, 3, 1, 3, 5, 7], [6, 4, 2, 2, 4, 6]): int list * int list fun mergesort ([]) = ??? mergesort ([a]) = ??? mergesort (x) = ??? mergesort ([4, 3, 2]); val it = (2, 3, 4): int list mergesort ([1, 3, 6, 3, 7, 3, 8, 9, 2, 5]); val it = [1, 2, 3, 3, 5, 6, 7, 8, 9): int list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
