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 Programmers by Justin Abrahms
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.5k
Technical Onboarding, Training, and Mentoring by Kate Heddleston and Nicole Zuckerman
pycon2014
1
2.1k
"My big gay adventure. Making, releasing and selling an indie game made in python." by Luke Miller
pycon2014
2
1.4k
Farewell and Welcome Home, Python in Two Genders by Naomi_Ceder
pycon2014
1
680
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
510
Hitchhikers Guide to Free and Open Source Participation by Elena Williams
pycon2014
6
1.1k
Localization Revisted (aka. Translations Evolved) by Ruchi Varshney
pycon2014
0
640
Smart Dumpster by Bradley E. Angell
pycon2014
0
450
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
680
Other Decks in Programming
See All in Programming
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
190
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
Rails と人魚の話/rails-and-mermaid
sanfrecce_osaka
0
100
Elm Form Validation
bkuhlmann
0
510
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
Anthropic Cookbook のおすすめレシピ
schroneko
7
870
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
260
Goのmultiple errorsについて (2024年4月版)
syumai
3
590
Hanami and htmx
bkuhlmann
0
210
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
360
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
4k
Featured
See All Featured
Designing for Performance
lara
601
67k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Code Review Best Practice
trishagee
55
15k
Writing Fast Ruby
sferik
621
60k
Adopting Sorbet at Scale
ufuk
68
8.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
120
39k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
40
4.4k
Web Components: a chance to create the future
zenorocha
305
41k
Navigating Team Friction
lara
178
13k
Faster Mobile Websites
deanohume
299
30k
The Cult of Friendly URLs
andyhume
74
5.7k
Being A Developer After 40
akosma
57
580k
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