Thursday, August 9, 2007

What's missing from this picture?

A friend was conducting an interview the other day and asked the applicant to write a program that traversed a tree in depth-first order. The applicant started by defining a class for the nodes in the tree:
class Node {
    int value;
    Node parent;
}


Well, it is certainly space efficient. Optimized for going up the tree, too.

No comments:

Post a Comment