The laboratory
Every widget on this page executes real operations in your browser using cgt-core.js, a port of the relevant parts of the Python SDK. The book's test suite checks those functions against reference outputs exported from the SDK, so the numbers here are the SDK's numbers. Each widget also appears in the chapter that explains it.
Arrays and linked lists: the same request, two costs
Text alternative: get(i) on an array costs one bounds check, one address computation and one read for every . On a linked list it costs one bounds check, a read of the head, pointer hops and a read. The widget executes both and draws the costs for every index. See Chapter 2.
Dynamic arrays: amortized doubling
Text alternative: appending elements one by one to an array that doubles its capacity when full costs exactly counted steps under the book’s cost model. See Chapter 2.
Tree addresses: pointers versus heap numerals
Text alternative: in a complete binary tree, the node at address has heap numeral . A pointer representation reaches it with pointer hops. The numeral reaches it with one arithmetic operation per -bit word, but a table indexed by numerals needs slots. See Chapter 5 and CGT-THM-003.
Compiling a move word
Text alternative: any word over compiles, in a heap-shaped tree with nodes , into a map that is defined exactly on an interval . After compilation each application costs a constant number of word operations, independent of the word’s length. See Chapter 13 and CGT-THM-006.
Admissibility languages
Text alternative: a regular expression over move symbols compiles (Thompson construction, subset construction, Moore minimization) into the minimal deterministic automaton that decides admissibility. See Chapter 8.
Constrained reachability: the product construction
Text alternative: the vertices reachable from a source along walks whose label word belongs to a regular language are found by breadth-first search over pairs (vertex, automaton state). At most pairs are explored, and the bound is attained on some inputs. See Chapter 8 and CGT-THM-001.
PageRank, one iteration at a time
Text alternative: power iteration contracts the distance to the PageRank vector by a factor per step, so the residual certifies the error: . The widget iterates on small graphs, including one with a dangling page. See Chapter 15 and CGT-THM-008.
Sorting: counting comparisons
Text alternative: insertion sort makes between comparisons (sorted input) and (reversed input); merge sort and heapsort make comparisons on every input. See Chapter 9.
When does preprocessing pay?
Text alternative: an index with build cost and query cost beats search with query cost within an epoch between invalidating updates only if the epoch has more than queries. See Chapter 12 and CGT-PROP-005.