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

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

View Full Document Right Arrow Icon
Tutorial 7: Binary Search Tree Short review on binary tree Tree traversals Binary Search Tree (BST) Properties FindKey FindMin/FindMax Insert/Delete For sorting?
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online