Lecture22 - Map as Vector Admin Todays topics ! Binary...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Admin Today’s topics Binary search trees, implementing Map as tree Reading Ch 13 Lecture #22 Map as Vector Unsorted Sorted Map() O(1) O(1) ~Map() O(1) O(1) add() O(N) O(N) getValue() O(N) O(logN) Overhead per entry none none A different strategy Sorting the Vector Provides fast lookup, but still slow to insert (because of shufFing) Does a linked list help? Easy to insert, once at a position But hard to ±nd position to insert. .. Will rearranging pointers help? Bashful Doc Dopey Grumpy Happy Sleepy Sneezy Bashful Doc Dopey Grumpy Happy Sleepy Sneezy Bashful Doc Dopey Grumpy Happy Sleepy Sneezy Voila. .. a binary search tree! Tree terminology Node, tree, subtree, parent, child, root, leaf Bashful Doc Dopey Grumpy Happy Sleepy Sneezy
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Trees in general Rules for all trees Recursive branching structure Single root node Every node reachable from root by unique path Examples Game tree Family tree Filesystem hierarchy Decomposition tree Binary, ternary, n-ary Binary search tree handouts cs106 ~julie cs143 exams slides Mon exams Wed midterm personal Binary search tree in specifc Binary tree Each node has at most 2 children Binary search tree Arranged for ef±cient search/insert All nodes in left subtree are less than root, all nodes in right subtree are greater 57 32 79 62 93 15 7 59 71 struct node { int val; node *left, *right; }; Operating on trees Many tree algorithms are recursive Not suprisingly! Handle current node, recur on subtrees
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/12/2011 for the course CS 108 taught by Professor Smith during the Spring '11 term at Central Mich..

Page1 / 6

Lecture22 - Map as Vector Admin Todays topics ! Binary...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online