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.1k
Localization Revisted (aka. Translations Evolved) by Ruchi Varshney
pycon2014
0
670
Smart Dumpster by Bradley E. Angell
pycon2014
0
480
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
700
Other Decks in Programming
See All in Programming
いまから追い上げる、Jetpack Compose トレーニング
nyafunta9858
0
250
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
630
エラーレスポンス設計から考える、0→1開発におけるGraphQLへの向き合い方
bicstone
5
1.5k
What you can do with Ruby on WebAssembly
kateinoigakukun
0
160
ブラウザ互換の重要性 - あらゆるユーザーに価値を届けるために必要なこと
yamanoku
0
110
Swiftコードバトル必勝法
toshi0383
0
150
長期運用プロダクトの開発速度を維持し続けるためのリファクタリング実践例
wataruss
8
2.7k
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
260
全部見せます! クラシルリワードのSwiftTesting移行プロジェクト
uetyo
0
190
The Shape of a Service Object
inem
0
480
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
410
開発を加速する共有Swift Package実践
elmetal
PRO
0
400
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Code Review Best Practice
trishagee
62
16k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
4 Signs Your Business is Dying
shpigford
179
21k
Speed Design
sergeychernyshev
22
420
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
Building a Modern Day E-commerce SEO Strategy
aleyda
36
6.8k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
3k
From Idea to $5000 a Month in 5 Months
shpigford
379
46k
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