摘要: Q:What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm ?The exact complexity and why ??A:if we use 2 element as a pivot (suppose 1st and last element) then we partisan the array into three part and we use quick shot in every partisanSo the new recurrence 阅读全文
posted @ 2012-06-25 10:55 百分百好牛 阅读(197) 评论(0) 推荐(0) 编辑
摘要: Two sorted array. Find kth smallest elementO(logK)A:Compare A[k/2] and B[k/2].If A[k/2] < B[k/2], it means these A[1] to A[k/2] elements are part of first k elements.Now, the kth element can be in A[k/2 + 1] to A[k] or B[1] to B[k/2]. (note: here may be B[1] to B[k], *not* B[k/2])Hence, we reduce 阅读全文
posted @ 2012-06-25 10:46 百分百好牛 阅读(637) 评论(0) 推荐(0) 编辑