# List partition

Document Sample

```					                      List Partitioning, Inductive Thinking
(Nifty Examples in Discrete Mathematics – SIGCSE 2004 Workshop)

Below is a specification for the function h : int list  int  int list

h( [a1, a2, …., an], m ) = [b1, b2, . . . , bk , bk+1 , . . . , bn] such that
[b1, b2, . . . , bk , bk+1 , . . . , bn] is a permutation of [a1, a2, …., an]
and  i, 1  i  k, bi  m and  i, k+1  i  n, bi > m

a) Give one possible list that is returned by
h( [5,1,2,4,2,9,10,3,1,8], 5 )

b) Describe clearly in English what function h does.

c) Give the base (stopping) case for function h by filling in the
blanks h( ___, m ) = ____       Ans: h( [ ], m ) = [ ]

d) Describe in English what you would wish1 for?

Ans: The result returned by h( [a2, …., an] , m )

e) Complete the following skeleton definition for function h (here
a1:: [a2, …., an] = [a1, a2, …., an] ( prepend) and
[a1, a2, …., an-1] @ [ an ] = [a1, a2, …., an] (append)

fun h( [ ], m ) =
| h( a::rest, m ) = if a > m
then

else

1
“Wishful thinking” in the way Abelson and Sussman express it? Basically ??? oracle, etc

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 4 posted: 12/11/2011 language: pages: 1
How are you planning on using Docstoc?