Search Trees_Part_1

Search Trees_Part_1 - Search Trees Chapter 10 < 2 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Search Trees Chapter 10 < 2 1 CSE 2011 Prof. J. Elder 6 9 > 4= -1- 8 Last Updated: 3/3/10 6:14 PM Binary Search Trees A binary search tree is a binary tree storing key-value entries at its internal nodes and satisfying the following property: Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) key(v) key(w) The textbook assumes that external nodes are ‘placeholders’: they do not store entries (makes algorithms a little simpler) An inorder traversal of a binary search trees visits the keys in increasing order Binary search trees are ideal for dictionaries with ordered keys. 6 2 1 CSE 2011 Prof. J. Elder 9 4 8 -2- Last Updated: 3/3/10 6:14 PM Binary Search Tree All nodes in left subtree Any node All nodes in right subtree 38 25 51 17 4 31 21 CSE 2011 Prof. J. Elder 28 42 35 40 -3- 63 49 55 71 Last Updated: 3/3/10 6:14 PM Search: Loop Invariant Maintain a sub-tree. If the key is contained in the original tree, then the key is contained in the sub-tree. 38 key 17 25 51 17 4 CSE 2011 Prof. J. Elder 31 21 28 42 35 40 -4- 63 49 55 71 Last Updated: 3/3/10 6:14 PM Search: Define Step Cut sub-tree in half. Determine which half the key would be in. Keep that half. 38 key 17 25 51 17 4 If key < root, then key is in left half. CSE 2011 Prof. J. Elder 31 21 28 If key = root, then key is found -5- 42 35 40 63 49 55 71 If key > root, then key is in right half. Last Updated: 3/3/10 6:14 PM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

Search Trees_Part_1 - Search Trees Chapter 10 &amp;lt; 2 1...

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

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