Algorithms and OOD (CSC 207 2013F) : EBoards

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


Overview

Preliminaries

Admin

Questions on the exam

Is the prologue up yet?

The prologue is now available at http://bit.ly/207exam2pro

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();
it.next();  // Returns a
it.next();  // 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

Terminology:

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

               0
            /      \
          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 http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.