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
Computer Science Fundamentals for Self-Taught P...
Search
PyCon 2014
April 11, 2014
Programming
4
1.8k
Computer Science Fundamentals for Self-Taught Programmers by Justin Abrahms
PyCon 2014
April 11, 2014
Tweet
Share
More Decks by PyCon 2014
See All by PyCon 2014
Postgres Performance for Humans by Craig Kerstiens
pycon2014
29
3.6k
Technical Onboarding, Training, and Mentoring by Kate Heddleston and Nicole Zuckerman
pycon2014
1
2.2k
"My big gay adventure. Making, releasing and selling an indie game made in python." by Luke Miller
pycon2014
2
1.5k
Farewell and Welcome Home, Python in Two Genders by Naomi_Ceder
pycon2014
1
700
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
520
Hitchhikers Guide to Free and Open Source Participation by Elena Williams
pycon2014
6
1.2k
Localization Revisted (aka. Translations Evolved) by Ruchi Varshney
pycon2014
0
680
Smart Dumpster by Bradley E. Angell
pycon2014
0
490
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
710
Other Decks in Programming
See All in Programming
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
190
Remix on Hono on Cloudflare Workers
yusukebe
1
290
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
cmp.Or に感動した
otakakot
3
190
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
130
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Happy Clients
brianwarren
98
6.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Typedesign – Prime Four
hannesfritz
40
2.4k
Designing for Performance
lara
604
68k
Agile that works and the tools we love
rasmusluckow
327
21k
Being A Developer After 40
akosma
87
590k
Site-Speed That Sticks
csswizardry
0
27
We Have a Design System, Now What?
morganepeng
50
7.2k
It's Worth the Effort
3n
183
27k
Side Projects
sachag
452
42k
Transcript
Justin Abrahms Computer Science for the self taught programmer http://bit.ly/1gfszix
Who am I? • Justin Abrahms • Director of Product
Engineering at Quick Left • Author of Imhotep • @justinabrahms or github://justinabrahms
Overview • How I learn about Big O? • What
is Big O? • How is Big O done? • Resources and learned wisdom
None
A sane data model
Our data model
Our ACTUAL data model
What does N+1 Selects look like? entries = get_post_ids() final_list
= [] for entry_id in entries: entry = get_entry(entry_id) final_list.append(entry)
Questions • How did I miss this? • How did
this guy know about it and I didn’t? • How can I make sure this never happens again.
–Wikipedia (aka Inducer of Impostor Syndrome) In mathematics, big O
notation describes the limiting behavior of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions.
–Me Big O is how programmers talk about the relation
of how much stuff is being done when comparing two pieces of code.
Google Study List Studied: • Data Structures • Algorithms •
System Design • Java Internals • Concurrency Issues
Google Study List Studied: • Data Structures! • Algorithms! •
System Design • Java Internals • Concurrency Issues These are Big O things
–Wikipedia A data structure is a particular way of storing
and organizing data in a computer so that it can be used efficiently.
–Wikipedia An algorithm is a step-by-step procedure for calculations
O(n)
What sorts of Big O are there? • O(1) —
Constant Time • O(log n) — Logarithmic Time • O(n) — Linear Time • O(n²) — Quadratic Time • O(n!) — Factorial Time
Intentionally left blank for people in the back
def get_from_list(idx, lst): return lst[idx] O(1)
def item_in_list(item, lst): for entry in lst: if entry ==
item: return True return False O(n)
Wait a second…
def item_in_list(item, lst): for entry in lst: if entry ==
item: return True return False O(n) — Broken Down
def item_in_list(item, lst): for entry in lst: O(n) if entry
== item: return True return False O(n) — Broken Down
def item_in_list(item, lst): for entry in lst: O(n) if entry
== item: O(1) return True return False O(n) — Broken Down
def item_in_list(item, lst): for entry in lst: O(n) if entry
== item: O(1) return True O(1) return False O(1) O(n) — Broken Down
def item_in_list(item, lst): for entry in lst: O(n) if entry
== item: O(1) return True O(1) return False O(1) O(n) — Broken Down =O(n) * O(1) + O(1)
Why don’t we say Big O of O(n) * O(1)
+ O(1)?
In non-“math-y” terms • If we plot our function, we
can also plot M * the big O and end up with a line that our function never crosses (for certain values of X)
Example O(n) * O(1) + O(1) Big O: To Plot:
?
Example O(n) * O(1) + O(1) Big O: To Plot:
x * ? O(n) always means x
Example O(n) * O(1) + O(1) Big O: To Plot:
x * 5 + 9 O(1) means pick any constant number
Example To Plot: x * 5 + 9
Example To Plot: x * 5 + 9
Example To Plot: x * 5 + 9
Is it O(1)? To Plot: x * 5 + 9
Is it O(n²)? To Plot: x * 5 + 9
Big O is an approximation of algorithmic complexity
def item_in_list(item, lst): for entry in lst: if entry ==
item: return True return False O(n)
What if the list is empty?
def item_in_list(item, lst): for entry in lst: if entry ==
item: return True return False O(n)
O(log n) The best example of O(log n) is binary
search.
O(log n) 1 2 3 4 5 6 7 8
9 10
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 6?
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 6? Nope.
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 3?
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 3? Nope.
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 4?
O(log n) 1 2 3 4 5 6 7 8
9 10 4 == 4? Yes!
def get_pairs(lst): pair_list = [] for i1 in lst: for
i2 in lst: pair_list.append([i1, i2]) return pair_list ! O(n²)
def get_pairs(lst): pair_list = [] O(1) for i1 in lst:
O(N) for i2 in lst: O(N) pair_list.append([i1, i2]) O(1) return pair_list O(1) ! O(n²)
def get_pairs(lst): pair_list = [] O(1) for i1 in lst:
O(N) for i2 in lst: O(N) pair_list.append([i1, i2]) O(1) return pair_list O(1) ! O(n²) = O(1) + O(n) * O(n) * O(1) + O(1)
O(n²) = O(1) + O(n) * O(n) * O(1) +
O(1)
O(n²) = O(1) + O(n) * O(n) * O(1) +
O(1)
O(n²) = O(1) + O(n) * O(n) * O(1) +
O(1) = O(n) * O(n) * O(1) + O(1) + O(1)
O(n²) = O(1) + O(n) * O(n) * O(1) +
O(1) = O(n) * O(n) * O(1) + O(1) + O(1) = x * x + 7 + 9 + 13
O(n²) = O(1) + O(n) * O(n) * O(1) +
O(1) = O(n) * O(n) * O(1) + O(1) + O(1) = x * x + 7 + 9 + 13 = x² + 29
O(n²) = x² + 29
O(n²) = x² + 29
O(n²) = x² + 29
O(n²) = x² + 29
Gotchas
The Big O of a function might not matter
Theoretical speed is different than practical speed.
This is probably not going to make your app faster.
Resources
Resources http://algorist.com/
Resources https://www.coursera.org/course/algo
Resources https://leanpub.com/computer-science-for-self-taught-programmers/
How do I write my code differently now?
Knowing Big-O doesn’t make you write your code differently.
Big O is… • useful in communicating about complexity of
code • basic arithmetic and algebra • used in talking about algorithms and data structures • not as hard as it originally sounds
Thanks •
[email protected]
• @justinabrahms • github.com/justinabrahms Credits: ! NYC
slide photo via flickr://Andos_pics