classnotes RTX 4070 Ti SUPER · faster-whisper · DeepSeek

5101 - Design & Analysis of Algo

← 5101 - Design & Analysis of Algo

DAA_31 Oct

Date 2026-10-31 Length 1h 14m Words 8,045 Segments 490
⤓ Download transcript (.txt with timestamps) ⤓ Plain transcript (.txt) ⤓ Transcript (.md)

Summary


session: "5101-design-analysis-of-algo/2026-10-31 0000 DAA 31 Oct"

title: "DAA 31 Oct"

date: "2026-10-31 00:00"

duration: "1h 14m"

language: "en"

model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"

parts: 2

transcript_chars: 39313

generated: "2026-11-24T00:04:19+05:30"


DAA 31 Oct

Overview

This class completes the treatment of M-way search trees and introduces B-trees as balanced M-way search trees. It recaps M-way tree structure, searching, insertion and the four deletion cases (with worked 4-way tree deletions), then shows the skewness problem that motivates balancing. The B-tree properties, naming convention (2-3 tree, 4-5 tree), upward growth, median pop-up insertion and cascading splits are developed through several worked insertions. The second half covers choosing the order m (fixed at creation), insertion complexity, and sizing nodes from disk blocks; B-tree deletion is deferred to the next class.

Learning outcomes

Core concepts

M-way search tree

An extension of a BST where a node may have up to m children (a BST allows only two), and each node holds a set of keys rather than a single key, giving m possibilities of movement. If a node has m children it can have at most m − 1 keys; this keeps the height close to log of n. Keys in a node are in ascending order: everything left of a key is less than it, and everything right of a key is greater than it but less than the next key (e.g., with key 18, nodes 7, 12, 18 are less than 18; nodes such as 19, 41 are greater than 18 but less than 44). This is the base structure on which B-trees are built.

Searching in an M-way tree

Start at the root; since nodes are sorted, apply binary search at each node to decide which child to descend to; repeat. It is an extended BST search where a search is done on each node. Searching does not change the tree structure.

Insertion in an M-way tree

First search whether the element is present, because no duplicates are allowed. If you reach a node where the key could be inserted and there is space (max keys m − 1, max children m), insert in sorted order. If the node already has the maximum number of keys, there are no further nodes to descend to, and the key is not present, create a new node with that value at the appropriate downward location — a new node with one key and two null pointers.

Deletion — four cases

1. Node to be removed is a leaf with no left child and no right child: simply remove it.

2. There is a left child but no right child: pick the highest element from the left child and replace the node.

3. There is only a right child: pick the smallest element from the right and replace the node.

4. Both children are available: use either case 2 or case 3 — it is totally up to your choice.

Taking the highest from the left or the lowest from the right ensures the M-way tree property holds (left < root < right). If confused about highest/lowest, use the in-order predecessor (highest from left) or in-order successor (lowest from right).

Skewness problem

Repeated insertion on the rightmost (or leftmost) side can make the M-way tree unbalanced, just as in a BST. When the height grows rapidly in one direction, the claim of insertion, deletion and searching in log of n time vanishes, violating the M-way tree property. This motivates the B-tree.

B-tree

A balanced M-way search tree, introduced to remove the unbalancing problem; it maintains additional properties to balance the movement of nodes. Motivation: the M-way tree minimizes file access due to its restricted height (why it is used in secondary storage), but the height must be kept as low as possible. B-tree properties (in addition to the M-way properties, which are maintained):

1. The root has at least 2 child nodes and at most m child nodes; the root is allowed only one key and two children — minimum number of children in the root is 2.

2. Every internal node (every node except the root) must have at least ceiling of m/2 and at most m children. Example: for a 5-way tree, ceiling of 5/2 = 3, so 3 to 5 children are allowed. A node with 2 children is allowed only for the root. This minimum cap is crucial to maintain during insertion and deletion.

3. The number of keys in each internal node is 1 less than the number of child nodes.

4. All leaf nodes must be at the same level. (This is why the tree grows upward — we cannot insert a node below the leaf level.)

