3. Common data structures - skip table

First, what is the skip 
table The full name of the skip table is called the skip table, referred to as the skip table. The skip table is a randomized data structure, which can be regarded as a variant of the binary tree. Its performance is comparable to the red-black tree and the AVL tree, but the principle of the skip table is very simple. It is currently used in Redis and LeveIDB. arrive. 
When searching the sorted list, the time complexity of using binary search is O(logn), but the insertion and deletion of the sorted list is an O(n) algorithm. 
When searching an ordered linked list, the time complexity is O(n), but the insertion algorithm for the linked list is O(1). 
It can be seen that the ordered list and the linked list have their own advantages and disadvantages, and the jump list we are going to talk about is a data structure that integrates the advantages of the above two data structures, but consumes more space.

2. The principle of 
the skip table The principle of the skip table is very simple. The skip table is actually an ordered linked list that can perform binary search. The data structure model of the skip table is shown in the figure: 
write picture description here

It can be seen that the skip table adds a multi-level index to the original ordered linked list, and realizes fast search through the index . First , find the last position on the highest level index that is smaller than the current search element , and then jump to the next level index to continue searching until it jumps to the bottom level. At this time, it is very close to the position of the element to be searched (if the search element exists) if). Since multiple elements can be skipped at once according to the index, the search speed of skip search is also fasterIdeally, the skip table is like a full binary tree, and the time complexity of searching is O(logn) . The question is how to decide how many levels of indexes a node has? ? In response to this problem, the founder of the skip table proposed a method of tossing a coin, using a random function to generate a 0 or 1, if it is 1, level++, until the 0 position is generated, when the amount of data is large enough, the value of level tends to be normally distributed.


3. Comparison of skip table and red -black tree, AVL tree and other balanced data structures  . There are very few places that need to be changed when the skip table is updated , and there are many places that need to be changed in the red- black tree and AVL tree . In the case of multi-threading, when the red-black tree and the AVL tree need a lot of lock resources to maintain a balance, the closer the root node is, the easier it is to compete . However, the operation of the skip table is more local, and there are few resources that need to be locked.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324605042&siteId=291194637