use*_*413 6 algorithm merge skip-lists data-structures
我该如何合并给出2 Skip lists(每个具有n个密钥)转换成一个单一Skip List的O(n)时间复杂度(最坏情况)?
只是寻找算法 - 没有特定的实现/语言.
store the two skip lists in two arrays: A,B
merge the arrays.
repeat until getting into root ('top' is a linked list containing only one element):
for each second entry in the skip list 'top' add a 'tag' (link 'upstairs' of the previous level)
Run Code Online (Sandbox Code Playgroud)
它确实是O(n)因为存储和合并是O(n),并且在循环中,你需要迭代:
n+n/2+n/4+n/8+... = sigma(n/2^k) where k in (0,infinity) = 2n
Run Code Online (Sandbox Code Playgroud)