NoteJ++
Friday, June 16, 2017
Basic CS Algorithm Review
Quick Sort
直覺想法:
divide and conquer
divide:
一個陣列輸入,透過pivot來分三類:
小於(丟進子問題排序)
pivot
大於(丟進子問題排序)
conquer:
把上述三類合再一起
return:
當子問題輸入的陣列長度小於等於1 (不用再排序了,所以回傳)
平均複雜度:O(nlogn)
每個點走一次和pivot比較大小 -> n
binary divide and conquer -> logn (樹的深度)
code:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment