Introduction to Programming in Java ยท Sedgewick & Wayne, 2e

Interactive Companions

Play with the ideas before you write the code. These are built to match the textbook's own examples section by section — each one is self-contained, with its own dark-mode toggle, so you can jump in wherever you're reading.
ยง4.1 Performance pp. 494–530
ยง4.2 Sorting and Searching pp. 531–565
1
Sequential Search: Hits, Misses, and Quadratic Time
Step through the whitelist filter's search loop compare by compare (and watch == fail), measure ~N/2 compares per hit and N per miss, then run the doubling test: ratio 4, quadratic.
โ†’
2
Binary Search Arithmetic: lo, mid, hi
Move lo and hi over the sorted whitelist and watch the half-open interval, mid and both halves update; predict-the-mid quiz and the (lo + hi)/2 overflow.
โ†’
3
Binary Search: The Recursion Trace
Step through the recursive search() line by line with its call stack, for hits and misses — then shuffle the array and watch binary search miss keys that are there.
โ†’
4
Binary Search: Building the Search Tree
Build the tree of middles level by level for N = 2k − 1: every miss is a top-to-bottom path of lg(N+1) compares.
โ†’
5
Twenty Questions: Converting to Binary
Pick a number, ask up to 8 yes/no questions, watch its binary digits reveal themselves one at a time.
โ†’
6
Weighing an Object on a Balance
The exact same questions, acted out physically with a two-pan scale and 64/32/16/8/4/2/1-unit weights.
โ†’
7
Inverting a Function with Bisection
Generalize from integers to real numbers: solve Φ(x) = y for any monotone curve, no closed-form inverse required.
โ†’
8
Insertion Sort: The 16 Names
Sort the 16 names from the slides one compare at a time, watch the trace build row by row (p. 544), and compare the cost of sorted, random and reversed input: ~N, ~N2/4, ~N2/2.
โ†’
9
Mergesort: Divide, Sort, Merge
Merge two sorted halves one move at a time (equal keys keep their order), step through the whole recursion with its call stack and trace (p. 551), count 2N data moves on each of the lg N levels, and compare predicted times with insertion sort.
โ†’
10
Zipf's Law: The Most Common Words
Sort the words, count the runs, sort the counts: rank ร— count stays roughly constant in four novels. Fit the slope on a log-log plot, predict counts from 1/k, and try your own text.
โ†’
ยง4.3–4.5 Stacks & Queues ยท Symbol Tables ยท Case Study pp. 566–714
more companions coming as this chapter gets built out

Built to accompany COSC 2230 (Computer Science III). Each page computes everything live in the browser — nothing here is a canned animation, so the numbers you see are the real output of the formulas or algorithms being taught.