Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 2100
Data Structures

Michael Goldwasser

Fall 2015

Dept. of Math & Computer Science

Homework Assignment 06

Trees

Contents:


Overview

Topic: Trees
Related Reading: Ch. 7. Most relevant for these questions will be 7.2.2, 7.2.3, and 7.3.6.
Due: Friday, 13 November 2015, 10:00am


Collaboration Policy

For this assignment, you must work individually.

Please make sure you adhere to the policies on academic integrity in this regard.


Problems to be Submitted (20 points)

  1. (5 points)

    For the tree in Figure 7.11 (on page 285), what order will nodes be visited during a postorder traversal?

  2. (5 points)

    Draw a (proper) binary tree T such that simultaneously,

  3. (5 points)

    The structure of a tree cannot be unambiguously reconstructed having only a preorder listing of its contents. Therefore, the output of the preorderPrint function on page 279 cannot be used to ambiguously reconstruct the tree. They suggest the parenPrint method on page 280 as a way to represent the structure of a tree unambiguously.

    However, for a proper binary tree the preorder listing of the contents does suffice if we also designate whether each node is internal or external. That is, consider the following pseodocode:

    void dump(const BinaryTree& T, const Position& p) {
       if (p.isExternal())
          cout << "0 " << *p << endl;;
       else {
          cout << "1 " << *p << endl;;
          dump(T, p.left());
          dump(T, p.right());
       }
    }      
          
    Draw a picture of the tree represented by the following output of such a dump.
    1 A
    1 B
    0 C      
    1 D
    0 E
    0 F
    1 G
    1 H
    0 I      
    0 J      
    0 K      
          

  4. (5 points)

    Creativity Exercise C-7.18(b) on page 315 of the text. Note well, you only need to do part (b) of that problem, producing a new rendering of the tree from Figure 7.20


Extra Credit

  1. (2 points)

    Creative Exercise C-7.25 on page 316 of the text.


Michael Goldwasser
CSCI 2100, Fall 2015
Last modified: Friday, 04 April 2014
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit