Algorithms and OOD (CSC 207 2013F) : EBoards

CSC207.01 2013F, Class 44: Trees, Generalized




Questions on the exam

Is the prologue up yet?

The prologue is now available at

Any hints on dealing with the functions as objects problem?

I'd suggest that you first write the functions assuming that all of the types are integers. Once you've gotten that working, you can start to think about the generic types.

Can you explain the Iterator.remove method?

It removes the value you've just seen.

Suppose we have the list a b c d and want to remove the b

Iterator<...> it = list.iterator();;  // Returns a;  // Returns b
it.remove();        // Removes b

If we pass all of the unit tests you provide, is our answer correct?

In general, yes. However, you still must take a reasonable approach. For example, you could simulate deletion in BSTs by putting null in as the value and then doing some clever maniuplations. But I specify that your really do have to delete nodes and rearrange the tree.

_What should we make anonymous and inner in the iteration problem?

Just the iterator. (You might make the node and cursor inner classes, but it's not necessary.)

Thinking about trees

Trees, abstracted


What methods should we provide? (assume we're trying to model hierarchies, not decision trees or partial orders)

An array-based implementation of binary trees

Here's a tree of the indices we'd get

            /      \
          1          2
        /   \      /   \
      3      4    5      6
     / \    / \  / \    / \
    7   8  9  10 11 12 13 14

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.