Homework Assignment 4


Assignment

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


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 one minute after class starts. Details:

Grading