【发布时间】:2015-02-25 06:50:10
【问题描述】:
所以我正在研究一个算法问题,并且对正确答案应该是什么样子感到非常困惑。我有一个答案,但如果有人能给我反馈/指导,我将不胜感激。
问题:
Casc Merge is a recursive algorithm: Assume there
are n sorted lists, each of size m. Recursively
Casc Merge the first n − 1 lists and then
Merge the last list (of size m) into the sorted list A (which is of size (n-1)m).
1)Write down code for it
这是我目前所想到的。看来我希望自己走在正确的轨道上,但就像我说的那样,我不知道。我尝试谷歌搜索并没有得到太多帮助
proc Cas(A, L, c)
if c == n then
Merge(A, L[c-1], L[c])
end if
else
Merge(A, Casc(A, L, c), Casc=(A, L, c+1))
end else
end proc
再次感谢您对伪代码的任何建议/反馈。
假设合并进行 m + n - 1 次比较
S(n) = { 1 if c = 1
S(n-1) + m - 1 otherwise
}
【问题讨论】:
标签: algorithm sorting merge mergesort