English 中文(简体)
证明使用微粒合并分类清单的算法
原标题:prove the algorithm that uses min-heap to merge k sorted lists

我读一下CLRS,在练习6.5-8时有一些问题。

Give an O(n lg k)-time algorithm to merge k sorted lists into one sorted list, where n is the total number of elements in all the inputs lists. (Hint: use a min0heap for k-way merging.)

大家都说,解决办法是

(1) 利用k清单的第一要素,建造一个lement粒,

2) 摘录(摘录)以获取最小元素,从肥皂中取到结果清单,

3)从上选取下一个内容,即我们刚刚从中选取的。 插入斜坡,第2段。

我可以理解时间是O(n lg k),但我并没有获得第3步中选择的正确性。 http://www.un.org/?

最佳回答

正确性证据的主旨是,剩下的最低要素始终是要提取的内容。 支持这一索赔的关键是,每个清单的优先顺序都包含该清单中剩下的最低内容。 因此,由于余下的最低部分也是从“<>/em>号”名单上删除的其余最低部分,因此由 extract取回。

我们需要从第3部分的同一清单中选择一个要素,以保持每个清单在调查表中至少有一个要素的不变性。 否则,我们可能会有这样的情况。

1 2
3 4

如果我们从包含1和3的首选中删除1个,将其改为4个,则下一次开采将是3个错误。

问题回答

暂无回答




相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签