Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Quick Sort
Search
KuoE0
March 15, 2013
Programming
5
10k
Quick Sort
KuoE0
March 15, 2013
Tweet
Share
More Decks by KuoE0
See All by KuoE0
Protocol handler in Gecko
kuoe0
0
100
面試面試面試,因為很重要所以要說三次!
kuoe0
2
270
應徵軟體工程師
kuoe0
0
180
面試心得分享
kuoe0
0
430
Windows 真的不好用...
kuoe0
0
310
Python @Wheel Lab
kuoe0
0
230
Introduction to VP8
kuoe0
0
270
Python @NCKU_CSIE
kuoe0
0
130
[ACM-ICPC] Tree Isomorphism
kuoe0
1
260
Other Decks in Programming
See All in Programming
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
dchart: charts from deck markup
ajstarks
3
990
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
250
CSC307 Lecture 02
javiergs
PRO
1
770
組織で育むオブザーバビリティ
ryota_hnk
0
170
CSC307 Lecture 08
javiergs
PRO
0
670
高速開発のためのコード整理術
sutetotanuki
1
390
CSC307 Lecture 04
javiergs
PRO
0
660
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
540
AI巻き込み型コードレビューのススメ
nealle
0
130
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
450
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
120
Statistics for Hackers
jakevdp
799
230k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
110
The Pragmatic Product Professional
lauravandoore
37
7.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
930
The Cult of Friendly URLs
andyhume
79
6.8k
Google's AI Overviews - The New Search
badams
0
900
Rails Girls Zürich Keynote
gr2m
96
14k
Transcript
Quick Sort ֲࢸݢʢKuoE0ʣ
[email protected]
KuoE0.ch
Latest update: Mar 15, 2013 Attribution-ShareAlike 3.0 Unported (CC BY-SA
3.0) http://creativecommons.org/licenses/by-sa/3.0/
Algorithm ࠾༻ divide & conquer ࡦུ
Divide ኺᏐྻதग़Ұݸݩૉ࡞ҝ pivotɼར ༻ pivot ሡݪᏐྻҝၷݸࢠᏐྻɿ • ॴ༗ݩૉখԙ pivot తᏐྻ
A • ॴ༗ݩૉେԙ pivot తݩૉతᏐྻ B • ԙ pivot తݩૉՄ์ஔࡏҰݸத
2 9 4 3 8 7 5 1 6
2 9 4 3 8 7 5 1 6 2
7 4 3 5 1 6 9 8
9 8 2 4 3 5 1 6 2 9
4 3 8 7 5 1 6 2 7 4 3 5 1 6 9 8
9 8 2 4 3 5 1 6 2 4
5 1 6 2 9 4 3 8 7 5 1 6 2 7 4 3 5 1 6 9 8 3
4 5 6 2 1 9 8 2 4 3
5 1 6 2 4 5 1 6 2 9 4 3 8 7 5 1 6 2 7 4 3 5 1 6 9 8 3
4 5 6 2 1 2 9 8 2 4
3 5 1 6 2 4 5 1 6 2 9 4 3 8 7 5 1 6 2 7 4 3 5 1 6 9 8 3 1
4 5 6 2 1 2 9 8 2 4
3 5 1 6 2 4 5 1 6 2 9 4 3 8 7 5 1 6 2 2 7 4 3 5 1 6 9 8 3 1
4 5 6 5 6 2 1 2 9 8
2 4 3 5 1 6 2 4 5 1 6 2 9 4 3 8 7 5 1 6 2 2 7 4 3 5 1 6 9 8 3 1 4
5 6 4 5 6 5 6 2 1 2
9 8 2 4 3 5 1 6 2 4 5 1 6 2 9 4 3 8 7 5 1 6 2 2 7 4 3 5 1 6 9 8 3 1 4
5 6 5 4 5 6 5 6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4 5 6 5 6 1 2 1 2 4 5 6 5 6 1 2 3 4 5 6 9 2 5 2 5 9 7 1 6 4 3 8
8 9 1 2 3 4 5 6 8 9
4 5 6 5 6 1 2 1 2 4 5 6 5 6 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 9 2 5 2 5 9 7 1 6 4 3 8
9 3 How to Divide 4 1 5 8 6
7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2
9 3 How to Divide 4 1 5 8 6
4 7 2 4 1 3 2 5 8 7 9 6
5 6 7 8 9 3 2 1 4 How
to Conquer
5 6 7 8 9 3 2 1 4 How
to Conquer
5 6 7 8 9 3 2 1 4 How
to Conquer
5 6 7 8 9 3 2 1 4 How
to Conquer
void quickSort( int L, int R ) { if (
R - L <= 1 ) return; int pivot = N[ R - 1 ], p = L; for ( int i = L; i < R - 1; ++i ) { if ( N[ i ] <= pivot ) { swap( N[ i ], N[ p ] ); ++p; } } swap( N[ R - 1 ], N[ p ] ); quickSort( L, p ); quickSort( p + 1, R ); } In-place Version
9 4 3 6 5 1 8 7 How to
Divide 2
9 4 3 6 5 1 8 7 How to
Divide 2 6
9 4 3 6 5 1 8 7 How to
Divide 2 2 6
9 4 3 6 5 1 8 7 How to
Divide 2 2 6
9 4 3 6 5 1 8 7 How to
Divide 2 2 2 6
9 9 4 3 6 5 1 8 7 How
to Divide 2 2 2 6
9 9 4 4 3 6 5 1 8 7
How to Divide 2 2 2 9 6
9 9 4 4 3 6 5 1 8 7
How to Divide 2 2 2 9 6
9 9 4 4 3 6 5 1 8 7
How to Divide 2 2 2 9 4 6
9 9 4 4 3 3 6 5 1 8
7 How to Divide 2 2 2 9 4 6
9 9 4 4 3 3 6 5 1 8
7 How to Divide 2 2 2 9 4 6
9 9 4 4 3 3 6 5 1 8
7 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 8
7 8 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 8
7 8 8 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 8
7 8 7 8 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 8
7 8 7 8 7 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 9 4 3 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 1 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 1 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 1 1 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 1 1 6
9 9 4 4 3 3 6 5 1 5
8 7 8 7 8 7 How to Divide 2 2 2 5 9 4 3 1 1 6 2 5 4 3 1 8 9 7
6 How to Conquer 1 4 2 3 5 8
7 9 1 4 2 3 5 8 7 9
6 How to Conquer 1 4 2 3 5 8
7 9 1 4 2 3 5 8 7 9
End