2.5.Quick sort
Last updated
Was this helpful?
Last updated
Was this helpful?
Introduction
目前被認為效率最高的排序演算法(sorting algorithm)
快速排序法也是利用,不斷地將資料分成兩部分以解決問題
最佳時間複雜度:O(nlog n)
平均時間複雜度:O(nlog n)
最差時間複雜度:O(n2)
空間複雜度:O(n)
實作步驟:
1.選擇序列中的一個數字為pivot(通常為最左邊的數字)
2.將此序列中大於pivot的數字放到pivot右邊, 小於pivot的放到pivot左邊
3.以pivot為中心, 將左半部與右半部各自進行步驟1~2
程式碼