CSE3144 Β· Advanced Data Structures Β· Jul–Nov Semester 2026 Β· Lecture 15 of 36 Β· CO CSE3144.2

Comparative Analysis of Advanced Tree Structures

Lectures 7 through 14 built nine different trees, one at a time. Today we stop building and start choosing: same input, different structures, and a real answer to "which one, and why."

Dr. Manu ShrivastavaCourse Instructor Β· Consultation Fri 2–5 PM, LHC 308F
~65 minutesSession outcome: compare balanced and indexing tree structures
L15 Β· 00 β€” Agenda ~65 min

Today, part by part

Why compare at all?

00–04

Nine trees, one toolbox β€” the real skill is picking the right one under pressure.

The five axes of comparison

04–08

Height bound, branching factor, key type, rebalancing cost, memory vs. disk.

Recap: the balanced-BST family

08–13

BST, AVL, Red-Black, Splay β€” one gallery, one height-bound table.

Recap: the indexing family

13–18

B-trees, Tries/DST, Segment/Interval trees, Suffix trees β€” what each one indexes.

Animation: AVL vs. Red-Black, same 6 keys

18–30

Insert 10,20,30,40,50,25 into both, side by side β€” every rotation and recolor.

Animation: binary height vs. B-tree height

30–38

Same 15 keys, two structures β€” search for 13, count the node visits.

Decision guide: scenario β†’ structure

38–43

A working flowchart you can actually use in a design review.

The grand complexity table

43–48

All nine structures, one table: search, insert, delete, space, height.

No free lunch: trade-offs, side by side

48–53

Every advantage in this table is paid for somewhere else in the same row.

Where these actually run in production

53–58

Standard libraries, kernels, databases, routers, genome tools.

Recap & what's next

58–65

Lecture 16: Binary Heaps and Heap Operations.

CSE3144 β€” Lecture 15
L15 Β· 01 β€” Why compare at all? ~4 min

You now own nine trees. The job is picking the right one.

The situation

Across Lectures 7–14 you built, by hand, the BST, AVL tree, Red-Black tree, Splay tree, B-tree/B+-tree/B*-tree, Trie, Digital Search Tree, Segment tree, Interval tree, and Suffix tree. Each lecture asked "how does this one work?" None of them asked the question an engineer actually faces first: given this workload, which one do I reach for?

Why this matters in practice

Picking wrong is expensive, not just inelegant. A database index built as a plain binary search tree instead of a B+-tree can turn a 3-disk-read lookup into a 20-disk-read lookup β€” on every single query. A router forwarding table built as a sorted array instead of a trie turns an O(1)-ish prefix match into a binary search that still doesn't naturally support "longest prefix." Today builds the decision framework so that choice is deliberate, not accidental.

CSE3144 β€” Lecture 15 Β· Why compare
L15 Β· 02 β€” Five axes of comparison ~4 min

Every tree in this course differs along the same five dimensions

1 Β· Height guarantee

Is worst-case height bounded at all? By how tight a constant? Unbalanced BSTs have none; AVL and RB guarantee O(log n) with different constants; Splay guarantees it only amortized, not per operation.

2 Β· Branching factor

Binary (2 children) vs. multiway (B-trees: dozens to hundreds of children per node). Higher branching factor means shallower trees β€” the whole reason B-trees exist for disk-resident data.

3 Β· Key type supported

Ordered scalar keys (BST family, B-tree family) vs. string/bit keys decomposed character-by-character (Trie, DST, Suffix tree) vs. ranges/intervals (Segment tree, Interval tree).

4 Β· Rebalancing cost

Rotations (AVL, RB, B-tree splits), pure recoloring (RB, cheaper than a rotation), or no explicit rebalancing at all but restructuring on every access (Splay).

5 Β· Memory vs. disk orientation

Designed for in-RAM pointer-chasing (BST family) vs. designed to minimize block/page reads from secondary storage (B-tree family) β€” a difference that dominates real-world performance far more than the Big-O alone suggests.

The framework

Every comparison in this lecture is really just: where does this structure sit on these five axes, and what does that cost or buy you? Keep this list open β€” we'll refer back to it constantly.

CSE3144 β€” Lecture 15 Β· Five axes
L15 Β· 03 β€” Recap: the balanced-BST family ~5 min

BST β†’ AVL β†’ Red-Black β†’ Splay: tightening (or trading away) the height guarantee

StructureHeight boundRebalancing mechanicOne-line character
BST (L7)None β€” O(n) worst case (a sorted-insert chain degenerates to a linked list)NoneThe baseline every balanced tree is trying to fix.
AVL tree (L7–8)≤ 1.44 logβ‚‚(n+2) βˆ’ 0.33 (Knuth) β€” the tightest of the threeRotations on insert (≤2) and delete (up to O(log n) up the path)Strict: every node's left/right subtree heights differ by at most 1.
Red-Black tree (L9)≤ 2 logβ‚‚(n+1) β€” looser than AVL by roughly a factor of 1.4≤2 rotations on insert, ≤3 on delete, plus cheap O(log n) recolorsLooser height rule, cheaper average fixup β€” the standard library default.
Splay tree (L10)No worst-case bound per operation β€” a single access can visit O(n) nodesRotates the accessed node all the way to the root, every time (no separate "check and fix" step)No guarantee per op, but O(log n) amortized over any sequence β€” and free adaptation to access locality (the working-set property).

