26findMin/ findMaxReturn the node containing the smallest element in the treeStart at the root and goes left/right as long as there is a left/right child. The stopping point is the smallest/largest elementTime complexity = O(height of the tree)
27Searching BST (specific elem) If we are searching for 15, then we are done.If we are searching for a key < 15, then we should search in the left subtree.If we are searching fora key > 15, then weshould search in theright subtree.
30insert Time complexity = O(height of the tree) Proceed down the tree as you would with a findIf X is found, do nothing (or update something)Otherwise, insert X at the last spot on the path traversedTime complexity = O(height of the tree)
32deleteWhen we delete a node, we need to consider how we take care of the children of the deleted node.This has to be done such that the property of the search tree is maintained.
33delete Three cases: (1) the node is a leaf Delete it immediately(2) the node has one sub-tree (right or left)Adjust a pointer from the parent to bypass that node
34delete(3) the node has 2 childrenreplace the key of that node with the minimum element at the right subtree (or the maximum element at the left subtree)delete the minimum elementHas either no child or only right child because if it has a left child, that left child would be smaller and would have been chosen. So invoke case 1 or 2.Time complexity = O(height of the tree)
40Properties of AVL Trees It is a balanced binary tree (definition of Russian mathematicians Adelson-Velskii and Landis)The height of its sub-trees differs by no more than one (its balance factor is -1, 0, or 1), and its subtrees are also balanced.
41Properties of AVL Trees A sub tree is calledLeft high (LH) if its balance is 1Equally high (EH) if it is 0Right high (RH) if it is -1
42Operations on AVL Trees Insertion and deletion are same as in BSTIf unbalance occurs corresponding rotations must be performed to restore balance
43Balanced trees: AVL tree rotations Steps:Check if case is case 1 or 2 of the following and act accordinglyCase 1:tree is left high &out-of-balance is created by a adding node to the left of the left sub-tree…… One right rotation is needed Rotate out-of-balance node right
44Case 1: single R-rotation Tree is left balancedunbalance is caused by node on the left of left sub-treeh+2h+1h+1h+1hhhhh
45Balanced trees: AVL tree rotations Case 2:tree is left highout-of-balance is created by a adding node to the right of the left sub-tree…… Two rotations are needed:Move from bottom of left sub-tree upwards till an unbalanced node is found and rotate it left Rotate left sub-tree right
46Case 2: Double LR-rotation Add node to right of left balanced subtreeh+2h+1h+2h+2hhh+1h+1h+1hhh First rotation .. Left rotation of unbalanced node c Second rotation … Right rotation of left sub-tree g