You are on page 1of 3

FIT2004 Prac questions for week 6

1) Prove that the number of leaves (e) in a proper binary tree equals the
number of internal nodes (i) plus 1, that is, e = i + 1.
Base case: zero internal nodes, one external node:
1=0+1
TRUE
E(i) is a function which returns the number of external nodes in a proper
binary tree with i amount of internal nodes. Thus, E(0) = 1 (as shown
above).
Assume there exists a number k, in which E(k) = k + 1 (eg: k = 0)
If E(k+1) = (k+1) + 1 for any number k, then e = i + 1 is true for all
natural numbers.
E(k) = k + 1
E(k+1) = (k + 1) + 1

2) The following is a B-Tree with L=M=3. Show the steps for inserting 23 into
it.

1)

2)

3)

4)

5)
3) Give the recursive formula describing the number of nodes in a worst Case
AVL tree of height h and prove that this number can be defined via the
Fibonacci number.
Recursive formula:
NumNodes(h) = NumNodes(h -1) + NumNodes(h -2) + 1
1) add one to both sides:
NumNodes(h) + 1 = NumNodes(h -1) + NumNodes(h -2) + 2
2) Rephrase:
(NumNodes(h) + 1) = (NumNodes(h -1) + 1) + (NumNodes(h -2) + 1)
This gives the same recursive function as the Fibonacci sequence (F(n) =
F(n-1) + F(n-2)).
If we fix up the starting difference, we can see that NumNodes(h) + 1 =
F(n+2)

Giving:
NumNodes(h) = F(n+2) - 1
4) Consider the following red-black tree, Note that the heavy circles indicate
red nodes. Show the steps for inserting into this tree.

1)

2)

3)

4)
5) asd

You might also like