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
98
面試面試面試,因為很重要所以要說三次!
kuoe0
2
240
應徵軟體工程師
kuoe0
0
170
面試心得分享
kuoe0
0
410
Windows 真的不好用...
kuoe0
0
290
Python @Wheel Lab
kuoe0
0
210
Introduction to VP8
kuoe0
0
250
Python @NCKU_CSIE
kuoe0
0
120
[ACM-ICPC] Tree Isomorphism
kuoe0
1
250
Other Decks in Programming
See All in Programming
マイコンでもRustのtestがしたい その2/KernelVM Tokyo 18
tnishinaga
2
2.3k
testingを眺める
matumoto
1
110
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
210
実践!App Intents対応
yuukiw00w
1
360
Laravel Boost 超入門
fire_arlo
1
140
「リーダーは意思決定する人」って本当?~ 学びを現場で活かす、リーダー4ヶ月目の試行錯誤 ~
marina1017
0
240
Claude Codeで挑むOSSコントリビュート
eycjur
0
180
なぜ今、Terraformの本を書いたのか? - 著者陣に聞く!『Terraformではじめる実践IaC』登壇資料
fufuhu
4
670
Updates on MLS on Ruby (and maybe more)
sylph01
1
110
自作OSでDOOMを動かしてみた
zakki0925224
1
1.4k
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
990
TanStack DB ~状態管理の新しい考え方~
bmthd
2
340
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Thoughts on Productivity
jonyablonski
69
4.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
480
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Six Lessons from altMBA
skipperchong
28
4k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Statistics for Hackers
jakevdp
799
220k
Side Projects
sachag
455
43k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Music & Morning Musume
bryan
46
6.7k
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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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 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