DEV Community

Yash
Yash

Posted on

Skip Lists - Advanced DSA

Redis which is a popular fast in-memory database uses many optimization techniques to speed up the retrievals, one of them is the concept of using skip lists, in simple terms skip lists are augmented linked lists for faster search, as you can skip through portions of the list which don't contain the data you're looking for.

The data is stored in the form of linked lists with an additional information pertaining to an abstract concept of lanes, each node contains 3 data members: value, next and down and the data has a layer of abstraction called lanes, there are 2 types of lanes: normal lane, which is the original linked list and express lanes which are the abstractions, here is a representation:

Image description
// Image courtesy: https://www.geeksforgeeks.org/skip-list/

The code for searching in a linked list is really neat:

SkipNode* search(int key) {
    curr = head;
    while(curr != nullptr) {
        while(curr -> right != nullptr && curr -> right -> value <= key) {
            curr = curr -> right;
        }
        if(curr -> val == key) break;
        curr = curr -> down;
    }
}
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay