Skip to content

feat: add Skip List (Data-Structures/Linked-List)#1896

Open
ChrisJr404 wants to merge 1 commit intoTheAlgorithms:masterfrom
ChrisJr404:feat/skip-list
Open

feat: add Skip List (Data-Structures/Linked-List)#1896
ChrisJr404 wants to merge 1 commit intoTheAlgorithms:masterfrom
ChrisJr404:feat/skip-list

Conversation

@ChrisJr404
Copy link
Copy Markdown

What

Adds a Skip List implementation under Data-Structures/Linked-List/SkipList.js with a companion test file under the existing test/ directory.

A skip list is a probabilistic ordered-set / map data structure with expected O(log n) search, insert and delete. Each newly inserted node is promoted to the next level with probability p (default 1/2), giving an expected height of log_{1/p}(n). Compared to balanced BSTs (AVL, red-black) it is much simpler to implement because there are no rotations - balance is maintained statistically rather than structurally. Its semantics also map cleanly onto a multi-level linked list, which is why it lives next to the other linked-list variants in this repo.

Reference: https://en.wikipedia.org/wiki/Skip_list

API

SkipList exposes:

  • insert(key, value?) (returns this, chainable; updates value if key exists)
  • search(key) -> value or undefined
  • has(key) -> boolean
  • delete(key) -> boolean
  • size() / isEmpty()
  • entries() generator yielding [key, value] pairs in ascending key order
  • Symbol.iterator yielding keys in ascending order

The constructor accepts { maxLevel, p, random } so the RNG can be injected for deterministic testing.

Tests

Data-Structures/Linked-List/test/SkipList.test.js adds 14 cases covering:

  • empty / size / isEmpty
  • insert + search (with and without explicit value)
  • key reinsertion updates value without growing size
  • has() membership
  • delete present / delete absent
  • ascending iteration regardless of insertion order
  • entries() output
  • string keys with lexicographic ordering
  • a 500-op randomized stress workload (deterministic LCG) cross-checked against a Set reference
  • input validation on the constructor (maxLevel, p, random)
  • behaviour under forced-min and forced-max promotion levels

Checks

  • npm run check-style clean
  • npm test -> 347 files / 11984 tests pass locally (including the 14 new ones)

DIRECTORY.md is intentionally not touched in this PR - the UpdateDirectory workflow will regenerate it on push.

@ChrisJr404 ChrisJr404 requested a review from appgurueu as a code owner May 5, 2026 21:26
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.35691% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.12%. Comparing base (5c39e87) to head (a21e687).

Files with missing lines Patch % Lines
Data-Structures/Linked-List/SkipList.js 99.35% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1896      +/-   ##
==========================================
+ Coverage   85.91%   86.12%   +0.20%     
==========================================
  Files         379      380       +1     
  Lines       19778    20089     +311     
  Branches     3016     3068      +52     
==========================================
+ Hits        16993    17302     +309     
- Misses       2785     2787       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants