[理工] sorted list

看板Grad-ProbAsk作者 (ck)時間10年前 (2013/12/18 11:54), 編輯推噓2(208)
留言10則, 4人參與, 最新討論串1/1
1.Explain the sorting algorithm that is most suitable to be used with single linked list? You need to explain why your sorting algorithm could be better then others. 這題我想寫bubble sort 因為bubble sort每回可像array一樣,一開始就讓第一個元素和第二個元素依序往後比 而其他sort演算法,需先移動到第i項才可開始做排序 例如quick sort,光是由後往前找比pivot還小的值每回就需花O(N)^2 而bubble sort執行完成 worst case 為O(N)^2 best case可達O(N) 2.Suppose you are given a sorted list of N elements followed by f(N) randomly ordered elements. How would you best sort the entire list if i. f(N) = O(1) ii. f(N) = O(logN) iii. f(N) = O(根號N) iv. f(N) = How large can f(N) be for the entire list still to be sortable in O(N) time? 其實我不太懂這題再問什麼 希望前輩能指點一下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.20.242.232

12/18 12:07, , 1F
第二題題目的意思應該是有N個已經排好的東西後面接f(N)
12/18 12:07, 1F

12/18 12:07, , 2F
個沒排的,問要多快才能把後面排進去,直覺好像是inserti
12/18 12:07, 2F

12/18 12:07, , 3F
on不過貌似不好。
12/18 12:07, 3F

12/18 12:12, , 4F
第一題我會寫LSD吧 因為可以作為hash sorting用chain
12/18 12:12, 4F

12/18 12:13, , 5F
至於第二題 是在問可以突破nlogn限制達到O(n)?
12/18 12:13, 5F

12/18 13:01, , 6F
第二題有查到答案,i是insertion ii是merge sort
12/18 13:01, 6F

12/18 13:15, , 7F
第二題不是N個排好的,後面要接f(N)個排好的元素嗎
12/18 13:15, 7F

12/18 13:25, , 8F
應該吧手機排板出問題既然知道題目再問怎我就不解答了
12/18 13:25, 8F

12/18 14:03, , 9F
真是太感謝前輩了~
12/18 14:03, 9F

12/19 17:48, , 10F
merge sort
12/19 17:48, 10F
文章代碼(AID): #1IiHoBbn (Grad-ProbAsk)