COMP1011 Exercises for Week 12
Computing 1A 05s2 Last updated Tue 19 Jul 2005 14:37
Mail cs1011@cse.unsw.edu.au

# Lab Exercises Week 12

## Trees

### Ex 1:

Recall the notion of a depth of a tree that we discussed in the lecture, which is the maximum distance between the root of a tree and any of its leaves. Implement a polymorphic function
```depthTree :: Tree a -> Int
```

which computes the depth of a tree. For example, we have

```Tree> depthTree Leaf
0
Tree> depthTree (Node 1 Leaf  Leaf )
1
Tree> depthTree (Node 2 Leaf (Node 3 Leaf Leaf))
2```
When you have completed the above exercises show them to your tutor for this week's core mark.

### Ex 2:

Implement a function reverseTree:: Tree a -> Tree a which reverses the order of the elements in the tree by swaping the left and the right subtree of each node.

```    4                               4
/ \                             / \
2   6              ===>         6   2
/   / \                         / \   \
1   5   7                       7   5   1
```
When you have completed the above exercises show them to your tutor for this week's advanced mark.