Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.

Similar presentations


Presentation on theme: "Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code."— Presentation transcript:

1 Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.

2 3 Topics 1.Some more on height 2.Tree Traversals 3.Doubly Linked Lists 4.Big O of recursive functions

3 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 )

4 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 )

5 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)

6

7 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

8 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)

9 How do we compute the Big O of recursive functions?

10 Solve the problems in RecurrenceRelationProblems.java A. B. C. D. E.


Download ppt "Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code."

Similar presentations


Ads by Google