Menu

[Solved]10 Points Define Function Computes Product Integers M N N M Inclusive Use Function Define Q37198788

Must be written in ML programming language.

(10 points) Define a function which computes the product of all integers between m and n (with n >= m) inclusive. Use this fu

fun mergesort [[ I mergesort [a][a] merge sort [a,b] if mergesort L = b [a,b] else [b,a] then a < let val (M, N)split L in me

(10 points) Define a function which computes the product of all integers between m and n (with n >= m) inclusive. Use this function to define the function Cak (the number of combinations of n elements taken k by k), which is defined by 1. Test your code with sample input and report result 2· (10 points) Define a function rem duplicate: ‘ ‘ a list-> ‘ ‘a list which takes in input a list and removes all the duplicates. Test your code with sample input and report result Examples: rem duplicate [ rem duplicate [1,2,1] – [1,2] rem duplicate [“a”, “a”, “a”] [“a”] rem duplicate [[1], [1,2], [1,2,3], [1,2],[4,5]] = 3. (30 points) Here is an SML mergesort program fun merge ([], yS) Ys merge (xs, [ ] ) = xs merge (x::xs, y:ys) = if x < y then x: :merge (xs, y: :ys) else y: :merge (x: :xs, ys) fun split [] I split [a] split (a: :b: :cs) val = let split cs in (M,N) end fun mergesort [[ I mergesort [a][a] merge sort [a,b] if mergesort L = b [a,b] else [b,a] then a < let val (M, N)split L in merge (mergesort M, mergesort N) end Note that mergesort includes three base cases ([], [a], [a,b]) and all are handled correctly Suppose we delete the third line ofmerge sort, so that [a,b] s no longer handle as a base case. You can verify that this change makes no difference in the type of mergesort or in its behavior. Now suppose we also delete the second line of mergesort, leaving fun mergesort [ I mergesort L – let val (M,N) = split L in merge (mergesort M, mergesort N) end What effect does this change have on the type that SML infers for mergesort? Verify that whether updated mergesort works correctly by running on your system and explain your findings. Show transcribed image text (10 points) Define a function which computes the product of all integers between m and n (with n >= m) inclusive. Use this function to define the function Cak (the number of combinations of n elements taken k by k), which is defined by 1. Test your code with sample input and report result 2· (10 points) Define a function rem duplicate: ‘ ‘ a list-> ‘ ‘a list which takes in input a list and removes all the duplicates. Test your code with sample input and report result Examples: rem duplicate [ rem duplicate [1,2,1] – [1,2] rem duplicate [“a”, “a”, “a”] [“a”] rem duplicate [[1], [1,2], [1,2,3], [1,2],[4,5]] = 3. (30 points) Here is an SML mergesort program fun merge ([], yS) Ys merge (xs, [ ] ) = xs merge (x::xs, y:ys) = if x

Expert Answer


Answer to (10 points) Define a function which computes the product of all integers between m and n (with n >= m) inclusive. Use th… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *