Each project below is tailored to a specific algorithm and scientific question from Chapter 18, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.
Project 1 of 3 · v1-c18-p01Foundational · ~20 min
Linear vs. Binary Search Complexity Benchmark
Lab activity: 1. Find a record fast · Related code: block-01.js, block-04.js · Pioneer: View profile
Real-World Problem: Searching 10 million sorted IDs one by one is slow, while halving the interval finds any ID in 24 steps.
Scientific Question: How does the comparison count of binary search grow when array size increases 1,000×?
Objective: Implement linear and binary search, count exact comparisons across sizes 16 to 65,536, and verify O(log2 n).
Hypothesis to Test: Doubling array size adds at most 1 extra comparison to binary search, whereas it doubles worst-case linear search.
Step-by-Step Implementation
Write linearSearch(arr, target) and binarySearch(arr, target) returning both index and comparison count.
Run both on sorted arrays of size 16, 256, 1024, and 65536.
Verify binary search fails on an unsorted array (precondition violation).
Compare worst-case comparisons against Math.ceil(Math.log2(n)).
Concrete Input: Sorted arrays of size 16, 1024, and 65536; search for worst-case missing key.
Expected Output: N=1024: Linear=1024 vs. Binary=10; N=65536: Linear=65536 vs. Binary=16.
Test Cases: Found first/middle/last element -> exact index; Missing element -> -1 in <= ceil(log2(n))+1 steps.
Boundary Condition: Empty array [] must return -1 in 0 comparisons without infinite loop.
Common Mistake to Avoid: Using (lo + hi) / 2 without Math.floor, or setting hi = mid instead of mid - 1 causing infinite loops.
Interpreting Results: Logarithmic algorithms scale effortlessly from classroom lists to planetary databases.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 18 before testing the boundary case: Empty array [] must return -1 in 0 comparisons without infinite loop.
Extension Challenge: Implement lowerBound() to find the first occurrence when duplicate keys exist.
Reflection Question: Why is sorting data once worth the upfront cost if you will search it thousands of times?
Test Cases: Single word -> matching IDs; Two words -> exact intersection; Stop/missing word -> empty array.
Boundary Condition: Empty query string should return [] cleanly rather than throwing.
Common Mistake to Avoid: Forgetting to lowercase both indexed tokens AND query tokens.
Interpreting Results: Inverted indexes (like Pagefind powering this very website!) make instant static search possible.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 18 before testing the boundary case: Empty query string should return [] cleanly rather than throwing.
Extension Challenge: Add an OR query mode and snippet highlighting using safe DOM textContent (no innerHTML).
Reflection Question: How did Alan Emtage's Archie (1990) pioneer automated indexing before the modern web?
Expected Output: Ranks converge with C highest (most incoming links) and total sum = 1.000000.
Test Cases: Sum of ranks always 1.0; Node with more high-rank in-links scores higher than isolated node.
Boundary Condition: Self-loops and parallel edges should be normalized consistently.
Common Mistake to Avoid: Dropping dangling-node mass, which causes total PageRank to decay toward 0.
Interpreting Results: Larry Page, Sergey Brin, and Jon Kleinberg showed that graph structure carries rich collective signal.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 18 before testing the boundary case: Self-loops and parallel edges should be normalized consistently.
Extension Challenge: Add a spam link farm pointing to Node D and test how damping limits artificial rank inflation.
Reflection Question: Why do modern search engines combine hundreds of signals rather than relying solely on PageRank?