==========================================================
Problem 1
We have seen some representations for binary trees. Now consider another representation for binary trees.
If the input is: [(parent, child)]
[(ant,bat), (bat,cat), (cat,data), (data,eat), (data,fat), (ant,kneighbourhood), (kneighbourhood,lamp), (lamp,mat), (lamp,nat), (nat,oat), (kneighbourhood,pat), (pat,queue), (queue,rat), (queue,sat), (pat,tata), (bat,hat), (hat,inode), (hat,jpeg)]
Then the output should be: String
"ant\n+bat\n +cat\n  +data\n  +eat\n  +fat\n \n +hat\n +inode\n +jpeg\n+kneighbourhood\n +lamp\n  +mat\n  +nat\n  +oat\n  \n +pat\n +queue\n  +rat\n  +sat\n +tata\n"
The output string when displayed on a terminal might look as shown below:
ant
+bat
 +cat
  +data
  +eat
  +fat
 
 +hat
 +inode
 +jpeg
+kneighbourhood
+lamp
 +mat
 +nat
 +oat

+pat
+queue
 +rat
 +sat
+tata
Note the way the spaces, newlines and other characters are used to make this representation.
Write a program that takes a list of tuples representing a binary tree and will
generate an equivalent binary tree in the representation described above.
The name of your function should be: bin2text
==========================================================
Problem 2
Write a Haskell program to generate all possible distinct binary trees
of size n;
where the size of a binary tree is equal to number of nodes in it.
Two given binary trees are considered distinct if their shapes are different.
(Note that we pay no attention to the values of nodes to decide whether the
two given binary trees are distinct or not.)
For example, let us suppose, b1, b2 and b3 are binary trees each of size 3.
Let us suppose b1 is as shown below:
12
/
/
10
\
\
11
Let us suppose b2 is as shown below:
12
/
/
11
\
\
10
note that b1 and b2 are not distinct for our purpose; whereas b3, which is shown
below, is different w.r.t. both b1 and b2.
12
/
/
11
/
/
10
Hint: You may find Haskell data constructors useful in solving this problem.
Also, things from CMGT may be found to be useful.
The name of your function should be: genAllBin
==========================================================
Problem 2
Consider this new scheme of writing down natural numbers shown in the file
"schemeoutputsamples".
Therein given are a few of the sequences of natural numbers written as per
the rules of the scheme. Carefully observe how the sequences generate the
outputs.
Write a program that takes an integer, n, as its input and outputs the sequence
of the first n natural numbers as per the scheme discussed above.
The name of your function should be: newScheme
==========================================================