text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
You only need n steps for linear search.
3,000.37
2.07
But what if you want to instead find an algorithm that's logarithmic?
3,002.44
4.72
What algorithm that we used might be logarithmic in nature?
3,007.16
5.03
Binary.
3,012.19
0.62
So binary search, as Derek proposed, once we knew the list was sorted
3,012.81
4.54
was an alternative to that.
3,017.35
2.32
And constant time.
3,019.67
0.94
What about this?
3,020.61
2.46
What's an algorithm, maybe independent of today,
3,023.07
2
that allows you constant time, running time?
3,025.07
2.63
It could be anything.
3,034.986
0.874
How about hello world?
3,035.86
2.79
The [? say ?] block, or printf like that.
3,038.65
1.95
If you can just say a whole phrase at once.
3,040.6
2.15
Or maybe just adding two numbers together is like one step.
3,042.75
3.57
No matter how big the numbers are, it still just takes one step
3,046.32
2.674
to add them all together.
3,048.994
1.041
It depends on some of the lower-level implementation details.
3,050.035
2.365
And even printf or the [? say ?] block has multiple characters.
3,052.4
2.56
So we'll actually come back to this in the future
3,054.96
2.041
as to what it really means to be a step.
3,057.001
1.819
But anything that takes a constant number of steps.
3,058.82
2.95
Checking an "if" condition, returning a value.
3,061.77
2.4
Statements, generally, might be broadly speaking just constant time,
3,064.17
3.24
but we'll see contradictions to that before long.
3,067.41
2.82
So let's take a look at two other symbols.
3,070.23
2.02
This one being a capital omega symbol.
3,072.25
2.56
And this omega symbol is the opposite, really, of big O. Big O
3,074.81
3.64
is an upper bound on the running time.
3,078.45
1.61
In the worst case, how many steps might it
3,080.06
1.75
take to find an element in a list of n elements?
3,081.81
2.97
n steps.
3,084.78
1.05
So big O of n.
3,085.83
1.137
Bubble sort, selection sort, insertion sort?
3,086.967
1.833
They're on the order of n squared.
3,088.8
1.69
But what about the lower bound?
3,090.49
1.78
Especially when you get lucky in the best case so to speak,
3,092.27
2.9
how few steps might you solve problems with?
3,095.17
2.58
So for instance, if we consider the same formulas,
3,097.75
2.78
but this time with capital omega, what's an algorithm
3,100.53
3.22
that no matter what takes n squared steps,
3,103.75
3.58
even if, for instance, the list is sorted?
3,107.33
3.88
So suppose our 8 volunteers here were already 1, 2, 3, 4, 5, 6, 7, 8.
3,111.21
4.58
Which of those algorithms would still have required n squared steps?
3,115.79
3.79
So not linear search or binary search because those are much lower.
3,125.52
3.25
But insertion, bubble sort, selection sort.
3,128.77
4.55
Well, what about selection sort?
3,133.32
1.66
Even if the list is already sorted, how do I find the smallest element?
3,134.98
3.71
I'm lucky and it's right here, but I don't know that yet, right?
3,138.69
3.62
To know that, I have to confidently walk the whole list and realize,
3,142.31
3.209
well, that was a waste of time.
3,145.519
1.291
1 is indeed the smallest element.
3,146.81
1.54
It's sorted.
3,148.35
0.93
How do I find the next smallest element?
3,149.28
3.09
Start at the left.
3,152.37
0.844
But you can ignore number 1.
3,153.214
1.166
So it's a minor savings.
3,154.38
1.39
OK, 2.
3,155.77
0.77
Feel's pretty small, but got to check.
3,156.54
3.16
Dammit, that was the smallest.
3,159.7
1.65
And so selection sort, even in the best case when the list is already sorted,
3,161.35
5.72
is going to take at least on the order of n squared
3,167.07
4.09
steps because of that naivete of it.
3,171.16
2.09
Because of that underlying design of just looking
3,173.25
2.23
for the smallest element with no optimizations means
3,175.48
2.77
the algorithm's always going to take us that many steps.
3,178.25
2.34
But it doesn't have to be that way.
3,180.59
1.458
What about bubble sort?
3,182.048
1.052
Suppose that all 8 humans are sorted, 1 all the way through 8.
3,183.1
3.52
And here I am comparing the first two.
3,186.62
1.77
1 and 2?
3,188.39
0.76
Not out of order.
3,189.15
1.13
2 and 3, 3 and 4, 4 and 5, 5 and 6, 6 and 7, 7 and 8.
3,190.28
5.04
OK, everything looks good.
3,195.32
1.43
And in particular, what did I not do while walking from left to right?
3,196.75
5.714
I didn't do any swaps.
3,202.464
0.916
So it would be foolish of me algorithmically to do any of that
3,203.38
3.03
again because the answer is not going to change.
3,206.41
2.27
And so done.
3,208.68
0.63
It took me n steps to sort n elements with bubble sort
3,209.31
3.69
if the list is already sorted.
3,213
2.08
So it would be omega of n because in the best case, it takes you n steps.
3,215.08
4.33
Could a sorting algorithm be constant time
3,219.41
3.58
or logarithmic, log n or order of 1?
3,222.99
3.74
Or omega of 1 rather?
3,226.73
3.32
Can you sort n elements in logarithmic time or constant time?
3,230.05
5.494
What's the intuition there?
3,239.26
1.36
These are kind of like now the fundamental meaning of computing
3,240.62
3.36
and what you can actually do.
3,243.98
1.63
What does it mean for me to ask, can you sort n elements
3,245.61
3.08
in log n time or constant time?
3,248.69
2.37
Well, that effectively is like saying, can you
3,251.06
2.76
sort n elements without even looking at some of those elements?
3,253.82
4.81
Because both log n and 1-- or mathematically,
3,258.63
3.14
and if you don't recall, take it on faith today-- less than omega of n
3,261.77
4.19
in general.
3,265.96
1.27
So can you possibly, intuitively, in the real world,
3,267.23
3.29
sort n elements in some random order in fewer than n steps?
3,270.52
6.17
Yeah.
3,276.69
1.098
AUDIENCE: [INAUDIBLE].
3,277.788
0.916