All three balanced variants guarantee O(log n) search/insert/delete in the worst case except Splay, which trades that per-operation guarantee for automatic adaptation to real access patterns β€” cheap for the keys you use often, exactly the amortized-cost idea from Lecture 3's potential-method callback in Lecture 10.

CSE3144 β€” Lecture 15 Β· Balanced-BST recap
L15 Β· 04 β€” Recap: the indexing family ~5 min

B-trees, Tries/DST, Segment/Interval trees, Suffix trees: four different things to index

StructureWhat it indexesBranching / shapeSpace
B-tree / B+-tree / B*-tree (L11)Ordered scalar keys, optimized for block-device accessMultiway β€” order m means up to m children per nodeO(n), but sized to fill disk blocks
Trie / Digital Search Tree (L13)Strings or bit-patterns, decomposed character/bit by character/bitBranching factor = alphabet size (Trie) or 2 (binary DST)Θ(N·|Σ|) worst case (Trie); more compact for DST
Segment tree / Interval tree (L12)Ranges over a fixed universe (segment tree) or a dynamic set of intervals (interval tree)Binary, built once over the universe or the key setO(n)
Suffix tree (L14)Every substring of one text, via its suffixesBinary-to-multiway, compressed non-branching chainsO(m) guaranteed (m = text length)

Notice the pattern: every structure in this family exists because the balanced-BST family's assumption β€” "keys are single ordered scalars, and RAM pointer-chasing is cheap" β€” breaks down for some workload: disk-resident data, string keys, range queries, or substring queries. Indexing trees are balanced-BST ideas re-specialized for a specific kind of key or access pattern.

CSE3144 β€” Lecture 15 Β· Indexing-tree recap
L15 Β· 05 β€” Animation: AVL vs. Red-Black, same 6 keys ~12 min

Insert 10, 20, 30, 40, 50, 25 into both β€” watch where they agree and where they diverge

This is the exact sequence from Lecture 7–8's AVL build. Every insertion is animated into both trees at once β€” including steps where one tree needs a fixup and the other doesn't, and steps that are pure recoloring with zero structural change. Nothing is skipped.

Interactive β€” insert 10, 20, 30, 40, 50, 25 into an AVL tree and a Red-Black tree, side by side
CSE3144 β€” Lecture 15 Β· AVL vs. Red-Black
L15 Β· 06 β€” Animation: binary height vs. B-tree height ~8 min

Same 15 keys, two structures β€” search for 13, count the node visits

Keys 1–15 stored two ways: a perfectly balanced AVL tree (binary, height 3) and an order-5 B-tree (up to 4 keys / 5 children per node, height 1). Watch both search for the same key, one node-visit at a time β€” in a disk-resident structure, each visit is a potential disk read.

Interactive β€” search both structures for key 13
CSE3144 β€” Lecture 15 Β· Height vs. branching factor
L15 Β· 07 β€” Decision guide ~5 min

Scenario in, structure out

If your workload looks like……reach forBecause
General-purpose in-memory ordered map/set, frequent insert and deleteRed-Black treeCheapest average rebalancing cost among the guaranteed-O(log n) options
Lookup-heavy workload, insertions/deletions rare after initial buildAVL treeTightest height bound β†’ fewer comparisons per search, the cost you actually pay repeatedly
Access pattern is skewed / has strong temporal locality (caches, LRU-like use)Splay treeWorking-set property β€” recently touched keys become cheap automatically
Data lives on disk/SSD β€” database index, filesystem directoryB-tree / B+-treeHigh branching factor minimizes the number of block reads, which dominates real latency
Keys are strings and you need prefix search, autocomplete, or routingTrie (or compressed trie / DST for tighter space)Cost depends on key length, not on how many keys are stored
Repeated "which intervals overlap X" or "sum/max over range [lo,hi]" queriesInterval tree (dynamic interval set) or Segment tree (fixed range universe)Purpose-built augmentation (max_high, canonical decomposition) makes these O(log n) instead of an O(n) scan
Repeated substring / pattern-matching queries against one large fixed textSuffix tree (or suffix array in production)O(p) search per pattern regardless of text length, after one O(m) build
CSE3144 β€” Lecture 15 Β· Decision guide
L15 Β· 08 β€” The grand complexity table ~5 min

All nine structures, one table

