Download presentation

Presentation is loading. Please wait.

Published byNaomi Norris Modified about 1 year ago

1
2014-T2 Lecture 25 School of Engineering and Computer Science, Victoria University of Wellington Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas Kuehne, VUW COMP 103 Marcus Frean finishing traversals, and introducing Binary Search Trees (I)

2
2 RECAP-TODAY RECAP Tree traversals TODAY iterative in-order traversals! (two ways to proceed...) Introduction to Binary Search Trees Using hierarchical access to unstructured data Reading: Chapter 17.1

3
3 in-order traversal? method A... D B H FCAI EG

4
4 in-order traversal? method B... D B H FCAI EG

5
5 Depth-First vs Breadth-First Depth-First: Visit one child and all of its descendants before its siblings May visit root before, after, or between its children +Requires only one branch to manage traversal! − May find “costly” results first, and may not find results at all (infinite search trees) Breadth-First (level-order): Visit nodes in order of increasing depth May choose nodes in a level in a specific order − Requires accumulation of levels to manage traversal +Finds minimal solutions and guarantees success!

6
6 Remember: Efficiency Challenge Sorted Arrays access: O(log(n)) modification:O(n) Linear Linked Structures access:O(n) modification:O(1) [provided we know the position] Can we have the best of both worlds? yes, using trees!

7
7 Divide & Conquer Strategy eliminate as many as possible in each step Toby Tiger Lea Lion Bully Bulldog Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Feline Canine Bird

8
8 Divide & Conquer Strategy eliminate as many as possible in each step what does this remind you of? can we improve on the below? >19 <19 >51 <10 >10 <51

9
9 Divide & Conquer Strategy use existing elements for decision nodes

10
10 Divide & Conquer Strategy use existing elements for decision nodes now we need less nodes can get “lucky” on the way down

11
11 Binary Search Again Searching “50” low mid hi

12
12 Binary Search Trees Properties For every node: all items in left subtree

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google