Collection Kit

SkipList

Advanced

A SkipList is a probabilistic data structure that allows for fast search, insertion, and deletion operations, using multiple layers of linked lists.

Import Statement
import { SkipList } from "collection-kit";

Key Features

  • Probabilistic Balancing: Achieves balance through randomization, allowing for efficient operations.
  • Dynamic Size: Can grow and shrink as elements are added or removed.

Common Operations

Insert
Add a new element to the skip list.
Remove
Delete an element from the skip list.
Search
Check if an element exists in the skip list.

Example Code

import { SkipList } from "collection-kit";

const skipList = new SkipList();
skipList.insert(10);
skipList.insert(20);
skipList.insert(5);

console.log("Search 20:", skipList.search(20)); // true
skipList.remove(10);
console.log("Search 10:", skipList.search(10)); // false