C language jump table (skiplist) implementation, skiplist

Source: Internet
Author: User

C language jump table (skiplist) implementation, skiplist

I. Introduction

The Skip table (skiplist) is an excellent data structure, which is easy to implement. The complexity of insertion, deletion, and search is O (logN ). The core data structure of LevelDB is implemented by using the jump table, and the sorted set Data Structure of redis is also implemented by using the jump table. Code here: http://flyingsnail.blog.51cto.com/5341669/1020034

 

Ii. Jump table diagram

Consider an ordered table:

Search for <23, 43, 59> elements from the ordered table. The number of comparisons is <2, 4, 6>.

2 + 4 + 6 = 12 times. Are there any optimized algorithms? The linked list is ordered, but binary search cannot be used. Similar to binary

In the search tree, we extract some nodes as indexes. The following structure is obtained:

Here we extract <14, 34, 50, 72> as a primary index, so that the number of comparisons can be reduced during the search.

We can also extract some elements from the first-level index as a secondary index and change it to the following structure:

There are not many elements here, but they do not reflect the advantages. If there are enough elements, this index structure will reflect the advantages.

This is basically the core idea of table jumping. In fact, it is also an algorithm that exchanges space for time. By adding a forward pointer to each node, this improves the search efficiency.

Jump table

The following structure is the jump table:

-1 indicates INT_MIN, the minimum value of the linked list, 1 indicates INT_MAX, and the maximum value of the linked list.

Table jumping has the following properties:

(1) consists of multiple layers

(2) Each layer is an ordered linked list.

(3) The Bottom-layer (Level 1) linked list contains all elements

(4) If an element appears in the Level I linked list, it also appears in the linked list under Level I.

(5) Each node contains two pointers, one pointing to the next element in the same linked list and the other pointing to the following element.

 

Iii. Source Code Implementation

https://github.com/begeekmyfriend/skiplist

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.