StructureSearchInsertDeleteSpaceHeight / depth
BST (unbalanced)O(h)O(h)O(h)O(n)O(n) worst case
AVL treeO(log n)O(log n)O(log n)O(n)≤1.44 logβ‚‚n
Red-Black treeO(log n)O(log n)O(log n)O(n)≤2 logβ‚‚n
Splay treeO(log n) amortizedO(log n) amortizedO(log n) amortizedO(n)no per-op bound
B-tree / B+-tree (order m)O(log_t n), t=⌈m/2⌉O(log_t n)O(log_t n)O(n)very small β€” grows with branching factor
TrieO(L)O(L)O(L)Θ(N·|Σ|) worst caseO(L), independent of n
Digital Search TreeO(b)O(b)O(b)O(n·b) worst caseO(b), b = key bit-length
Segment treeO(log n) per queryO(log n) per point updateO(log n)O(n)O(log n), fixed universe
Interval treeO(log n + k) to report k overlapsO(log n)O(log n)O(n)O(log n)
Suffix treeO(p), pattern length pO(m) full buildrarely used dynamicallyO(m)O(m) worst case, typically far less

L = key length (Trie), b = key bit-length (DST), m = text length (Suffix tree), n = number of keys, h = tree height, t = B-tree minimum degree. Every one of these numbers was independently derived and hand-verified in its own lecture β€” this table just puts them side by side.

CSE3144 β€” Lecture 15 Β· Grand complexity table
L15 Β· 09 β€” No free lunch ~5 min

Every advantage in the last table is paid for somewhere else in the same row

Advantages, restated as trade-offs
  • AVL's tight height costs more rotations per insert/delete than Red-Black β€” verified numerically in this lecture's own head-to-head (3 rebalancing events vs. 2, for the same 6 keys).
  • B-trees' shallow height costs wasted space in partially-full nodes (a node can legally be as little as half full) and more complex split/merge logic than a binary rotation.
  • Tries' O(L) search costs Θ(NΒ·|Ξ£|) space in the worst case β€” fixed by compression (Lecture 13), which then costs implementation complexity.
  • Suffix trees' O(p) pattern search costs a genuinely intricate O(m) build (Ukkonen's algorithm) β€” which is exactly why suffix arrays often win in production despite being conceptually simpler, not more powerful.
  • Splay trees' automatic adaptation costs any worst-case per-operation guarantee at all β€” one unlucky access can legitimately cost O(n).
The one-sentence version

Every structure in this course is a different answer to the same question β€” "where should the cost go?" β€” and the right answer always depends on which operation your workload actually calls the most, not on which structure looks the most sophisticated on a slide.

CSE3144 β€” Lecture 15 Β· Trade-offs
L15 Β· 10 β€” Where these actually run ~5 min

Not a hypothetical exercise β€” these choices are load-bearing in real systems

Red-Black tree

C++'s std::map/std::set and Java's TreeMap/TreeSet are implemented as red-black trees in their standard library implementations. The Linux kernel uses red-black trees for the CFS process scheduler's run-queue and for tracking virtual memory areas.

B+-tree

The default on-disk index structure for most relational databases (e.g. InnoDB's clustered indexes in MySQL) and many filesystems β€” high branching factor is chosen specifically to match the disk block size, minimizing seeks.

Trie / compressed trie

IP routers use trie-like structures (compressed/PATRICIA tries) for longest-prefix-match forwarding lookups; search engines use tries for autocomplete and prefix-based term indices.

Splay tree

Well-suited to caches and any workload with strong temporal locality β€” recently or frequently accessed keys migrate toward the root and stay cheap, with no separate cache-eviction bookkeeping needed.

Segment / Interval tree

Computational-geometry engines, scheduling systems ("which meetings overlap this time slot?"), and graphics/collision-detection pipelines that need fast range or overlap queries.

Suffix tree / array

Bioinformatics tools for genome alignment and repeat-finding; full-text search engines and version-control diff tools that need fast substring queries over large fixed texts.

CSE3144 β€” Lecture 15 Β· Real-world use
L15 Β· 11 β€” Recap & what's next ~7 min

Same problem, nine tools β€” the choice is now yours to defend

Lecture 16 β€” next

Binary Heaps and Heap Operations

From "find/compare a specific key" to "always give me the extreme one" β€” a different family problem, a different structure.

Homework β€” bring to Lecture 16
  • Insert the keys 5, 3, 8, 1, 4, 7, 9, 2, 6 into both an AVL tree and a Red-Black tree by hand. Count rotations and recolors for each. Which used fewer structural changes?
  • For the same 9 keys, compare the resulting AVL/RB height against an order-4 B-tree built on the same keys. How many node visits does each need to find key 6?
  • Pick any one real system you use daily (a phone's contacts app, a text editor's autocomplete, a map app's routing). Which tree family from this course would you guess sits underneath it, and why?
  • In 3–4 sentences: why does "amortized O(log n)" (Splay tree) not mean the same guarantee as "worst-case O(log n)" (AVL/RB)? Give a concrete access sequence where the difference would show up.
CSE3144 β€” Lecture 15

Questions?

Dr. Manu Shrivastava β€” LHC 308F β€” Friday 2:00–5:00 PM

Next: Lecture 16 β€” Binary Heaps and Heap Operations.