text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
SPEAKER 1: Good question.
3,283.779
1.041
Could you make the whole list a big integer?
3,284.82
1.86
You could, that and other tricks.
3,286.68
1.73
But to do that, you're going to need to touch or somehow manipulate
3,288.41
4.28
all of those values at least once to kind of do that, I would think.
3,292.69
3.83
And so you've already spent n steps.
3,296.52
2.824
AUDIENCE: [INAUDIBLE].
3,299.344
0.916
SPEAKER 1: OK.
3,303.197
0.583
So if you have a like guessing algorithm-- yes, this is sorted.
3,303.78
4.4
That's constant time.
3,308.18
1.009
You're just not always correct.
3,309.189
1.291
So I should clarify, can you sort correctly n elements
3,310.48
3.86
without necessarily looking at all n-- the short answer is no.
3,314.34
3.24
There is like a fundamental limit of computation.
3,317.58
2.3
And also, just human intuition here.
3,319.88
1.89
You can't possibly claim to me and convince me, in a court of law even,
3,321.77
4.53
that these n elements are sorted if you can't even
3,326.3
2.48
testify to having looked at all n of those elements.
3,328.78
2.88
It's just not possible given the computational model
3,331.66
2.47
we've been discussing where a computer can only look at one element at a time.
3,334.13
3.89
So sorting is out of the question.
3,338.02
1.85
But an algorithm that takes omega of one step?
3,339.87
4.85
For instance in the best case, when might an algorithm need only one step?
3,344.72
5.64
How about something like linear search or even binary search?
3,350.36
3.93
The running time of those algorithms was big O of n and big O of log n
3,354.29
4.98
respectively.
3,359.27
0.95
Linear search, binary search.
3,360.22
2.8
What's the lower bound on those two algorithms' running times?
3,363.02
2.91
AUDIENCE: [INAUDIBLE].
3,370.407
0.933
SPEAKER 1: Yeah, it's omega of 1.
3,371.34
1.6
But why?
3,372.94
1.99
Derek wasn't so lucky.
3,374.93
1.08
But AJ, last year, touched the number 50-- voila, 1 step.
3,376.01
3.87
And that was actually, while sort of bad pedagogy for us,
3,379.88
3.42
was a perfect manifestation of yes, in the best
3,383.3
2.78
case the lower bound on your running time might indeed just be one step.
3,386.08
3.43
Or two steps, but some constant number of steps.
3,389.51
2.54
So we have a range of these options.
3,392.05
2.05
Now, sometimes these ranges coincide.
3,394.1
2.73
If your big O notation, so to speak, and your omega notation, so to speak,
3,396.83
4.16
are one in the same values, you can claim that the algorithm
3,400.99
2.95
has a running time in capital Theta.
3,403.94
2.77
So theta just means when big O and omega are the same,
3,406.71
3.35
you can instead use this formula and sort of convey two thoughts at once.
3,410.06
3.69
But for now, the takeaway is that as best we've
3,413.75
2.48
seen for something like sorting, the best we've done so far, at least
3,416.23
4.64
in the worst case, is big O of n squared.
3,420.87
2.022
And this doesn't feel very good, especially since sorting and searching
3,422.892
2.958
is all around us.
3,425.85
0.84
Anyone with an iPhone or an Android.
3,426.69
1.714
I mean, there's so much data that we're carrying around in our pockets
3,428.404
2.916
these days, let alone in the cloud and on our laptops and desktops,
3,431.32
3.08
that it's just generally good practice to keep sorted.
3,434.4
2.65
In your phone book, it would be pretty tedious
3,437.05
2.08
if all of your friends and family were in random order in the contacts list.
3,439.13
3.77
And you had to like scroll through the whole darn list, big O of n,
3,442.9
3.31
to find someone.
3,446.21
1.43
No, instead we have a search box, of course.
3,447.64
1.952
And most of us probably wouldn't blindly scroll through the whole list.
3,449.592
2.958
But even that search box, if you start typing in D-E-R to look up Derek,
3,452.55
4.36
or S-M-I-T-H to find Smith.
3,456.91
2.58
Well, how is iOS?
3,459.49
1.35
How is Android finding Mike Smith or finding Derek?
3,460.84
3.54
Those pieces of software themselves have algorithms that underneath the hood
3,464.38
5.92
are hopefully leveraging smarter algorithms than we've even seen here.
3,470.3
4.277
Because especially as you have more and more friends, more and more family
3,474.577
3.083
members, even big O of n squared starts to feel kind of slow
3,477.66
3.92
as we can see here.
3,481.58
1.37
Let me go ahead and open up an example.
3,482.95
4.384
So let's take a look at a demonstration.
3,487.334
1.666
Here is a visualization that someone on the internet kindly put together.
3,489
3.31
And it focuses on sorting numbers.
3,492.31
1.96
But rather than just show the numbers textually as 1, 2, 3, 4, 5, 6, 7, 8,
3,494.27
3.56
it instead shows them as bar.
3,497.83
1.36
So the shorter the bar, the smaller the number.
3,499.19
2.05
The taller the bar, the taller the number.
3,501.24
1.956
And let me go ahead and increase the speed of this,
3,503.196
2.124
just so it doesn't get too tedious.
3,505.32
1.61
And let's take a quick look at bubble sort.
3,506.93
3.39
Now, notice what's happening.
3,510.32
1.69
The two red bars adjacently are the ones that are
3,512.01
3.21
being compared and potentially swapped.
3,515.22
1.9
And you'll notice that just like in our human demo, what is happening over
3,517.12
3.13
there on the right-hand side?
3,520.25
3.525
AUDIENCE: [INAUDIBLE].
3,523.775
1.059
SPEAKER 1: Yeah.
3,524.834
0.666
So the biggest elements seem to be bubbling up, if you will, to the top.
3,525.5
4.71
Even though there's still a lot of work to be done to the left of those,
3,530.21
3.64
we indeed have the ability here to see the list getting sorted progressively.
3,533.85
7.394
But you know, I'm already getting bored.
3,541.244
1.666
This algorithm doesn't feel very fast.
3,542.91
1.583
It's very pretty.
3,544.493
0.907
It's very correct, it would seem, but it's a little slow.
3,545.4
3.09
Let's try another one to see if it's any better than that.
3,548.49
3.67
That's the spoiler.
3,552.16
0.84
That's what it should look like.
3,553
1.333
Let's try our friend selection sort, which is already sorted.
3,554.333
3.477
Let me stop this.
3,557.81
2.71
Let me click on Randomize Array.
3,560.52
3.86
And now click Selection Sort.
3,564.38
1.7