Keys within nodes are in ascending order, and all M-way tree properties hold.

Upward growth and naming convention

All trees seen so far (BST, AVL) grew downwards; the B-tree grows upwards like an actual tree. When a node is full, we do not go down — we go up by selecting a certain element to be placed at a specific node in the upward direction. A B-tree is also referred to by (keys, children): a 3-way tree is a 2-3 tree (2 keys, 3 children); a 5-way tree is a 4-5 tree (4 keys, 5 children).

Insertion in a B-tree and median pop-up

Insertion/deletion change the structure, so after insertion the properties must be maintained — analogous to rotations in an AVL tree, but here a certain set of rules is adopted. When a node is full and a new key must be inserted, the median element of that node pops up into the upper (parent) node; the remaining keys are split into two nodes. The tree grows upward, not downward. If the parent is also full, the pop-up cascades further up (two-level insertion), increasing the tree height by 1. The root is allowed a minimum of 2 children, unlike other nodes.

Order m fixed at creation

m is chosen once (e.g., 10, 20, 30, 100) based on requirements; the logical arrangement stays intact unless the entire arrangement is changed. m is "not fixed" in the sense that different users may pick different values (5, 4, 100, 1000), but once chosen it stays. A 5-way tree has maximum 5 children, so at most 4 elements per node, and remains 5-way throughout.

Insertion cost

If a node can be directly inserted where space is available, it is order of 1 (search + add). Pop-up operations increase computational complexity, but over a large number of insertions where only a few require such rearrangement, the overall cost is "near to order of 1."

Node sizing from hardware

A disk block/sector can hold, e.g., 512 entries; one block length can be the length of one node, or two or three blocks can be reserved for one node. This determines the maximum value stored (node width) and hence the height. Like declaring an array of size 100 in C while performing only 20–30 operations, a structure can be logically declared large and used minimally; space is not misutilized because links (linked-list style) are used rather than directly reserved locations, so unused space can be used by others. Capacity planning analogy: designing a site for 10,000–20,000 users even if only 2,000 use it — provision up front. In RAM, only the top node (or even just a single address/pointer to it) is stored; on a request you go to it and traverse down.

Formulas and maths

Worked examples

4-way tree deletion of 10: 4-way means max 3 keys, max 4 children. Search from root 20: 10 goes left. The node has no left child and no right child, so simply remove it. Resultant tree: 20, 40, 60, 5, 15, 25, 30, 45, 50, 70, 80, 90.

4-way tree deletion of 14: node has both left and right children → case 4, pick from either side.

Deletion of 25: search from 30 (25 goes left), then no key with value 25 is found → deletion unsuccessful (must search first, then remove).

Deletion of 70: it is in a leaf node, so simply remove it; remaining: 30, 60, 10, 20, 40, 50.

Deletion of 60 (4-way tree, max 3 keys, max 4 children): search from 40 (60 goes left). The root has only one key and 2 children; maximum is 4 but minimum could be 2 (or minimum could be 0 children). Since 60 has no right child, only one option: 50 is removed and replaces 60. Resultant tree: 40, 20, 30, and a node having 50, 80; then 70 and another node 90. (The instructor notes an intermediate drawing was wrong: since 60 has both 50 and 70 available, either can be picked; 50 was picked, leaving 70 and 90.)

Deletion of 50: simply remove it, no worries.

Deletion of 20: pick either 10 or 25 (practice). Picking 25 gives resultant tree: 50, 20, 30, 70, 5, 10, 60, 80, 90.

Identifying a B-tree: given a tree with node 8, 96, 116 (and others), if no information is given, identify any node with the maximum number of children — found 1, 2, 3, 4, 5 → it is a 5-way tree. Root has 1, 2, 3, 4 children (max allowed 5, min for root 2); other nodes minimum 3 (ceiling of 5/2); all leaves at the same level; keys = children − 1. So it is a B-tree.

Insert 4 into the 5-way B-tree: 4 goes to 8 (which has space, but has children on its left), descend to the node with 2 and 7; 2 says 4 goes right, 7 says 4 goes left; no further key downward and there is space (max 4 keys) → insert in sorted order. Result: node holds 2, 4, 7; all leaves remain at the same level; no structural change.

