如何在Skip lists
时间复杂度(最差情况)下将2个给定Skip List
(每个有n个密钥)合并为一个O(n)
?
只是寻找算法 - 没有特定的实现/语言。
答案 0 :(得分:7)
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)
确实是O(n)因为存储和合并是O(n),并且在循环中,你需要迭代:
n+n/2+n/4+n/8+... = sigma(n/2^k) where k in (0,infinity) = 2n