Homework Assignment 3


Due: Feb. 2 before class starts (now Feb. 4 by 5pm)


Assignment

  1. (30 points) Provide statements and proofs for the following:
    1. What is the minimum number of internal nodes for an improper binary tree with n nodes?
    2. What is the maximum number of internal nodes for an improper binary tree with n nodes?
    3. What is the minimum number of external nodes for an improper binary tree with n nodes?
    4. What is the maximum number of external nodes for an improper binary tree with n nodes?
    5. Let T be a proper binary tree with height h and n nodes. Show that log(n+1)-1 ≤ h ≤ (n-1)/2.
    6. For the prior question what structure of trees yield the upper and lower bounds?
  2. (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.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  3. (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.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  4. Bonus. (10 points) Two ordered trees T' and T" are said to be isomorphic if one of the following holds: Design and analyze an algorithm that tests whether two given ordered trees are isomorphic.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity