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
Algorithms & Complexity
Search
Cheesecake Labs
April 05, 2018
Programming
0
36
Algorithms & Complexity
Frank Kair
Cheesecake Labs
April 05, 2018
Tweet
Share
More Decks by Cheesecake Labs
See All by Cheesecake Labs
Cats' wellness & care
cheesecakelabs
0
49
How do we create the first impressions?
cheesecakelabs
0
53
Menstrual cup: suit and freedom
cheesecakelabs
0
57
Life is a cycle, better with a bicycle
cheesecakelabs
0
51
Interview Process: how to get the best of people
cheesecakelabs
1
81
My capsule wardrobe experience
cheesecakelabs
3
58
Stonewall Rebellion and its impact on LGBTQIA+ history
cheesecakelabs
1
37
Pregnancy, childbirth and breastfeeding: What do I have to do with it?
cheesecakelabs
0
45
MBTI - Psychological types described by Jung
cheesecakelabs
0
130
Other Decks in Programming
See All in Programming
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
820
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
2
520
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
140
Gleamという選択肢
comamoca
6
740
Benchmark
sysong
0
230
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
1
840
A2A プロトコルを試してみる
azukiazusa1
2
860
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
380
Perplexity Slack Botを作ってAI活用を進めた話 / AI Engineering Summit プレイベント
n3xem
0
670
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
0
3k
Go Modules: From Basics to Beyond / Go Modulesの基本とその先へ
kuro_kurorrr
0
120
Featured
See All Featured
Docker and Python
trallard
44
3.4k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Building Adaptive Systems
keathley
43
2.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Art, The Web, and Tiny UX
lynnandtonic
299
21k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
660
The Cost Of JavaScript in 2023
addyosmani
51
8.4k
Visualization
eitanlees
146
16k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
124
52k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Transcript
Algorithms & Complexity Frank Kair
Last time...
Project Euler
polyglot-euler
polyglot-euler
polyglot-euler
Fibonacci example
Analysis of Algorithms Asymptotics / Complexity Theory
None
Applied Maths → Computer Science
Complexity Analysis We need a way to define the runtime
of an algorithm regardless of the machine it’s currently running on.
Linear Search
Binary Search
Big O Big O is a mathematical notation that describes
the limiting behaviour of a function when the argument tends towards a particular value or infinity.
The letter O is used because the growth rate of
a function is also referred to as the order of the function. [...] an upper bound on the growth rate of the function. Big O
Big O
Big O Length Iteration worst case 1 1 10 10
100 100 1000 1000 10000 10000 … ...
Big O
None
Big O
How do we profile these algorithms?
Just count the loops, then?
Merge Sort
Merge Sort
Merge Sort
Merge Sort O(n)
Merge Sort
Merge Sort O(n)
Merge Sort O(n) O(n)
Merge Sort O(n) O(n) ?
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n T(n) = 2T(n/2) + n
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n T(n) = 2T(n/2) + n = 2 [ 2T(n/4) + n/2 ] + n
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n T(n) = 2T(n/2) + n = 2 [ 2T(n/4) + n/2 ] + n = 4T(n/4) + 2n = 4 [ 2T(n/8) n/4 ] + n = 8T(n/8) + 3n = 16T(n/16) + 4n = ... = (2^k)T(n/(2^k)) + kn
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn T(1) = c Merge Sort
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn T(1) = c n/(2^k) = 1 Merge Sort
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn T(1) = c n/(2^k) = 1 2^k = n Merge Sort
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn T(1) = c n/(2^k) = 1 2^k = n k = lg n Merge Sort
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn k = lg n T(n) = Merge Sort
Recurrence relation T(n) = c if n == 1 =
2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn k = lg n T(n) = (2^lg n)T(1) + n lg n Merge Sort
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn k = lg n T(n) = (2^lg n)T(1) + n lg n = cn + n lg n
Merge Sort Recurrence relation T(n) = c if n ==
1 = 2T(n/2) + n T(n) = (2^k)T(n/(2^k)) + kn k = lg n T(n) = (2^lg n)T(1) + n lg n = cn + n lg n O(n log n)
Does it matter?
Data Structures
Arrays vs Linked Lists
Binary Search Tree
B+ Trees
Back to Fibonacci… Why was it bad?
Fibonacci
Fibonacci
Fibonacci
Fibonacci
Fast Fibonacci
Paradigms / Techniques
Divide and Conquer Dynamic Programming Greedy Paradigms / Techniques
The Classics
Fast Fourier Transform Page Rank Dijkstra Miller-Rabin The Classics
Thank you!