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.3k
"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
720
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
530
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
690
Smart Dumpster by Bradley E. Angell
pycon2014
0
510
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
720
Other Decks in Programming
See All in Programming
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
時計仕掛けのCompose
mkeeda
1
290
SwiftUI Viewの責務分離
elmetal
PRO
1
220
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2.2k
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
45
16k
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
730
SpringBoot3.4の構造化ログ #kanjava
irof
2
980
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
740
Formの複雑さに立ち向かう
bmthd
1
810
Rails アプリ地図考 Flush Cut
makicamel
1
110
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Done Done
chrislema
182
16k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
How to train your dragon (web standard)
notwaldorf
91
5.8k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
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