classnotes RTX 4070 Ti SUPER · faster-whisper · DeepSeek

5101 - Design & Analysis of Algo

← 5101 - Design & Analysis of Algo

DAA_17 Oct

Date 2026-10-17 Length 1h 30m Words 11,579 Segments 656
⤓ Download transcript (.txt with timestamps) ⤓ Plain transcript (.txt) ⤓ Transcript (.md)

Summary


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

title: "DAA 17 Oct"

date: "2026-10-17 00:00"

duration: "1h 30m"

language: "en"

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

parts: 3

transcript_chars: 57431

generated: "2026-11-23T23:58:12+05:30"


DAA 17 Oct

Overview

This class covers how binary trees are stored in memory (link vs. sequential/array representation), the three depth-first traversals (pre-order, in-order, post-order) and how a stack is used to perform them, and the definition and construction of binary search trees (BSTs). It then works through BST insertion, searching complexity, duplicate removal, and all three deletion cases, including the in-order successor and cascading deletions. The class closes by motivating balanced trees: the skewness problem and the AVL tree with its balance factor. This material sits at the foundation of the tree unit — BST is described as the base on which AVL, RB, MV and B trees are built.

Learning outcomes

Core concepts

Tree representation in memory

Link representation is a form of doubly linked list: a left field pointing to the left child, a right field pointing to the right child, and an info part in between. Sequential representation stores the tree in a linear array using the policy k, 2k, 2k+1 on each node to determine node locations. Avail space is the addition of available memory "on the top" — the pointer points to the most recently deleted (most recently available) space. Choice rule: for a dense tree (complete or nearly complete) prefer sequential representation; for a sparse tree (connections not fully occupied, far from complete) prefer link representation. In the lab/coding, array representation is primarily used — it is more viable and easy to go. This matters because representation determines memory cost and access pattern for every operation that follows.

Traversal

Traversal means visiting all the nodes of the tree. Pre-order is root, left, right — the root appears at the first position. In-order is left, root, right — the root comes in between the left and right side. Post-order is left, right, root — the root appears at the last position. The policy is applied on each and every node (check only the three nodes: left child, right child, parent), not the entire tree at once. Tree reconstruction: using pre-order + in-order, or in-order + post-order, the entire tree structure can be recreated — instead of storing the actual tree structure, we can store two arrays and gain back the tree when required. Traversal is the basis for the stack procedures below and for the deletion-by-successor rule later.

Stack and stack-based traversal

A stack is a one-ended data structure where insertion and deletion are performed from the top, and the element on top is processed first (LIFO — last in, first out); it is compared to the chapati container at home, where the last chapati cooked is eaten first. Push is insertion into the stack; pop is deletion from the stack. A stack is used when we need to delay some operation over another.

Binary tree and BST definitions

A binary tree is a tree where there are two possible movements in the lower direction — left child and right child; no condition is imposed on what goes left or right. A Binary Search Tree (BST) is a binary tree (maximum allowed children is two: zero, one, or two) in which each node n has the property: n is greater than every value in the left subtree and n is less than every value in the right subtree — in short left < root < right, with no equality sign, so duplicate entries are not allowed. Formal definition given: a binary search tree is always a binary tree; if each node n of the tree has the property that n is greater than every value on the left subtree and n is less than every value on the right subtree, it is a BST. BST is also known as a binary sorted tree — "sorted" means the same property is followed; binary search tree is the famous name. BSTs never allow duplicate entries; later trees (AVL, RB, MV, B tree) also never allow duplicates, B+ tree may allow duplicate entries, and heaps allow duplicates but have their own different property. A node in a BST may hold an entry record of the data — an array of values, not a single element (this relates to the MV tree); for explanation, single-element nodes are used. AVL, RB, MV and B trees all carry forward the BST property with something additional — BST is the base of the tree data structure.

The four primary operations and node types

