1
Department of Computer Science and Engineering
York University, Winter 2009
CSE 2011:
Assignment 3
Due Date - Saturday, May 23, 7pm!
Question 1
3-ary Tree
[35 points]
Let T be a full 3-ary tree (see Figure 1); that is, each parent has exactly 3 children. Let H(n) denote the
height of this tree, where n represents the number of nodes in the tree. Prove the following is true for
all full 3-ary trees:
H(n) = log
3
(2
⋅
n+1) -1
Hint: use induction!
Figure 1
Full 3-are tree
Answer:
Use induction.
Case:
n=1
H(1) = log
3
(2*1+1) – 1 = 0
- OK!
Case:
n=2
CANNOT BE! We cannot have 2 nodes in 3-ary tree.
New valid n:
When adding new set of nodes (at n+1 level), every node at level 1 will
now become the root of a sub-tree that is identical to the entire tree of
step n. Hence,
n
new
= 3*n
prev
+ 1
n
prev
= (n
new
-1)/3
Case: n=4
H(4) = log
3
(2*4+1) – 1 = 1
- OK!
Case: n
H(n) = H(n
prev
) + 1 =
= log
3
(2*n
prev
+1) -1 + 1 =
= log
3
(2*(n
new
-1)/3 + 1) =
= log
3
((2*(n
new
-1)+3)/3) =
= log
3
((2*n
new
+1) - 1

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*