Loading...
Development

Module 105

Here is your complete, exam-ready, beautifully organized notes for UNIT II – Advanced Data Structures (8 Lectures)
Perfect for university exams, interviews, and viva!

UNIT II – ADVANCED DATA STRUCTURES (Summary Table First – Must Remember!)

Data StructureTypeInsertDeleteSearchMin/Extract-MinSpaceUsed In / Best For
Red-Black TreeBalanced BSTO(log n)O(log n)O(log n)O(log n)O(n)STL set/map (C++), Java TreeMap
B-TreeMulti-way TreeO(log n)O(log n)O(log n)O(n)Databases, File Systems (NTFS, ext4)
Binomial HeapHeap (Forest)O(log n)O(log n)O(log n)O(n)Dijkstra (better amortized)
Fibonacci HeapHeap (Forest)O(1)O(log n)O(1) amortizedO(n)Fastest Dijkstra/Prim (theoretical)
Trie (Prefix Tree)Tree (Radix)O(m)O(m)O(m)O(ALPHABET×keys)Autocomplete, Dictionary, IP Routing
Skip ListProbabilisticO(log n) expectedO(log n) expO(log n) expO(log n)O(n) expectedLevelDB, Redis (ZSET), Concurrent maps

1. RED-BLACK TREES (Most Important for Exams)

Properties (5 Rules):

  1. Every node is Red or Black
  2. Root is always Black
  3. All leaves (NIL) are Black
  4. Red node → both children Black (No two Reds adjacent)
  5. Every path from node to descendant leaves has same number of Black nodes

Operations: O(log n) guaranteed
Rotations + Recoloring to maintain balance

Use Case: std::map, std::set in C++, Java TreeMap/TreeSet

Insert Example (simple):

Insert 10, 20, 30 → Right-right case → Left Rotate + Recolor

2. B-TREES (Order m)

  • Used in databases & file systems
  • Each node can have up to m children, m-1 keys
  • All leaves at same level
  • Node: at least ⌈m/2⌉-1 keys (except root)

Operations: O(log n)
Node splitting & merging

Why B-Tree? → Minimizes disk reads (one node = one disk block)

3. BINOMIAL HEAPS

  • Forest of binomial trees (B0, B1, ..., Bk)
  • Each tree satisfies min-heap property
  • At most one tree of each order
OperationTime Complexity
InsertO(log n)
Find-MinO(1)
Extract-MinO(log n)
Decrease-KeyO(log n)
Merge (Union)O(log n)

Better than binary heap for Decrease-Key in Dijkstra

4. FIBONACCI HEAPS (King of Amortized Performance)

OperationAmortized TimeWorst Case
InsertO(1)O(1)
Find-MinO(1)O(1)
Extract-MinO(log n)O(log n)
Decrease-KeyO(1)O(log n)
DeleteO(log n)O(log n)
Union (Merge)O(1)O(1)

Used in fastest theoretical Dijkstra & Prim

Structure: Circular doubly-linked list of trees + lazy merging

5. TRIE (Prefix Tree)

Best for string operations

Node contains:

  • Array/Map of children (26 or dynamic)
  • isEndOfWord flag

Operations:

  • Insert: O(length)
  • Search: O(length)
  • StartsWith: O(prefix length)

Example:

Insert: "cat", "car", "cart", "dog"
Root
 ├── c
 │    ├── a
 │    │    ├── t → end
 │    │    └── r → end
 │    │         └── t → end
 └── d
      └── o
           └── g → end

Applications:

  • Autocomplete
  • Spell checker
  • IP routing (longest prefix match)

6. SKIP LISTS

“Probabilistic Alternative to Balanced BST”

  • Multiple layers of linked lists
  • Bottom layer = full list
  • Each higher layer = “express lane” (50% nodes promoted randomly)

Expected Time: O(log n) for Insert/Search/Delete
Space: O(n)

Why used?

  • Simple to implement
  • Lock-free concurrent versions possible
  • Used in Redis (Sorted Sets), LevelDB, Lucene

QUICK COMPARISON TABLE (Draw This in Exam!)

FeatureRB TreeB-TreeF-HeapTrieSkip List
Guaranteed O(log n)YesYesNoNoNo (expected)
Worst-case InsertO(log n)O(log n)O(log n)O(m)O(n) rare
Amortized O(1) opsNoNoYes
Disk-friendlyNoYesNoNoNo
String operationsNoNoNoYesNo
Concurrent-safe easyHardHardHardMediumEasy
Real-world usageHighVery HighRareHighHigh

One-Liner for Viva

StructureOne-Liner Answer
Red-Black TreeSelf-balancing BST with O(log n) guaranteed operations
B-TreeMulti-way tree for disk-based storage (DBs, filesystems)
Fibonacci HeapFastest amortized heap for Dijkstra/Prim
TriePrefix tree for fast string search/insert/delete
Skip ListProbabilistic layered list – simple alternative to balanced trees

Bonus: Real-World Usage (2025)

Data StructureWhere You See It Today
Red-Black TreeC++ STL (map, set), Java (TreeMap), Linux kernel (scheduler)
B-TreeMySQL (InnoDB), PostgreSQL, NTFS, ext4, MongoDB (WiredTiger)
Fibonacci HeapOnly in advanced algorithm courses & research
TrieRedis (autocomplete), DNS, routers, compilers
Skip ListRedis (Sorted Sets), LevelDB/RocksDB, ConcurrentHashMap (Java)

You now have complete Unit II notes – ready to score full marks in theory, practical, and viva!
Want handwritten-style PDF or colored diagram sheet? Just say!