1. in the article skip lists: A Probabilistic alternative to balanced trees, which was originally published by William put in ACM: table jumping is a data structure that may replace the Balance Tree in many applications as an implementation method. The Skip List algorithm has the same progressive expected time boundary as the Balance Tree, and is simpler, faster, and uses less space. In fact, jump tables, as the name suggests, jump linked lists and jump tables add forward pointers on the basis of the linked list. For the linked list, the time complexity of sequential search is linear time. In order to improve the search efficiency, add an extra forward pointer to the node of the ordered linked list. You can use an additional forward pointer to span several nodes in the linked list. Then the problem arises, of course it's not the best excavator. How to know how to add additional forward pointers, how many extra forward pointers, and the number of nodes to be crossed for an ordered linked list? In the implementation of the table jumping, the randomization technology is used, the average time complexity of table search, insertion, and deletion is O (logn). The following is an example of a skip table (from Wikipedia ): it can be seen that the Skip table consists of the following parts: <1> header head: maintains the node pointer of the Skip table <2> node: actually saves the element value, each node has one or more layers <3> layer level: stores the pointer pointing to the next node of this layer <4> table tail: the traversal of all skip tables composed of null always starts from the upper layer, and then gradually decreases to the lower layer as the range of element values decreases.
2. the basic principles of table jumping are as follows, the time complexity of the semi-query method is O (logn). In fact, the table jumping uses the space-to-time method to accelerate the search, insert, and delete operations, the properties of the table to be jumped are as follows <1> the table is composed of multiple layers, and the level is randomly generated by the inevitable probability of the process.
<2> each layer is an ordered linked list. The default value is ascending.
<3> the bottom-layer (level 1) linked list contains all elements.
<4> If an element is present in the linked list of level I, its linked list under Level I is also displayed.
<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.
Lists the process of converting from an ordered linked list to a table jump.
3. Implementation of table jumping as the basic data structure is widely used in some open-source implementations, including leveldb and redis. The ordered set in redis is implemented based on the basic structure of the jump table, and the implementation of memtable in leveldb is based on the jump table. In terms of performance, the jump table can fully match the Balance Tree. Binary trees can be used to represent abstract data structures such as dictionaries and ordered linked lists. When elements are inserted in a random order, they exhibit excellent performance, but when an ordered element is inserted continuously, it will quickly degrade and lead to very bad performance. The expression of the table Skip is more intuitive than that of the tree, and the algorithm implementation is simpler. Compared with the Balance Tree, it provides constant factor speed improvement and effective space efficiency. Each node does not need to store balance or priority information.
Find, insert, and delete skip tables as follows:
Sets the maximum number of layers of the table to be jumped. The number of layers of each node is implemented based on the randomization algorithm. The higher the layer, the lower the probability.
Table skip search implementation
Insert implementation for table jumping
Delete Implementation of table jumping
Refer:
Redis Design and Implementation
Skip lists: A Probabilistic alternative to balanced trees
Wikipedia-Skip table
Skip table skiplist