6

如何在时间复杂度(最坏情况)中将 2 个给定Skip lists(每个都有 n 个键)合并为一个?Skip ListO(n)

只是寻找算法 - 没有特定的实现/语言。

4

1 回答 1

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
于 2011-05-08T08:30:43.863 回答