Algorithm Atlas · worked example
See the algorithm, step by step
Promote nodes randomly into sparse express lanes and descend when the next jump overshoots.
This call is starting. Local values appear as they are initialized.
Data & variables
Changed Source indexExample input
[3,6,7]Follow the code. Data appears here when it enters scope.
Call stack · 1 frame
maincall 1
Rust source
Line 59struct SkipNode {
key: i32,
next: Vec<Option<usize>>,
}
fn skip_contains(values: &[i32], target: i32) -> bool {
const LEVELS: usize = 32;
let mut nodes = vec![SkipNode {
key: i32::MIN,
next: vec![None; LEVELS],
}];
let mut random = 0xC0FFEE_u64;
for &key in values {
let mut update = [0; LEVELS];
let mut v = 0;
for level in (0..LEVELS).rev() {
while let Some(u) = nodes[v].next[level] {
if nodes[u].key >= key {
break;
}
v = u;
}
update[level] = v;
}
if nodes[v].next[0].is_some_and(|u| nodes[u].key == key) {
continue;
}
let mut height = 1;
while height < LEVELS {
random ^= random << 13;
random ^= random >> 7;
random ^= random << 17;
if random & 1 == 0 {
break;
}
height += 1;
}
let index = nodes.len();
let next = (0..height)
.map(|level| nodes[update[level]].next[level])
.collect();
nodes.push(SkipNode { key, next });
for level in 0..height {
nodes[update[level]].next[level] = Some(index);
}
}
let mut v = 0;
for level in (0..LEVELS).rev() {
while let Some(u) = nodes[v].next[level] {
if nodes[u].key >= target {
break;
}
v = u;
}
}
nodes[v].next[0].is_some_and(|u| nodes[u].key == target)
}
fn main() {
let result = skip_contains(&[3, 6, 7], 19).to_string();
println!("{result}");
}
Try your own version
Change the independent fixture `[3,6,7]` in a legal way, then compare the result with your prediction. Explain how the same invariant applies to the separate visible challenge `[3,6,7,9,12,19,17,26,21,25]`.
Open personal copy in Playground ↗Start with this exact source and input, change a value, then use Run or Debug locally. This replay stays attached to the original example.
Recordings use a native Rust target. Playground runs on wasm32-wasip1; target-sized types such as usize can have different limits.