The four primary operations in data structures are insertion, deletion, traversal, searching. Traversal and searching do not modify the tree structure, so the BST property is not hampered; insertion and deletion may violate the BST property and thus the property must be restored by certain operations (to be done later). Insertion rule: first search (since duplicates are not allowed); if not found, add the new element. Deletion rule: if found, remove; otherwise declare the element is not present. Three types of nodes: root (the initial point from where the tree primarily starts; also a special type of intermediate node), intermediate nodes (nodes having one or two children, not zero children), and leaf nodes (no children).

Skewness problem

While constructing a BST, the tree may go skewed in one specific direction (few nodes on the left, increasing very high on the right). Inserting a, b, c, d, … gives a right-skewed tree; inserting z, y, x, …, a gives a left-skewed tree. It is no longer a tree but effectively a linear array, where searching takes order of n. This is the unbalancing problem: although left < root < right is maintained, the log n search time is not preserved, and the exercise of making the BST is lost because linear search would do the same. The fix is to maintain the BST to be of balanced height — left height and right height should not be exactly the same but should be comparable — so that log n can be preserved. This motivates the AVL tree.

AVL tree

The AVL tree (Adelson, Walensky, Landis) is the most popular balanced binary tree: a binary search tree with an additional condition that left and right heights are balanced. An empty binary tree is an AVL tree. The balance factor is the difference between left height and right height; AVL allows 0, 1 or −1 (not 2). For a leaf node the balance factor is 0.

Deletion in a BST

Memory/table representation and the avail pointer

The table is the memory; it holds addresses (the info part), and left and right are the links. E.g., "left 8" means at location 8 the left child is present; "right 10" means at location 10 the right child is present. 8 and 10 are addresses, not values — at address 8 you find 15, at address 10 you find 50. The avail pointer points to the available list; when a node is removed, the pointer shifts to that location; insertion and deletion happen from the top (where the node is started). This is an important property of avail.

Formulas and maths

$k$ is the node's array index; used to place a tree into a linear array.

Applies to every node n relative to every value in its left and right subtrees; used to define and validate a BST.

$n$ is the number of elements; used to contrast BST search with the order of $n$ comparisons in a linear linked list or array.

$n$ is the number of elements; used when the tree is balanced — if the tree becomes skewed, order of $\log n$ reaches order of $n$.

$n$ is the number of elements; used to note that cascading deletion is never exactly $\log n$ but more than that, while the order remains $\log n$.

HTL and HTR are the heights of the left and right subtrees; used to check the AVL condition.

Used to decide whether a BST node is balanced.

Worked examples

Building a BST from 2, 7, 3, 1, 31, 41, 29, 44, 47, 63

(No duplicates included, since a BST will not contain any.)

Property-check example

Nodes 38, 14, 23, 18, 8 on one side and 56, 45, 82, 70 on the other — 8 is on the left of 14; 23 and 18 on the right; 18 < 23 so it is placed on the left of 23; 70 is under 82 with 56 and 45. The property holds.

Alphabetical example

Harris, Cohen, Levis, Kell, Rubin, Brown, Green, Davis — alphabetically sorted names less than the root appear on the left, and the root is further less than the right ("less" means appearing prior in alphabetical order).

Insertion into a pre-existing tree

Tree contains 38, 14, 56, 23, 45, 82, 70, 18; insert 20, 40, 60, 50, 33, 55, 11:

Depth and comparisons

In the worked example tree, the maximum depth is 4 (levels labeled 0, 1, 2, 3, 4), so the height of the tree is 4; the maximum number of comparisons for inserting a new node is of the order of 4 — the comparisons performed were 1, 2, 3, 4, 5, i.e., order of n plus 1 or so.

Memory/table example

Tree: 60, 25, 75, 15, 50, 66, 33, 44 arranged likewise. In memory: start node 60; its left is at location 2 (25) and right at location 7 (75). For 25, left is at location 8 (15) and right at location 10 (50). 15 has left only, no right. 33's left is located at 1; 44 is at location 9 and has no left side. The avail pointer points at the 5th location.

Transcript

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

loading…