# T7 - Tutorial 7 Binary Search Tree Short review on binary...

This preview shows pages 1–7. Sign up to view the full content.

Tutorial 7: Binary Search Tree Short review on binary tree Tree traversals Binary Search Tree (BST) Properties FindKey FindMin/FindMax Insert/Delete For sorting?

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

View Full Document
Short review on binary tree At most two children for each node A root node at the top (or the tree is empty) Nodes with no child = leaf nodes Left complete tree if : All levels are full except last level Last level filled from left to right
Tree traversals To visit each node of the tree Recursively visiting left and right sub-trees Pre-order (NLR) Current Node Node , Left sub-tree, Right sub-tree In-order (LNR) Left , Node Node , Right Post-order (LRN) Left , Right , Node Node

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

View Full Document
Tree traversals Examples Pre-order (NLR) 9 ,4,2,3,8,6,7 Always print the node first In-order (LNR) 2,4,3, 9 ,6,8,7 Print whenever return from left Post-order (LRN) 2,3,4,6,7,8, 9 Print whenever return from right
Tree traversals Question Question: Draw the binary tree whose tree traversal sequences are: A, B, D, C, E in Preorder and B, D, A, C, E in Inorder . 1. 1st element of preorder = A = root! 2. Note: given the root , inorder ( L N R ) has the left and right partitions: B,D , A , C,E B A D E C

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

View Full Document
Preorder: A , B, D , C, E and Inorder: B, D , A , C, E Next level on the left : A->B->D or A->D->B? 1. Preorder (N L R ), (i.e. A-> Left ) give B first, so the levels on the left is A->B->D D is left or right child of B? 1.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/22/2008 for the course CS 105 taught by Professor Woo during the Spring '08 term at HKUST.

### Page1 / 30

T7 - Tutorial 7 Binary Search Tree Short review on binary...

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

View Full Document
Ask a homework question - tutors are online