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
30
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
38
How do we create the first impressions?
cheesecakelabs
0
42
Menstrual cup: suit and freedom
cheesecakelabs
0
43
Life is a cycle, better with a bicycle
cheesecakelabs
0
37
Interview Process: how to get the best of people
cheesecakelabs
1
64
My capsule wardrobe experience
cheesecakelabs
3
48
Stonewall Rebellion and its impact on LGBTQIA+ history
cheesecakelabs
1
27
Pregnancy, childbirth and breastfeeding: What do I have to do with it?
cheesecakelabs
0
38
MBTI - Psychological types described by Jung
cheesecakelabs
0
88
Other Decks in Programming
See All in Programming
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
260
HUIT新歓2024「競技プログラミング、やってみませんか?」
slephy2784
1
270
ゆるい個人開発のススメ
kuroppe1819
10
980
Designing for tomorrow's programming workflows
honnibal
PRO
2
120
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
660
Netty Chicago Java User Group 2024-04-17
sullis
0
170
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
190
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
260
VS Code をプロダクトにどう取り込むか
onomax
1
350
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
Hanami and htmx
bkuhlmann
0
200
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
260
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Principles of Awesome APIs and How to Build Them.
keavy
121
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
YesSQL, Process and Tooling at Scale
rocio
164
13k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Fantastic passwords and where to find them - at NoRuKo
philnash
37
2.5k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.6k
Git: the NoSQL Database
bkeepers
PRO
422
63k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Happy Clients
brianwarren
92
6.4k
Visualization
eitanlees
136
14k
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!