The basic idea of searching on the Skip List is to first find the range of the key from the highest level layer.
Then, repeat the search operation from the lower level until Level 1.
Strictly speaking, a skip table does not belong to the search tree, but it can provide some functions of the Binary Search Tree in an extremely simple way: insert and search.
The time complexity of skip table operations is expected to be O (log n), and O (n) in the worst case, similar to fast sorting and randomization treap.
Structure
The jump table comes from the linked list, for example:
Head-> 2-> 4-> 6-> 8-> 10-> 12-> null
Search for the above linked list. N nodes are required in the worst case. However, if you attach a pointer to each node, such as adding 2-> 6-> 10, you only need to test n/2 + 1 nodes.
Similarly, if we can make every node whose ordinal number is a multiple of 2 ^ I has a pointer pointing to a node whose next ordinal number is a multiple of 2 ^ I, in theory, we only need to test n log nodes at most.
However, these demanding requirements are not conducive to program implementation, So we relaxed the requirement that nodes with K pointers are called K-level nodes. Change the preceding condition "each node whose ordinal number is a multiple of 2 ^ I has a pointer pointing to a node whose ordinal number is a multiple of 2 ^ I" to the I pointer of each k-level node. the pointing node must have at least level I. This is a property that is easy to retain, and we can randomly specify K to make the probability of a node ORDER k 2 ^-K.
Search
At the top node, start from the highest level and keep following this level until the next node or null greater than the one we are looking for is found. When it drops to the first-order stop, it can be found or it is not in this table.
Insert
Similar to searching, record every node that enables us to go to the next level. After finding the position, splice the new node into the table. Point the pointer of the corresponding level of each recorded node to the new node, and point the corresponding level of the new node to the node pointed to by the original pointer.
Delete
The delete operation on the Skip List only needs to delete elements directly (including pointer trimming ).