Insert 5: goes to 8, then left; node has space, no further node downward → inserted in sorted order. Result: node holds 2, 4, 5. The node is now full (5 children), so no more can be accommodated.

Insert 58 (crucial case): 58 goes right of 8, left of 96; descend to node 37, 46, 55, 86 (transcript also says "37, 45, 55, 86" / "37, 46, 55, 86"); no 58 below and the node is full → temporarily place 58 (violation). Median element 55 pops up and is placed just before 96; split into two children: 37 and 46 on the left, 58 and 86 on the right. Resultant root: 8, 55, 96, 160 (transcript also says "8, 58, 96, 160" then corrects: 55 pops up, not 8). All nodes stay at the same level; one extra node pushed into the top node.

Insert 6 (after 55 insertion): 6 goes left; node 2, 4, 5, 6 is full → median 5 pops up; split into 2 and 4, and 6 and 7. The upper node 5, 8, 55, 96, 106 is temporarily overfull → 55 pops up. Resultant: 55 at top; 5, 8; 2, 4; 6, 7; 37 and 46. This is a two-level insertion; the tree height increased by 1. The root (55) is allowed a minimum of 2 children, unlike other nodes.

Example 1 — B-tree of order 5 (target 5), inserting 10, 20, 25, 50, 75, 100, 110, 120:

1. 10, 20, 25, 50 are accommodated on the root itself (max 4 elements).

2. 75 arrives; it would go to the right, but accommodating it violates the B-tree property, so the median 25 pops up: root becomes 25, with left node {10, 20} and right node {50, 75}.

3. 100 goes to the right of 25 and is easily accommodated (allowed keys = 4).

4. 110 is also accommodated in that node.

5. 120 arrives; accommodating it violates the property, so median 100 pops up. Result: root {25, 100}; left node {10, 20}; left of 100: {50, 75}; right: {110, 120}.

Example 2 — B-tree of order 3 (2 to 3 children), inserting 75 then 57:

1. 50 → 60 goes to its right → 75 arrives causing overflow; median 60 pops up. The node shows 60, 70, 65, 75 (as described).

2. Insert 57: 60 says go left, 50 says go right, 60 says go — 57 is inserted in the node, but it is full, and the median is also 57, so 57 pops up.

3. 57 tries to go up, but that node is also full, so 60 pops up. Result: 60 at the top, with a 57 node and a 70 node.

Student's earlier observation (referenced): when 6 was inserted in the previous slide, the tree structure changed drastically and height increased; 5 popped up, and if 5 goes up the node again becomes imbalanced (5 not allowed), so the median goes up again — two times.

Questions asked in class

Q (Hrithika): How is the median taken — is it the higher ceiling?

A: Median is nothing but n by 2; for even you can choose n/2 + 1 and for odd n/2 — the basic median formula. Since the list is already sorted, just pick the median element; that will be the pop-up.

Q (Mubal): What kind of tree is it — I'm thinking it's a four-way tree?

A: This is a five-way tree.

Q: Is m always fixed? If there is huge data and we want minimal depth, can we change m?

A: m is fixed at creation (10, 20, 30, 100, whatever) depending on requirement; height and everything then change accordingly. That dynamic exists, but initially you must fix what width you are targeting. The instructor may use 5 or 4; you can use 100 or 1000 — but once used, the logical arrangement remains intact unless you change the entire arrangement.

Q: Based on insertion, complexity increases — at what point of insertion, or is it the same?

A: If the node can be directly inserted where space is available, it is order of 1 (we searched and added). Pop-up operations increase computational complexity, but for, say, 100 elements where only two or three insertions need such arrangement, overall it is near order of 1. A single insertion is of course more complicated.

Q: A B-tree doesn't necessarily guarantee balance; when designing a database index for millions of records, how do we determine the optimal m while balancing height / I/O?

A: Keep the height as log of n.

Transcript

One line per segment, [hh:mm:ss] timestamp first.

loading…