Understand it
Lower levels refine the search within the remaining key interval. The worked program demonstrates this invariant on an independent fixture, so you can study the implementation before predicting the challenge result.
For teaching input [3,6,7], the worked program returns false. Its functions are complete and use only std. Adapt the same state transitions to the visible challenge input [3,6,7,9,12,19,17,26,21,25]; predict that result before opening the answer reveal. The precise contract is: Return whether 19 is found after inserting the values.
Return canonical output: lowercase booleans, decimal integers without leading zeros, comma-separated values and semicolon-separated groups, with no extra whitespace or final newline. Whole medians use integer form and half medians use .5. Textual sentinels such as none and # retain their stated meaning. String and character-grid fixtures use ASCII unless the lesson explicitly specifies Unicode scalar values.
Solve the exact task, not just the visible example: Return whether 19 is found after inserting the values. On input [3,6,7,9,12,19,17,26,21,25], predict the output before opening the answer reveal. The revealed output is a test oracle for this case, while private checks exercise other legal cases. Start by stating the input grammar and output format in your own words. Parse the complete input, including surrounding whitespace, before relying on any convenient positions in the example.
Build the solution around one maintained claim: Promote nodes randomly into sparse express lanes and descend when the next jump overshoots. Decide what state represents that claim, how it is initialized, what a single update does, and when the algorithm stops. An advanced structure or offline query order packages an invariant across operations. Name what each node, block, or reordered query state stores. Trace the visible input by hand and record at least two intermediate states, not only the final answer. If the trace cannot justify your predicted output, there is a gap between the idea and the implementation.
Check both correctness and cost. The intended bound is O(log n) expected search/update · O(n) space; explain which operation dominates it and how many times the input can trigger that operation. Test empty ranges, repeated updates, undo operations where supported, and the exact boundary between adjacent blocks. Add one small case that should succeed, one boundary case, and one case chosen to challenge the invariant. Compare your hand result with the program's result, then use a failing case to fix the earliest incorrect state transition rather than patching the final output.
The pattern
Promote nodes randomly into sparse express lanes and descend when the next jump overshoots.
When to use it: probabilistic ordered maps and concurrent-friendly indexes
Complexity: O(log n) expected search/update · O(n) space
Input: [3,6,7,9,12,19,17,26,21,25]
Read the code
struct SkipNode {
key: i32,
next: Vec<Option<usize>>,
}
fn skip_contains(values: &[i32], target: i32) -> bool {
const LEVELS: usize = 32;
let mut nodes = vec![SkipNode {
key: i32::MIN,
next: vec![None; LEVELS],
}];
let mut random = 0xC0FFEE_u64;
for &key in values {
let mut update = [0; LEVELS];
let mut v = 0;
for level in (0..LEVELS).rev() {
while let Some(u) = nodes[v].next[level] {
if nodes[u].key >= key {
break;
}
v = u;
}
update[level] = v;
}
if nodes[v].next[0].is_some_and(|u| nodes[u].key == key) {
continue;
}
let mut height = 1;
while height < LEVELS {
random ^= random << 13;
random ^= random >> 7;
random ^= random << 17;
if random & 1 == 0 {
break;
}
height += 1;
}
let index = nodes.len();
let next = (0..height)
.map(|level| nodes[update[level]].next[level])
.collect();
nodes.push(SkipNode { key, next });
for level in 0..height {
nodes[update[level]].next[level] = Some(index);
}
}
let mut v = 0;
for level in (0..LEVELS).rev() {
while let Some(u) = nodes[v].next[level] {
if nodes[u].key >= target {
break;
}
v = u;
}
}
nodes[v].next[0].is_some_and(|u| nodes[u].key == target)
}
fn main() {
let result = skip_contains(&[3, 6, 7], 19).to_string();
println!("{result}");
}
Complete std-only skip-list program for its typed teaching fixture. Parsing and output construction are separate from the core algorithm.
Practice starter
pub fn solve(input: &str) -> String {
// Return whether 19 is found after inserting the values.
// Trim surrounding whitespace; implement parsing and the algorithm.
let _ = input;
todo!("implement skip-list")
}
Try it
Return whether 19 is found after inserting the values.
What success looks like: The private harness prints PASS skip-list. It checks at least five distinct semantic inputs plus surrounding-whitespace variants. Explain complexity separately; this harness does not time the algorithm.
Check your understanding
Boundary check for skip-list: with input [1,2,3,4,5], what result should solve return?
Reveal the answer
falsetrue- The valid input necessarily panics
For this input the result is false. Lower levels refine the search within the remaining key interval. Compare this independent fixture with the worked trace: Inserting [3,6,7,9,12,19,17,26,21,25] builds a sorted bottom chain with promoted shortcuts. Search 19 moves right while the next key is smaller, then descends. The final equality check finds 19; a missing key cannot be inferred from a nearby shortcut alone.
Go deeper
Common misconception: “Every level stores unrelated unsorted keys”
Lower levels refine the search within the remaining key interval. The independent teaching fixture demonstrates this rule; predict the separate visible challenge before revealing its answer.
- Pattern-specific invariant: Lower levels refine the search within the remaining key interval. This is the property the named implementation maintains; explain which comparison, state update or recursive return in the worked program establishes it.
- Independent typed fixture: The worked call uses
[3,6,7]and computesfalse. Keep parsing separate, then identify the core state before and after this call. - Different legal case: For
[1,2,3,4,5], the independently calculated result isfalse. The complexity discussion uses O(log n) expected search/update · O(n) space. Verify the state invariant before reasoning about the operation count.
Transfer challenge: Change the independent fixture [3,6,7] in a legal way, then compare the result with your prediction. Explain how the same invariant applies to the separate visible challenge [3,6,7,9,12,19,17,26,21,25].
Connections
- Skip List: When to Use It: probabilistic ordered maps and concurrent-friendly indexes
- Rollback DSU: Mental Model: Record every parent or size mutation so recursion over time can undo unions without path compression.
Reveal the Algorithm Atlas answer
true
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Challenge: Skip List (courseId "algorithms", lessonId "algorithm.skip-list.challenge") Link: https://crabrix.com/learn/algorithms/algorithm.skip-list.challenge Goal: Lower levels refine the search within the remaining key interval. Return whether 19 is found after inserting the values. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=algorithms/algorithm.skip-list.challenge) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.