Problem 1:
Write a function to generate all subsequences in a given list without using explicit recursion.
You are allowed to use only the following higher order functions:
zip, zipWith, take, takeWhile, drop, dropWhile, map, repeat, cycle, filter
You are also allowed to use functions from the module "Data.List".

Problem 2:
We can see that a given tree can be represented by a sequence of balanced parentheses.
For example, Consider the following tree, whose root is "ant"
ant 3
+bat 2
 +cat 1
  +data 3
  +eat 0
  +fat 0
  +wat 0
 
 +hat 2
 +inode 0
 +jpeg 0
+kneighbourhood 1
 +lamp 3
 +mat 0
 +nat 0
 +oat 0

+pat 3
+queue 2
 +rat 0
 +sat 0
+sata 0
+tata 0
Now this tree can be represented as shown below:
ant ( bat ( cat ( data ( eat () fat () wat ()) ) hat ( inode () jpeg () ) )
kneighbourhood ( lamp ( mat () nat () oat () ) )
pat ( queue ( rat () sat ()) sata () (tata) ) )
If we ignore all node data in this tree then it can be represented as shown below:
((((()()()))(()()))((()()()))((()())()()))
NodeChildren Information:
1. Root has 3 children,
2. Each of those 3 nodes at level 2 have 2, 1, and 3 children respectively.
3. Each of those 6 nodes at level 3 have 1, 2, 3, 2, 0, and 0 children respectively.
4. Each of those 8 nodes at level 4 have 3, 0, 0, 0, 0, 0, 0, and 0 children
respectively.
5. Each of those 3 nodes at level 5 have 0, 0, and 0 children respectively.
This NodeChildren Information can be written in a compact way as a list as shown below:
3,2,1,3,1,2,3,2,0,0,3,0,0,0,0,0,0,0,0,0,0
Let us call this list a NCI list.
For this NCI list the corresponding sequence of balanced parentheses is : ((((()()()))(()()))((()()()))((()())()()))
Some more sample inputoutput pairs are given below:
if input NCI list = []
then
output = ""

if input NCI list = [0]
then
output = "()"

if input NCI list = [1,0]
then
output = "(())"

if input NCI list = [1,2,0,1,0]
then
output = "(((())()))"

if input NCI list = [3,2,0,0,0,0]
then
output = "((()())()())"

if input NCI list = [3,2,1,3,1,2,3,2,0,0,3,0,0,0,0,0,0,0,0,0,0]
then
output = "((((()()()))(()()))((()()()))((()())()()))"

Note that [1], [2], [1,2] are NOT valid NCI lists. Verify why this is so.
Write a program that will generate a string of balanced parentheses corroesponding to the tree from a NCI list given as input.
If a invalid list comes as input, you should output the string "Error: invalid NCI list.".
Note that your program should generate the string strictly in lefttoright order. That is, while generating the balanced parentheses string, your program should only append element(s) to the list. There should be no modification to the partial list generated in between.
For instance,
if NCI list = [1,0]
then
output = "(())
But while generating this output, the string should be generated strictly as
(
((
(()
(())
i.e you cannot do something like
(
()
(()
(())

For illustration, the entire sequence of generated parentheses for the NCI list [3,2,1,3,1,2,3,2,0,0,3,0,0,0,0,0,0,0,0,0,0] is shown below:
Note that starting with an empty string, on each succeeding line, only appends are done with either '(' or ')' as needed.
""
"("
"(("
"((("
"(((("
"((((("
"((((()"
"((((()("
"((((()()"
"((((()()("
"((((()()()"
"((((()()())"
"((((()()()))"
"((((()()()))("
"((((()()()))(("
"((((()()()))(()"
"((((()()()))(()("
"((((()()()))(()()"
"((((()()()))(()())"
"((((()()()))(()()))"
"((((()()()))(()()))("
"((((()()()))(()()))(("
"((((()()()))(()()))((("
"((((()()()))(()()))((()"
"((((()()()))(()()))((()("
"((((()()()))(()()))((()()"
"((((()()()))(()()))((()()("
"((((()()()))(()()))((()()()"
"((((()()()))(()()))((()()())"
"((((()()()))(()()))((()()()))"
"((((()()()))(()()))((()()()))("
"((((()()()))(()()))((()()()))(("
"((((()()()))(()()))((()()()))((("
"((((()()()))(()()))((()()()))((()"
"((((()()()))(()()))((()()()))((()("
"((((()()()))(()()))((()()()))((()()"
"((((()()()))(()()))((()()()))((()())"
"((((()()()))(()()))((()()()))((()())("
"((((()()()))(()()))((()()()))((()())()"
"((((()()()))(()()))((()()()))((()())()("
"((((()()()))(()()))((()()()))((()())()()"
"((((()()()))(()()))((()()()))((()())()())"
"((((()()()))(()()))((()()()))((()())()()))"

Bonus problem:
Write a program to generate the NCI list that corresponds to the given tree.