5101 - Design & Analysis of Algo
← 5101 - Design & Analysis of Algo
session: "5101-design-analysis-of-algo/2026-11-01 0000 DAA 01 Nov"
title: "DAA 01 Nov"
date: "2026-11-01 00:00"
duration: "1h 14m"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 2
transcript_chars: 44571
generated: "2026-11-23T13:35:02+05:30"
This class continued the study of B-trees, focusing on the insertion and deletion algorithms. It began with a recap of B-tree properties and a detailed walkthrough of insertion, including handling full nodes via splitting and median promotion. The session then covered deletion from leaf nodes, explaining borrowing and merging operations to maintain tree properties. A comparison was made between B-trees and Binary Search Trees (BSTs), highlighting their respective use cases in hierarchical storage and in-memory operations. The class concluded with administrative notes on assignments.
A B-tree is a balanced M-way tree designed to prevent skew. Key properties ensure all leaves are at the same level and nodes (except the root) maintain a minimum key count, guaranteeing O(log n) complexity for operations. This structure is crucial for efficient data management in secondary storage like databases.
Insertion always starts with a search. If the target node has space, the key is added in order. If the node is full, it splits: the median key is promoted to the parent, and the node is divided into two children. This can cause cascading splits upward, making the tree grow in height. This process maintains balance after every insertion.
When deleting a key from a leaf, if the leaf has more than the minimum keys, removal is simple. If the leaf is at the minimum, we first try to borrow a key from an immediate sibling (via the parent). If both siblings are also at their minimum, the leaf is merged with a sibling, and a key is brought down from the parent. This can trigger cascading merges upward.
BSTs, with one entity per node, are optimal for in-memory operations like duplicate removal. B-trees, with multiple entities per node, are designed for hierarchical, multi-level storage (e.g., on disk). A single B-tree node fetched into RAM can access large data chunks, making it more efficient than managing many BST root pointers for large datasets.
n keys.n is odd: Median position = n/2 + 1.n is even: Median position = n/2.Used to find the key to promote during a node split in insertion.
m - 1.ceil(m/2) - 1.ceil(m/2).m-1 keys (or 2 to m children as per property).Used to define the valid state of a B-tree and check for violations during operations.
1. Inserting 4 and 5 into a node with space: added directly.
2. Inserting 58 into node [37, 46, 55, 86]: Node becomes full [37, 46, 55, 58, 86]. Median (odd count: 5/2+1) is 55. 55 pops up to parent, node splits into two children: [36, 37, 46] and [58, 86].
3. Inserting 6 into node [2, 4, 5, 7]: Node is full [2, 4, 5, 6, 7]. Median 5 pops up, causing a cascade where the parent also becomes full, leading to further promotion.
1. Inserting 75 into node [65, 70]: becomes [65, 70, 75]. Median 70 pops up, splits node into children [65] and [75], 70 joins parent.
2. Inserting 57 into node [55, 58]: becomes [55, 57, 58]. Median 57 pops up, splits into [55] and [58], 57 joins parent. Parent node [50, 60, 57, 70] becomes full, causing median 60 to pop up further (cascading).
1. Delete 64 from leaf node [62, 64, 66] (has 3 keys, minimum is 2): Simply remove 64 → [62, 66].
2. Delete 23 from leaf node [20, 23] (bare minimum 2 keys). Left sibling [10, 16, 18] has 3 keys (> min). Borrow largest key (16) from left sibling via parent: 16 replaces 20 in parent, 20 moves down to replace 23. Result: leaf [16, 20], sibling [10, 18], parent updated.
3. Delete 72 from leaf node [72, 73] (bare minimum). Right sibling [75, 77, 78] has 3 keys (> min). Borrow smallest key (77) from right sibling via parent: 77 replaces 75 in parent, 75 moves down to replace 72. Result: leaf [73, 75], sibling [77, 78], parent updated.
4. Delete 65 from leaf node [65] (context: left sibling [60] and right sibling [70] both have bare minimum keys). Merge with left sibling and bring parent key down: merge [60] and [70] (removing 65), bringing down parent key 60, resulting in node [60, 70].
1. Delete 20: From a structure with root 50, left child 16, right child containing 20. Leaf [20] has left sibling [14,15] (bare minimum). Merge by bringing down parent key 16 to form [14,15,16], removing 20. This causes the parent node (was [16]) to violate min keys. Resolve by bringing down higher parent key 50 and merging with its siblings, forming a new root [10, 50, 70, 77] with a child [14, 15, 16, 27].
2. Delete 70 (internal): Replace with in-order predecessor 68 (from left child), as the right child had the bare minimum.
3. Delete 95 (internal): Replace with in-order successor 100 (from right child), as the left child had the bare minimum.
4. Delete 77 (internal): Both left and right siblings had bare minimum. Bring 77 down and merge the two sibling nodes.
5. Delete 80 (internal): Can be replaced by either in-order predecessor 79 or successor 81, as both have more than the minimum keys.
6. Delete 100 (internal): Removing it would violate min key property. Solution: Bring down 79, form a new node, and merge affected siblings.
7. Delete 50: Process involves bringing down 68 and merging nodes. Result: root becomes [10, 68] with appropriate children.
[65,70], why are 65 and 75 separated after sending 70 up?ceil(m/2)-1) first attempts to borrow from a sibling with surplus keys.1. Question: Insert the keys [22, 10, 5, 30, 40, 50, 15, 25] sequentially into an initially empty B-tree of order 3. Show the tree after each insertion that causes a split.
[22]. Insert 10: [10,22]. Insert 5: causes split of [5,10,22]; promote 10 to new root [10] with children [5] and [22]. Continue, showing splits when nodes exceed 2 keys, promoting the median each time.2. Question: In a B-tree of order 5, delete the key 20 from the following leaf node configuration: Parent node keys = [15, 30]; Target leaf = [18, 20]; Left sibling leaf = [10, 12, 14]; Right sibling leaf = [25, 26]. Show each step.
[18,20] is at minimum (2 keys). Left sibling has surplus (3 keys). Borrow largest key (14) from left sibling via parent: 14 replaces 15 in parent, 15 moves down to replace 20. Final leaf: [15,18]; Left sibling: [10,12]; Parent: [14,30].3. Question: Compare and contrast B-trees and Binary Search Trees. Give one specific use case where each is preferred and explain why.
ceil(m/2)-1).
One line per segment, [hh:mm:ss] timestamp first.
loading…