dkethin

本博客仅为学习日志!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2009年2月18日

摘要: 习题9.1-1 Show that the second smallest of n elements can be found with n + ⌈lg n⌉ - 2 comparisons in the worst case. (Hint: Also find the smallest element.) 卡了2个小时,其实看到lg n 已经往heap那里想了,但总是想当然的以为T(n)是O(... 阅读全文

posted @ 2009-02-18 03:07 kethin 阅读(314) 评论(0) 推荐(0)

2009年2月16日

摘要: 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 input lists. (Hint: Use a min-heap for k-way merging.) 我的解决思路是 Heaps i... 阅读全文

posted @ 2009-02-16 00:33 kethin 阅读(439) 评论(2) 推荐(0)

2009年2月15日

摘要: 要证明循环正确,必须在以下三个环节中,考虑 循环不变量的真假。 循环初始状态:在所有循环体执行前,循环不变量成立。 循环进行时:如果在一个循环体开始执行之前,不变量成立,那么在下一个循环体执行之前,不变量仍然成立。 循环终结后:当整个循环结束时,不变量可以直接说明算法的正确性。 以Insertsort为例,要证明其外循环的正确性。 Code Code highlighting prod... 阅读全文

posted @ 2009-02-15 19:33 kethin 阅读(2345) 评论(0) 推荐(0)