Homework Assignment 4
Assignment
-
(50 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. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.
-
(50 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. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.
-
Bonus.
(10 points) Describe, in pseudocode, a nonrecursive method for performing an
inorder traversal of a binary tree in linear time.
- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.