【问题标题】:Merge of Skip Lists跳过列表的合并
【发布时间】:2011-08-21 01:08:40
【问题描述】:

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

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

【问题讨论】:

    标签: algorithm data-structures merge skip-lists


    【解决方案1】:
    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),因为store和merge都是O(n),在循环中,你需要迭代:

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

    【讨论】:

    • 我不确定我是否正确使用了跳过列表的术语(在循环中),但我确信这个解决方案是正确的。如果您有不明白的地方,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    相关资源
    最近更新 更多