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:
    • 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.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity


General Instructions, Turning in assignments, and Grading

General Instructions

Turn in Instructions

Each assignment will be turned in in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean five minutes after class starts. Details:

Points