Merging Skip Lists

How can I combine 2 specified by Skip lists (each with n keys) into one single Skip List in O(n) time complexity (worst case)?

Just looking for an algorithm - there is no specific implementation / language.

+6
source share
1 answer
 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) 

this is really O (n), because store and merge are O (n), and in a loop you need to iterate:

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

Source: https://habr.com/ru/post/887545/


All Articles