text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
How many pairs of people did I consider in my first pass?
2,484.67
4.321
Say again.
2,488.991
0.499
AUDIENCE: 7.
2,489.49
0.499
SPEAKER 1: 7.
2,489.989
0.921
Because if you pair the first and the second,
2,490.91
2.019
then the second and the third, then the third and the fourth,
2,492.929
2.541
that gives you n minus 1 generally speaking.
2,495.47
2.13
You can't make 8 pairs out of 8 people.
2,497.6
1.65
You can make 7 pairs if you keep walking through the list.
2,499.25
2.542
We're not doing permutations.
2,501.792
1.208
We're just doing adjacent neighbors.
2,503
2.25
OK.
2,505.25
0.5
So that might generically be n minus 1 total steps
2,505.75
3.3
for the first pass of my algorithm.
2,509.05
1.72
But the upside of that was that our eighth volunteer, number 8,
2,510.77
3.39
bubbled his way all the way up to the end.
2,514.16
2.95
And so with bubble sort, I didn't need to consider him again.
2,517.11
3.01
The biggest number bubbled all the way up.
2,520.12
2.3
And so that was done.
2,522.42
1.14
So how many pairs did I need to consider the second time through bubble sort?
2,523.56
6.03
6.
2,529.59
0.5
Or more generically, n minus 2.
2,530.09
3.68
And then dot, dot, dot, until there was just one pair of two people left.
2,533.77
4.41
So I'll just do plus dot, dot, dot plus 1.
2,538.18
2.727
Now, you might recall from high school especially,
2,540.907
2.083
at least my math or physics textbooks always
2,542.99
1.833
had a little cheat sheet for like what these kinds of recurrences or formulas
2,544.823
3.277
add up to.
2,548.1
0.5
Does anyone recall what this one adds up to in a math book?
2,548.6
3.96
Or just mathematically?
2,552.56
3.27
So if we actually do this out, it's the same thing, beautifully,
2,555.83
3.57
as n times n minus 1 over 2.
2,559.4
3.25
And that, of course if you multiply things out,
2,562.65
3.63
is just the same thing as n squared minus n over 2.
2,566.28
3.26
And that, of course, feels like it would just multiply out to this.
2,569.54
6.35
So in other words, if asked, what is the efficiency of bubble sort,
2,575.89
2.97
or what is the running time of bubble sort to soar n elements,
2,578.86
3.47
you might sort of impressively say, well, it's
2,582.33
1.94
n squared divided by 2 minus n over 2.
2,584.27
2.37
But what does that actually mean?
2,586.64
1.51
Well, it turns out that when talking about the efficiency of algorithms,
2,588.15
3.42
you should really generally care about the component that
2,591.57
3.4
has the biggest order of magnitude.
2,594.97
2.07
The number that contributes the most to the total cost.
2,597.04
2.94
And by that I mean this, which is obviously bigger, n squared or n?
2,599.98
4.04
Assuming positive values of n.
2,604.02
1.68
So n squared, right?
2,605.7
1.13
Especially as n gets bigger, n squared is going to get even bigger than n.
2,606.83
3.692
So you know what?
2,610.522
0.708
I'm just going to kind of propose, let's just ignore the n minus 2
2,611.23
3.77
because as n gets really big, the dominating factor really
2,615
2.69
is going to be n square.
2,617.69
1.24
And for that matter, the n over 2, like who cares about the over 2?
2,618.93
2.82
n squared is kind of the essence of this formula right now.
2,621.75
3.672
So what does that mean?
2,625.422
0.958
Well, let's just do a concrete example to convince you of the fact
2,626.38
2.749
that we can cut a little bit of mathematical corner here
2,629.129
2.911
and only care about the big number for the following example.
2,632.04
2.792
This is proof by example, which is not a proof of anything.
2,634.832
2.458
It's just really to paint a picture of why we do this intuitively.
2,637.29
4.03
So suppose that there are a million volunteers on stage or a million
2,641.32
2.892
numbers that we want to sort.
2,644.212
1.208
Much bigger than 8.
2,645.42
1.55
Let's plug this in.
2,646.97
1.15
So if the total cost of bubble sort is n squared over 2 minus n over 2,
2,648.12
3.83
let's plug that in.
2,651.95
0.85
So that's a million squared divided by 2 minus a million divided by 2.
2,652.8
4.75
So if we multiply that out, that is 500 billion minus 500,000.
2,657.55
5.39
Big numbers.
2,662.94
0.86
But when you multiply that out, I mean-- my god, 499,999,500,000.
2,663.8
5.25
I mean, to my own eyes, that's pretty darn close to 500 billion
2,669.05
5.24
in the first place.
2,674.29
0.797
Why don't we just call it 500 billion?
2,675.087
1.583
So n squared, in other words.
2,676.67
1.489
So again, this is not a formal proof of anything.
2,678.159
2.041
But this is why, especially as n gets bigger,
2,680.2
2.25
that lower-ordered term, the minus n over 2,
2,682.45
2.53
just matters less and less and less in absolute form.
2,684.98
3.37
And so we'll generally say that something like bubble sort,
2,688.35
2.98
its running time is on the order of n squared.
2,691.33
3.6
Big O is actually formal computer science notation for on the order of.
2,694.93
4.097
And it has a formal mathematical definition.
2,699.027
1.833
But for us, we'll consider it really to be an upper bound on the running
2,700.86
5.57
time of this algorithm.
2,706.43
1.38
So an upper bound on how long this algorithm might take given n steps.
2,707.81
4.29
So big O itself is a formal notation.
2,712.1
2.14
We'll see it in a number of different contexts.
2,714.24
2.04
Depending on the algorithms we talk about in class,
2,716.28
2.31
we might say that the running time of an algorithm
2,718.59
2.083
is on the order of n squared, which is pretty bad.
2,720.673
2.687
Pretty slow. $500 billion sounds like a lot.
2,723.36
2.21
Well, maybe it's a little better on the order of n times log n.
2,725.57
2.625
And more on that some other time-- later.
2,728.195
2.955
But on the order of n, it was pretty good.
2,731.15
2.5
If there's n elements, it only takes you roughly n steps.
2,733.65
2.54
Maybe it's even better big O of log n.
2,736.19
2.88
Or really best would be big O of 1.
2,739.07
2.565
It just takes 1 step, or 10 steps, or 100 steps,
2,741.635
2.595
but a constant number of steps is what big O of 1 represents.
2,744.23
4.05
And there's any number of other formulas we
2,748.28
2.2