This article presents six algorithm demos in a single walkthrough. Each section focuses on the algorithmic idea, the specific immutable data-structure roles, and a compact core logic view.
Runtime-heavy animation generation is intentionally excluded from
vignette build. The visuals shown here are pre-rendered GIF assets under
vignettes/assets/algorithm-demos/.
Maintainer note: re-render one demo asset
Use:
source("vignettes/helpers/render_algorithm_demo_assets.R")
render_algorithm_demo_assets(demos = "sweep_line")CLI alternative:
Sweep Line
What This Illustrates
A one-dimensional sweep over interval start/end events. At each sweep position, we ask: “which intervals are active right now?” This demonstrates immutable state progression across ordered event keys.
Data Structures and Their Roles
-
interval_index: fast active-interval query at each x-position. -
ordered_sequence: persistent event stream keyed by x. -
flexseq: immutable snapshot history for playback.
Core Logic (Minimal)
# Minimal wrapper from algorithm_demos_helpers.R
out <- run_sweep_line_minimal(seed = 42L, track_snapshots = TRUE)
# Persistent step updates:
# 1) pop events at current x from ordered_sequence
# 2) query active intervals from interval_index
# 3) append immutable snapshot to flexseqSegment Sweep
What This Illustrates
A sweep over segment endpoint events with active-set intersection discovery. This highlights immutable event processing and query state over geometric input.
Data Structures and Their Roles
-
interval_index: active-segment candidate querying at current sweep x. -
ordered_sequence: endpoint event stream, processed in sorted order. -
flexseq: snapshot timeline of sweep states.
Convex Hull
What This Illustrates
Monotone-chain convex hull construction with immutable lower/upper hull stacks. The demo emphasizes turn tests and persistent stack evolution.
Data Structures and Their Roles
-
ordered_sequence: sorted point stream by(x, y). -
flexseq: persistent lower/upper hull stacks and snapshot timeline.
Fortune Frontier
What This Illustrates
A Fortune-style sweep frontier (beach line) visualization that replays immutable state over directrix progression. The focus is event-driven frontier evolution.
Data Structures and Their Roles
-
priority_queue: site events consumed by sweep position. -
ordered_sequence: active frontier registry. -
flexseq: snapshots and breakpoint trails for playback.
Core Logic (Minimal)
# Minimal wrapper from algorithm_demos_helpers.R
stats <- run_fortune_frontier_minimal(complexity = "standard")
stats
# Core behavior:
# - pop ready site events from priority queue
# - insert active sites into ordered frontier state
# - sample beach line and breakpoint trails into persistent snapshotsA* Organic History Large Fast
What This Illustrates
A large maze A* search with staged final-path reveal plus a pressure-history summary. The replay first settles on the solved state, then highlights the solved route in orange before revealing the final purple path overlay, and ends on a full persistent pressure view.
Data Structures and Their Roles
-
priority_queue: open-set frontier ordered byf = g + h. -
ordered_sequence: closed/visited keys for deterministic membership updates. -
flexseq: full persistent snapshot timeline used for replay and history metrics.
Core Logic (Minimal)
# Codified vignette preset (see algorithm_demos_helpers.R)
algorithm_demo_presets$astar_organic_history_large_fast
# Equivalent driver shape:
run_astar_from_preset(
name = "astar_organic_history_large_fast",
outfile = "vignettes/assets/algorithm-demos/05-astar-organic-history-large-fast.gif"
)Wave Clear
What This Illustrates
A queued “wave + clear-wave” process over a weighted obstacle field. The demo shows how immutable timelines make event replay and summary metrics straightforward.
Data Structures and Their Roles
-
priority_queue: add/clear events scheduled by time. -
ordered_sequence: active-cell set keyed by cell id. -
flexseq: immutable snapshot timeline for animation and playback.





