2009-04-27 20:41:58 UTC
Here are the first 10 lines, for example:
1 75 2 4
2 68 6 7
3 58 9 10
4 88 12 15
5 28 18 19
6 27 21 22
7 24 24 25
8 5 28 29
9 69 31 34
10 61 37 38
For example, the first line of the file is 1 75 2 4. It means that value of the node with key 1 is 75, key (line of file) of the left child of this node is 2, and key of right child is 4. Note: not all nodes in the file are part of the tree. Some lines in the file are there just to confuse you. What is the depth of this tree? (Depth is defined as the total number of nodes along the longest path.)
So... this is what I have so far (and its not much):
import java.util.Scanner;
import java.io.File;
class depth
{
public static void main(String[]args) throws Exception
{
Scanner sc = new Scanner(new File("tree.input"));
public int size()
{
return(size(root));
}
private int size(Node node)
{
if (node == null) return(0);
else
{
return(size(node.left) + 1 + size(node.right));
}
}
}
}
I'm not sure how to use the file to input my tree into the program. Can someone please help me get started working on this? If you want, you can do the whole problem and post it here. I have to find the depth of this tree with Java. Thank you! :)