开发者

Merge of Skip Lists

开发者 https://www.devze.com 2023-03-04 15:22 出处:网络
How can I merge 2 given Skip lists (each with n keys) into a one single Skip List in O(n) time complexity (worst case)?

How can I merge 2 given Skip lists (each with n keys) into a one single Skip List in O(n) time complexity (worst case)?

Just looking for the algorithm 开发者_StackOverflow- no particular implementation/language.


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)

it is indeed O(n) because store and merge are O(n), and in the loop, you need to iterate over:

n+n/2+n/4+n/8+... = sigma(n/2^k) where k in (0,infinity) = 2n
0

精彩评论

暂无评论...
验证码 换一张
取 消