lec15 - 2/7/11 2/7/11 CS C341 / I S C361 Data Structures...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 2/7/11 Sundar B. CSIS, CS C341 / I S C361 Data Structures & Algorithms Dictionary Data Structures – Search Trees Binary Search Trees – Order Queries Balancing a Search Tree - Height Balance Property - AVL Tree - Example - Rotations - Time Complexity - Number of rotations for insert - Number of rotations for delete 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Binary Search Trees (BSTs) BSTs store data in order: i.e. if you traverse a BST such that for all nodes v, Visit all nodes in the left sub tree of v Visit v Visit all nodes in the right sub tree of v then you are visiting them in sorted order. This is referred to as in-order traversal 22
Background image of page 2
2/7/11 Sundar B. Binary Search Trees (BSTs) Revisiting delete (in an Ordered Dictionary): Deletion of an element with two non- empty subtrees required a pull-up operation. One way of pulling-up – find an element, say c, closest to the element to be deleted, say d How? overwrite d with c delete node (originally) containing c 33
Background image of page 3

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Binary Search Trees (BSTs) Revisiting delete (in an Ordered Dictionary): Here is the pullUpLeft procedure pullUpLeft(OrdDict toDel, OrdDict cur) { pre = toDel; while (cur->right != NULL) { pre=cur; cur=cur->right; } toDel->rootVal = cur->rootVal; if (cur->left==NULL) { prev->right = NULL; } else { prev->right = cur->left; } 44
Background image of page 4
2/7/11 Sundar B. Binary Search Trees – Order Queries Exercises: Write a procedure to find the minimum element in a BST. Write a procedure to find the maximum element in a BST Write a procedure to find the second smallest element in a BST. Write a procedure to find the kth smallest element in a BST. Write a procedure to find the element closest to a given element in a BST. 55
Background image of page 5

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Binary Search Tree - Complexity Time Complexity: Find, insert, delete # steps = Height of the tree Height of binary tree (by induction): Empty Tree ==> 0 Non-empty ==> 1 + max(height(left), height(right)) Balanced Tree – Best case Height = log(N) where N is the number of nodes Unbalanced Tree – Worst case 66
Background image of page 6
2/7/11 Sundar B. Height-balance property A node v in a binary tree is said to be height- balanced if the difference between the heights of the children of v – it’s sub-trees – is at most 1. Height Balance Property: A binary tree is said to be height-balanced if each of its nodes is height-balanced. Adel’son-Vel’skii and Landis tree (or AVL tree) Any height-balanced binary tree is referred to as an AVL tree.
Background image of page 7

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

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

Page1 / 29

lec15 - 2/7/11 2/7/11 CS C341 / I S C361 Data Structures...

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

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