Presentation on theme: "Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code."— Presentation transcript:
Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.
3 Topics 1.Some more on height 2.Tree Traversals 3.Doubly Linked Lists 4.Big O of recursive functions
Given a tree that’s height-balanced, what is its height? Number of nodes = 7 Height = 3 Number of nodes = 5 Height = 3 A.O(n) B.O(n log n) C.O(log n) D.O(n 2 )
What is the maximum amount of time it could take to insert a node in a binary search tree? How about find a node? H = tree height N = # of tree elements 1)O(H) 2)O(N) 3)O(N + H) 4)O(log H) 5)O(H 2 )
What is the maximum amount of time it could take to insert a node in a binary search tree? How about find a node? O(tree height)
Traversals Preorder (N L R): Inorder (L N R): Postorder (L R N): Read N L R as “first visit node, then visit left subtree, then vision right subtree” Go to “Quizzes/Tests” section of Sakai and find today’s classwork – fill it out
Onward! Go to the TreeNodeExample code from Monday’s class Try to write: 1.An iterative version of containsNode that assumes the tree is a binary search tree 2.An iterative version of containsNode that does not assume the tree is a binary search tree (hint: you’ll want a stack or queue)
How do we compute the Big O of recursive functions?
Solve the problems in RecurrenceRelationProblems.java A. B. C. D. E.