Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Ocaml Language. Write a tail-recursive function split : a list -> a list * a list that takes a list and returns a pair

Use Ocaml Language.

Write a tail-recursive function split : a list -> a list * a list that takes a list and returns a pair of lists such that for all l, (fst (split l)) @ (snd (split l)) is a permutation of l. That is, it splits a list into two lists and returns a pair of the two lists. The lengths of the two lists should differ by at most one.

For example, split [1;2;3;4;5] can return ([1;2;3], [4;5]) or ([1;3;5], [2; 4]) or ([5;3], [4;2;1] but not ([], [1;2;3;4;5]) or ([1;2;3], [3;4;5]) or ([1], [5]).

The base code:

let split (l: 'a list) : 'a list * 'a list = raise ImplementMe ;;

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago