Monday, April 20, 2009

Extra Credit Opportunity

Well, Mark has a couple ideas for extra credit:
1. Watch the competition online. Unfortunately, a professor broadcasting over the internet an encouragement to students to pull an all-nighter might be frowned upon in some societies. So, that wouldn't work.
2. Solve the last problem we did during the practice session. A summary of which follows. As with us, you aren't allowed to use online resources other than the Java API. (Though if you haven't had data structures, you might be allowed to look up more information on what a "tree" is.)
Ben's summary of the 4th problem during the practice session
A tree is a series of objects connected by lines. The objects are called nodes (or edges), and the lines are called vertices. You can think of this like cities (nodes) connected by roads (vertices). There is just one way to get from point A to point B (i.e. there are no cycles); in other words, if there is a road from A to B, there wouldn't be both roads from A to C and C to B. The roads go both ways (non-directed), so a road from A to B means there is a road from B to A.
You can break these trees up into subtrees. Each subtree is a tree. A tree (or subtree) can have only one node, but in this example, a tree (and subtree) cannot be empty (null). Here is an example:
Tree: Nodes: A, B, C; Vertices: A to B, B to C
Subtrees: A & B & C (A to B, B to C); A & B (A to B); B & C (B to C); A (no vertices); B (no vertices); C (no vertices)
A & C is not a subtree because there is no way to get from A to C without B.

Input:
You will be given a number "n" of nodes for a subtree. This will be followed by n-1 vertices, as per the sample input. The input will be terminated with n = 0. Do not process this case.
Nodes will be listed as numbers from 1 to n. Vertices will be two nodes, separated by a space, indicating a path between the two nodes.
(The sample input is the same case as explained in the above example.)

Output:
For each case, print the number of possible distinct subtrees possible from the given tree.

Sample Input:
3
1 2
2 3
0

Sample Output:
Case 1: 6

**The problem was of course was more detailed than this, and I apologize, especially for those of you new to trees. However, I need to get to bed at a decent schedule. Besides, this is extra credit for you (for us it was a practice to test the "system").
**For those of you not in CS courses (i.e. graduated), I'll send you a postcard or have something else for you if you solve this.
**Also, special extra bonus for those of you who can solve it in a more efficient algorithm than ours was (exponential time, for anyone who knows what that means).

4 comments:

  1. hmm... maybe mark and i will work on this tonight,

    ReplyDelete
  2. Hey, we hope to get up in the middle of the night (in Iowa) and see a balloon or two directly opposite St. Petersburg!!
    Good luck, guys!
    from John's mom and dad

    ReplyDelete
  3. Are there orange trees? I got one of those near my place.
    And I'd love a postcard, but have no chance at solving any of those problems.

    ReplyDelete
  4. I hear mark is giving extra credit to those who've graduated... can he apply that to my 171 class?? thanks.

    ReplyDelete