Homework Assignment 3
Due: Feb. 2 before class starts (now Feb. 4 by 5pm)
Assignment
-
(30 points) Provide statements and proofs for the following:
- What is the minimum number of internal nodes for an improper binary
tree with
n
nodes?
- What is the maximum number of internal nodes for an improper binary
tree with
n
nodes?
- What is the minimum number of external nodes for an improper binary
tree with
n
nodes?
- What is the maximum number of external nodes for an improper binary
tree with
n
nodes?
- Let
T
be a proper binary tree with height h
and n
nodes. Show that
log(n+1)-1 ≤ h ≤ (n-1)/2.
- For the prior question what structure of trees yield the upper and
lower bounds?
-
(40 points) Show how to use an Euler tour traversal to compute the level
number
f(p)
, as defined in Section 8.3.2, of each position in a
binary tree T
.
- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
-
(30 points) Let
T
be a tree with n
positions.
Define the lowest common ancestor (LCA) between two
positions p
and q
as the lowest position in
T
that has both p
and q
as
descendants (where we allow a position to be a descendant of itself). Given
two positions p
and q
, describe and analyze an
efficient algorithm for finding the LCA of p
and
q
.
- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
-
Bonus.
(10 points)
Two ordered trees
T'
and T"
are said to be
isomorphic if one of the following holds:
- Both
T'
and T"
are empty.
- Both
T'
and T"
consist of a single
node.
- The roots of
T'
and T"
have the same number
k≥1
of subtrees, and the ith
such subtree of T'
is isomorphic to the
ith
such subtree of T"
for
i=1,...,k
.
Design and analyze an algorithm that tests whether two given ordered trees
are isomorphic.
- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity