5101 - Design & Analysis of Algo
← 5101 - Design & Analysis of Algo
session: "5101-design-analysis-of-algo/2026-10-25 0000 DAA 25 Oct"
title: "DAA 25 Oct"
date: "2026-10-25 00:00"
duration: "1h 33m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 2
transcript_chars: 50123
generated: "2026-11-24T00:03:03+05:30"
This class completes the treatment of AVL deletion rotations (R0, R1, R−1 and their equivalence to LL/LR rotations), then moves to M-way trees: their properties, search, insertion, and deletion. Worked insertions are done in a 5-way tree (6, 146, 251) and a 3-way tree (1, 9, 22, 26), followed by the four deletion cases based on null/non-null child pointers, with cascade delete examples and a property-violation bug that is diagnosed and fixed. The class ends by flagging the B-tree as the balanced M-way tree that resolves the skewness problem.
Node A is the first node that violates the balance factor property from the point of deletion; node B is the node to the left of A (its left chain). The rotation chosen depends on B's balance factor being 0, 1, or −1. R0 and R1 are similar to LL rotation; R−1 is similar to LR rotation. This matters because knowing only the two basic rotations (LL and RR) is enough to perform LR, RL, R0, R1, and R−1 — it connects the previous lecture's insertion rotations to deletion.
A tree where each node can have up to m ways (access paths) to lower nodes, instead of only two as in a binary tree / binary search tree. It is an extension / multi-way variant of the BST, effectively combining multiple BSTs. It matters because M-way trees are primarily used in secondary storage; searching and traversal are easy (at each node perform a binary search or linear search), and the aim is to keep values in sorted order and do search/insert in log n time.
1. A node does not hold a single value but an array of values. If m = 5: maximum children = 5, children may be 2 to 5, keys = 1 to 4.
2. BST-like property with range bounds: for key Ki, values in the left are less than the key and values in the right are greater than the key; additionally, values must lie within the range imposed by ancestor keys (e.g., values in a subtree must be greater than 18 but less than 44).
3. All values are always in sorted (ascending) order.
These properties are what every search, insertion, and deletion must preserve.
The BST does not allow duplicate entities; similarly the M-way tree does not allow duplicate insertion. Hence a search must precede any insertion (and deletion). This is why insertion explores to the extreme downward before placing a key.
Start at the root; at each node decide which range the key falls into and follow the corresponding child pointer; continue until found or until a null pointer shows the key is absent. This is the basis for both insertion and deletion.
1. Search the key to be inserted (duplicate entries are not allowed).
2. If we reach a node where the key could be inserted and it has available space, add the key with null child pointer(s) as applicable (two null child pointers as in the case of 146, or one null child pointer as in the case of 6).
3. If the node already has the maximum number of keys, make a new node with one key and two null pointers.
Insertion always goes down rather than into a node with space because a downward pointer may hide the value below (duplicates are not allowed); this also avoids pointer shifting. This can cause skewness — a problem to be solved by the B-tree.
Minimum child should be 2 and maximum child should be m; minimum key should be 1 and maximum key should be m − 1. This is the rule of thumb every time.
Either it is given in the question, or you identify any node in the tree with the maximum number of children (e.g., the node with 5 children indicates a 5-way tree).
Increasing m allows each node to store more keys and have more children, which reduces the height of the tree, but increases the searching time within a node because there are more elements to search at each node.
Search, insertion, and deletion always start from the root. In traversal (inorder: left, root, right) we also start at the root but do not read/print its value — we keep following left pointers (using a stack to delay operations) until the leftmost node, then print. The root is so named because it is the first node encountered in any operation.
Stated via the child pointers a_i, a_j:
a_i and a_j are null → simply remove the key (case 1).a_i not null and a_j null → pick the highest element from the left side (case 2).a_i null and a_j not null → pick the smallest element from the right child (case 3).Leaf deletion is easy: if the node from which deletion is to happen is a leaf, we are in case 1 — simply remove the key and shrink the node.
A deletion may itself require further deletions down the tree (e.g., removing 198 required removing 141, which required removing 148, which required removing 146). This chained operation is called cascade delete. The pulled-up element must be the extreme one: the left pointer must hold a value less than the root, and the right pointer a value greater than the root. Replacing with any value other than the correct extreme (e.g., the highest from the entire left subtree) violates the m-way tree property.
The in-order predecessor of 198 is 186 (just less than it) and the in-order successor is 262 (just greater than it); this BST property can also be adopted here.
Linear search can be used if the number of elements is small (less than five or ten); otherwise binary search is preferred. The main role is to reduce the complexity of searching on each node, depending on the number of elements available.
The deletion algorithm for the m-way tree does not track the complexity of both paths; you can either always choose left or always choose right, or introduce a special function that tracks the complexity of both paths and prefer the path with fewer nodes (less traversing) — this would be a modification of the algorithm.
Root keys 18, 44, 76, 198, with lower nodes including 7, 12; 80, 92, 141, 148; 262, 276, 286, 350; and 77.
Insertion sequence given: 4, 7, 8, 3, 2, 11, 17, 16, 44, 43, 21. Resultant tree described: root (4, 7); children (2, 3), (8, 11), (16, 17), (43, 44); and 21 in a node below (pointing from the left of 43).
18, 44, 76, 198; then 6, 7; then 80, 92, 141; then 262, 8, 10; then 77; then 148, 151, 172, 186; then 272, 286, 350; and 146 (having both pointers). Pointer details described: one node points to 146, others null; a node points to 272, 286, 350 with other fields null; 18 points to a node with two null pointers; a pointer to 77; a pointer to 148; etc.
Attempting to remove 198 via the left direction, the class initially pulled 141, then 148, then 146 — but 141's left child is 148, which is not possible (violation of the property). The fix: pick the highest element from the entire left subtree, which is 186, so 186 replaces 198. From the right side, the smallest element from all of it is 262, which replaces 198.
76 has only a right pointer, not a left pointer, so from the right side pick the smallest — 77 — and replace 76. Deletion is allowed from anywhere, not only the extreme left or right.
If the key values in the last leaf node are 8 and 15 instead of 8 and 11, and 10 is to be inserted, 10 goes to the left of 15 (the pointer is common, so it goes to the same place; it lies between 8 and 15, i.e., greater than 8 and less than 15). Values like 9, 10, 11, 12, 14 could be inserted in that range.
Q (on the 146 example): In a 3-way tree maximum children is 3 and maximum keys is 2 — how do we first identify the number of children and keys and the limit at each node?
A: It will be given in the question (e.g., "5-way"). If not given, identify any node in the tree with the maximum number of children — here the node with 5 children (the 48/148 node) indicates a 5-way tree. Either it is given or you check the node with the maximum possible children.
Q: When inserting 6, we inserted it into the existing key position (left of 7) without going to the leaves, but for 146 we went down through subtrees (80, 92, 141) and then inserted at the leaf even though a null pointer was available — why?
A: In the 146 case the node's available keys are already 4, which is the maximum for a 5-way tree, so it is full and cannot accommodate the key; it only provides direction, so a new key is created and given pointer access from the left. If, say, 177 were to be inserted, it could be inserted in the middle of 172 and 186 by updating the null pointer.
Q (on inserting 1 in the 3-way tree): Could 1 be inserted at the root itself?
A: First we must search — there are chances 1 may be present in the lower part, so we first establish that 1 is not present, then identify its correct position. If only 4 were at the root with pointers in both directions, 1 could be accommodated there, but since there is a lower pointer on the left, 1 might exist downward, so we dig down first. (This is why 6 was inserted directly: there was no downward pointer to the left.) The student also clarified confusion about (2, 3) having three pointers and being to the left of 4.
Q: In the 3-way example, when inserting 9, how do we choose which pointer to follow when there are many?
A: 9 is stored to the right of 8 but to the left of 11 — that is the common place; it is greater than 8 but less than 11. In general the place is determined by the BST property: for 8, left is less and right is greater; for 11, left is less and right is greater, because the pointers are merged to form this structure.
Q: Does increasing the order m always reduce the height of the tree, and what trade-off is introduced in searching and insertion?
A: Of course it reduces the height because each node accommodates more elements, but searching within a node takes longer when more elements are stored on each node — this is the trade-off.
Q (Hindi/Hinglish): When we insert a child pointer for 26, does it mean two children?
A: 26 is a key with two null child pointers — that is the rule:
One line per segment, [hh:mm:ss] timestamp first.
loading…