Skip to content

Latest commit

 

History

History
59 lines (51 loc) · 3.15 KB

File metadata and controls

59 lines (51 loc) · 3.15 KB

Lecture 13: BSTs, Red-Black Trees & Midterm Prep [25/02/2026]

Course: Advanced Data Structures and Algorithms


1. ADT: Dictionary & Symbol Tables [00:38:48]

  • Definition: A data structure maintaining a set of items under three operations: Search, Insert, and Delete.
  • Real-World Use:
    • Compilers: Maintaining a "Symbol Table" of all variable names and their addresses. Spelling errors are caught via search.
    • Scope Rules: Variables are inserted when entering a block/function and deleted when going out of scope.
    • Reserved Words: Static dictionaries for keywords like if, while, float.

2. Evolution of Dictionary Implementations [00:48:52]

  • Arrays: $O(n)$ search/insert/delete due to contiguous memory requirements and shifting.
  • Sorted Arrays: $O(\log n)$ search (Binary Search), but $O(n)$ for shift-heavy insert/delete.
  • Linked Lists: $O(n)$ for everything (no random access).
  • Goal: $O(\log n)$ for all three operations.

3. Binary Search Trees (BST) [01:04:12]

  • Nodes: Each node has data, left, right, and parent pointers.
  • Property: For every node $X$, all values in $X.left < X.data$ and all values in $X.right > X.data$.
  • Operations:
    • Search: Start at root. Descend left or right based on comparison. Complexity $O(h)$ (height).
    • Insert: Descend till a nil pointer is found; replace nil with the new node.
  • The "Skewed Tree" Problem [01:41:40]:
    • If data is inserted in sorted order ($10, 20, 30...$), the tree becomes a "linked list" with height $O(n)$.
    • This destroys the efficiency gains of the tree structure.

4. Red-Black Trees (RBT) [01:48:22]

  • Introduction: A self-balancing BST that imposes "Red" and "Black" properties on nodes to ensure the height remains $O(\log n)$ regardless of insertion order.
  • Complexity: Guarantees $O(\log n)$ for Search, Insert, and Delete.
  • Programming Assignment 2: Students are tasked with implementing a full Red-Black Tree.

5. Q&A & Random Access [00:55:53]

  • How Random Access Works: Address = Base_Address + (Index * Size_of_Type).
  • Heap vs. BST [02:06:02]:
    • Heap: Optimized for Max/Min access (Priority Queues). Search is $O(n)$ because you must check both children.
    • BST: Optimized for Search/Dictionary operations.

6. Midterm Exam Strategy [01:56:47]

  • Date: March 8th.
  • Portion: Everything taught up to Red-Black Trees (Principles, Incremental/Decremental, D&C, Heaps, Partition, Selection, number theory, BST, RBT).
  • Format: Subjective (Long answer). No MCQs.
  • Advice:
    • Solve CLRS Exercises (short/conceptual) instead of the long "Problems".
    • Time management: roughly 2 minutes per point.
    • "It's for what is recorded that you are going to be awarded marks."

Key Terms Corrected:

  • symbol table -> Symbol Table
  • licksicographic -> Lexicographic
  • CHAR High int -> char, int
  • Rakesh Kumar -> Student Question (Student Name)
  • root-black trees -> Rooted Trees
  • red-black trees -> Red-Black Trees
  • Kormann -> Cormen (CLRS)
  • low motor partition -> Lomuto Partition
  • decriminal design -> Decremental Design