為什麼這篇Sorted 意思鄉民發文收入到精華區:因為在Sorted 意思這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者cksh8008 (ck)看板Grad-ProbAsk標題[理工] sorted list時間W...
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