5101 - Design & Analysis of Algo
← 5101 - Design & Analysis of Algo
session: "5101-design-analysis-of-algo/2026-10-24 0000 DAA 24 Oct"
title: "DAA 24 Oct"
date: "2026-10-24 00:00"
duration: "1h 17m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 2
transcript_chars: 41918
generated: "2026-11-24T00:01:40+05:30"
This class reviews the BST property and balance factor, then works through AVL rotations for both insertion (LL, RR, LR, RL) and deletion (R0, R1, R−1), including several numeric deletion examples. It then motivates and introduces M-way trees, B trees and B+ trees as structures for indexing and multi-level indexing in secondary storage, and shows how an M-way tree node is formed (including a hand-drawn 3-way tree). Searching and insertion in an M-way tree are demonstrated with examples, while detailed insertion/deletion in M-way trees is deferred to the next class. The class sits at the transition from balanced binary trees (AVL) to multi-way balanced search structures (B/B+ trees), ahead of heaps, graphs and dynamic programming.
The BST property: left is always less than the root, which is always less than the right; you need not check the whole tree — just pick any three nodes (root, left, right); if left < root < right holds everywhere, the whole tree from root to leaf is a binary search tree. The balance factor is the difference between left height and right height; with the mod value it can be 0 or 1, without the mod (left height minus right height) it can be 0, 1 or −1. This is the invariant that AVL rotations restore, so it underpins everything that follows.
The operations are insertion, deletion, searching and traversal. In traversal you have to "visit" the node; in searching you identify a specific item of interest. Searching and traversal do not modify the tree structure, so the criteria used in a BST are the same for an AVL tree; insertion and deletion change the balance factor (the difference in left and right height gets disturbed). This distinction explains why only insertion and deletion trigger rotations.
The rotation happens on the first node (from the point of insertion) that violates the balance factor property; that node acts as the centre. Types by insertion position: insert on the left of the left subtree → LL; insert on the right of the right subtree → RR; insert on the left of the right subtree, or on the right of the left subtree → LR and RL.
Deletion also changes the AVL property, so three types of rotation are performed — R−1, R0 and R1 — named by the balance factor of node B (the left child of A, where A is the first node violating the property): balance factor of B = 0 → R0; = 1 → R1; = −1 → R−1. Equivalences to remember: insertion on LL is equivalent to deletion on RR (and removing something from the right is equivalent to insertion on the left); R0 is equivalent to LL (B has balance factor 0); R1 is also equivalent to LL (B has balance factor 1); R−1 is equivalent to LR (B has balance factor −1). Important note: A is not always the root node; it can be any intermediate node that violates the AVL tree property — the "A is the root" scenario is not applicable when the tree is very large (the examples use small trees).
In secondary storage (primarily the hard disk), data is stored in sectors/blocks and an index is maintained so retrieval is easy. Like using a book's index page to jump to a chapter/page instead of searching the entire book, an index gives direct/frequent access to data and keeps search time short. If the index itself is very large, another index over it (e.g., chapter-level, then topic-level) is kept — this is multi-level indexing. Since multiple values must be maintained at different levels, a single element per node (as in a BST) is not enough, so nodes with m children are used. BST and other structures discussed so far are stored in internal memory and support internal information retrieval; to favor retrieval and manipulation of data in external memory (storage devices such as hard disks), specialized data structures are required — M-way search tree, B tree and B+ tree allow different retrieval patterns for secondary storage, and the height of the tree is close to log of n, so search is managed accordingly.
An M-way tree is a tree whose node can have m children (m could be 2, 3, 4, 5, 7, whatever we want); each node does not hold a single value like a BST but could hold a set of elements, an array, or even an entire index. A B tree is a balanced M-way tree; a B+ tree is a variant of the B tree (there is a slight difference between the two). In the 5-way example, the maximum allowed child is 5 and the minimum is always 2; if the way is not given, identify any node having the maximum number of children — that number is the way of the tree. Each node has an address pointer field and a key field: for a 5-way tree, addresses can be 5 and keys can be 4, i.e., key = m − 1 and address = m; keys in all nodes are arranged in ascending order. A tree drawn from scratch fills all nodes on one level before going down, so its formation looks different from a resultant tree produced by multiple insertions and deletions.
Searching is similar to BST: start at the root, fetch the element in the root, get a direction key for where to move. Maximum comparisons per node is m − 1, much less than the total number of nodes in the tree, so search time again tends toward log n. As in BST and AVL, the m-way tree (described as an extended variant of the binary search tree) has no duplicate element; before inserting, first search whether the element is available; if not available, add it, otherwise deny. Insertion can happen on a node up to when there is sufficient space; if there is a downward key, first explore that path; if not found, add there.
Keys such as 46, 20, 54, 60 may be indexes or locations of data to fetch; if data is stored at some location y pointed to by 60, removing 60 means there is no pointer to the data, and the data is automatically removed. If a BST is totally in the leftward direction, it becomes a linear search; AVL restores the height on every insertion or deletion. VRAM is also part of the hard disk; such logical arrangements help — without them we would never get VRAM in our PC; it is an ensemble/combined approach to provide extra space by creating a logical arrangement to get more RAM in memory, with data whose immediate requirement is not there pushed toward VRAM and pulled toward RAM. Caching and logical organization are related, but caching is managed by different properties, primarily aligned with scheduling rather than tree structures; caching concerns the frequency of the data being witnessed.
Symbols: left height and right height are the heights of a node's left and right subtrees. Used to test whether a node satisfies the AVL property.
Symbols: the three permitted values of the balance factor. Used as the AVL invariant that rotations restore.
Symbols: m is the way/order of the tree (maximum children per node); key is the maximum number of keys per node; address is the number of address/child pointers per node. Used to size an M-way tree node.
Symbols: k is the actual number of children of a node, m the maximum. Used to check node occupancy (e.g., 5 children → maximum 4 keys).
Symbols: m is the way of the tree. Used to bound the work per node when searching an M-way tree.
Symbols: n is the number of elements. Used to state the search complexity of balanced M-way structures.
Symbols: n is the number of elements. Used to describe how the balance factor keeps search near logarithmic rather than linear.
Inserting 36 — 85 goes up, 96 comes down; 85's right child becomes the left child of 96. Three steps: 85 goes up; 96 becomes 85's right child; the right child of 85 becomes the left child of 96.
Inserting 65 — 34 becomes the first node violating the AVL property, designated A; its right child is designated B; the rotation is performed accordingly.
Tree with nodes 7, 24, 60, 18, 20, 23, 54, 46 (balance factors computed as above). Delete 60 (first identify the node per BST, then delete). Node 46 becomes the first node from the point of deletion with balance factor +2; designate its left child as B. B's balance factor is 0, so the rotation is R0, equivalent to LL. After the rotation, all balance factors are in the range 0, 1, −1.
Remove 24 — node 20's balance factor does not change (18, 17, 23). Then remove 23 — node 20's balance factor becomes 2, and the left child B has balance factor 1, so R1 is performed. R1 is again a resemblance of LL: B goes up, A comes down.
Node 37 gets balance factor 2; 26 goes up, 37 comes down, and the right child of 26 becomes the left child of 37. This is LL; it is called R1 because B's balance factor is 1 (if it were 0 it would be R0).
B has balance factor −1 and A has 2; identify C on the right side of B and perform the LR rotation: C goes up, A comes down, the left child of C becomes the right child of B, and the right child of C becomes the left child of A.
Start from BSTs such as {17, 16, 21} and {22, 23, 21, 27} (all valid BSTs). Merge them: 13's left child is kept; merging with 17 gives a pointer holding two values, 15 and 16; node 23 holds two values, 21 and 22 (binary trees don't allow duplicates, hence 22); 27 is also there. The result has 4 children — a 4-way tree with at most 3 elements per node, values in increasing order (13, 17, 23). M-way search tree property from the example: it is like a merger where the common points hold the BST property — values on the left side are less than the node's value and values on the right side are greater; the child between 13 and 17 holds values greater than 13 and less than 17 (15, 16); the child between 17 and 23 holds values greater than 17 and less than 23 (21, 22); values greater than 23 are stored to the right.
Nodes with 1, 2, 3, 4, 5 children; keys 18, 44, 76, 198, 262, 186, 144, 80, 90, 7, 6, 146 appear in the discussion. Maximum allowed child 5, minimum 2; keys per node 1 to 4. Child can vary from 2 to 5 and key from 1 to 4 (e.g., a node with 2 children is equivalent to a BST node; nodes with 3 keys/4 children, 1 key/2 children, 2 keys/3 children appear). Subtree range: left children of 18 are less than 18; for 198, left children are less than 198 and greater than 76, right children are greater than 198.
At the node with 44, 76 (and 80), 186 lies between 76 and 90, so we get an address and reach the next node; there 144 is greater, and 186 is identified.
18 says 6 could be placed on its left; at the node with 7, 6 goes on the left because 7 has no left child; the node's key count is only two (capacity 4), so 6 is directly inserted. (Inserting 146 was mentioned as an insertion example; details deferred to the next class.)
Values 17, 32, 45, 73, 29, 44, 48, 47, 41 (unique values, no duplicates). Three-way tree → maximum keys 2, maximum children 3.
One line per segment, [hh:mm:ss] timestamp first.
loading…