Compsci 201 Recitation 9 Professor Peck Jimmy Wei 3/21/2014

advertisement
Compsci 201 Recitation 9
Professor Peck
Jimmy Wei
3/21/2014
In this Recitation
• Trees practice
• Submit via Ambient this week!
Trees
• Snarf the code
• Draw the tree that is built from these lines of
code:
BST bst = new BST();
int[] data = { 6, 8, 2, 4, 1, 7, 5,
3 , 9 };
for (int i : data)
bst.add(i);
Questions
• How many leaves are on your tree?
• How many nodes are on level 2?
• Does your tree have a path that sums to 17?
• If so, what is the path?
• Does your tree have a path that sums to 10?
• If so, what is the path?
• What value is in the 5th node in your tree?
• Count nodes in order
Trees
• Complete the four methods in BST.java
•
•
•
•
numLeaves
levelCount
hasPathSum
findK
• Each method makes use of a recursive helper
function—you only need to write the helper,
and can leave the public method as is
• Submit via Ambient when complete!
Have a good weekend!
Don’t forget to submit!
Download