text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
This is going to be Z, so I'll just put this over here.
5,451.47
3.97
This is going to be C, so I'll put this over here, and B here, and A.
5,455.44
5.925
And we thought we might get chased away by the folks on the loading dock,
5,461.365
4.025
so we didn't bother getting D through Y, So we'll just pretend
5,465.39
2.98
that we have 26 such buckets here.
5,468.37
2.01
And suppose that the goal at hand is-- I don't know,
5,470.38
3.482
it's like at the end of an exam, so we've
5,473.862
1.708
got our old blue books that a class might use for students
5,475.57
3.23
writing essays in some class.
5,478.8
1.67
And it's time for the students to come submit their blue books.
5,480.47
3.16
Now, we could just collect them all and make a big mess as would generally
5,483.63
3.28
be the case, or we can be a little more methodical to at least make
5,486.91
3.24
our jobs easier.
5,490.15
1.384
Now, at the end of the day, what's going to be interesting about hash tables
5,491.534
3.166
is that there's going to be this distinction
5,494.7
1.833
between actual benefits and theoretical benefit, or lack thereof.
5,496.533
3.317
So, we'll come to that in just a moment, but here's A, B, C, D, and Z.
5,499.85
4.181
And you know what?
5,504.031
0.749
I just am going to ask the students in this class-- there are so
5,504.78
1.99
many people in the room after an exam, I just
5,506.77
2.27
want them to at least make my life 1/26 as difficult
5,509.04
4.96
by putting all the As over there, all the Bs here, all the Cs here,
5,514
3
all the Zs here, so that I don't have a massive mountain of As through Zs
5,517
4.66
that I have to sift through individually.
5,521.66
2.12
It would just be nice if they do the first pass
5,523.78
2.22
of bucketizing the values based on the first letter in their last name.
5,526
4.13
In other words, my hash function, my algorithm,
5,530.13
3.48
is going to be for each student to consider his or her last name,
5,533.61
4.09
look at the first letter they're in, and put his or her exam
5,537.7
3.22
in the appropriate bucket.
5,540.92
1.38
So, here is, for instance, someone with the letter
5,542.3
3.34
C. I'm going to put that blue book in here.
5,545.64
2.63
Here's someone with the letter A. That one's going to go here.
5,548.27
2.62
Letter Z?
5,550.89
0.746
This one's going to go over here.
5,551.636
1.374
Letter B?
5,553.01
1.11
This is going to go over here.
5,554.12
1.25
C, and B, and F-- Z, I mean, and all of [? the ?] [? letters ?] of the alphabet
5,555.37
6.8
in between.
5,562.17
0.78
So, hashing really has this visual and conceptual equivalence
5,562.95
3.774
of putting something in this bucket, putting something in that bucket,
5,566.724
2.916
putting something in this other bucket, ultimately
5,569.64
2.083
bucketizing all of your elements.
5,571.723
2.147
And you can think of this, frankly, as just an array,
5,573.87
2.21
but it's not just an array with one spot.
5,576.08
1.72
It looks I can stack multiple numbers or multiple blue books inside
5,577.8
5.04
of that array.
5,582.84
0.71
So, we're going to have to come back to that, because this clearly
5,583.55
1.55
can't be an array.
5,585.1
0.75
Normally, the array would be filled the moment you put one value in it.
5,585.85
3.2
But this hashing is the interesting part.
5,589.05
2.93
The juicy ingredient today is if I take into account as input what it is I'm
5,591.98
4.87
trying to store, use some piece of that information to decide where to put it,
5,596.85
4.66
that's an algorithm, because I can repeat that process,
5,601.51
2.85
so long as it's not random.
5,604.36
1.27
You go over here, you go over here.
5,605.63
1.51
That's amazing.
5,607.14
1.04
Wow, OK, pushing my luck.
5,608.18
2.84
OK, so I'm not just randomly putting things here.
5,611.02
2.644
I'm actually giving some thought as to where I'm putting things,
5,613.664
2.666
and that makes the algorithm deterministic, repeatable, predictable
5,616.33
4.54
so that if you insert something now, you can absolutely
5,620.87
3.38
find it if present later.
5,624.25
2.37
Unfortunately, if our hash table does look
5,626.62
2.03
like this, just a simple array from bracket 0 to bracket n minus 1 dot,
5,628.65
4.12
dot, dot in between, and it's just an array
5,632.77
2.33
for integers or an array for strings or whatever, once you put something here,
5,635.1
5.59
or here, or here, that's it.
5,640.69
3.14
There is no more room to put another element there
5,643.83
2.64
wide as I might have drawn this table.
5,646.47
1.94
If there's an int there, that's it.
5,648.41
1.98
So, what could you do?
5,650.39
2.12
Suppose that you do have an array structure like this,
5,652.51
4.06
and that is unacceptable.
5,656.57
3.47
You have a whole bunch of elements here and this table looks like this,
5,660.04
6.96
and you consider this table like this.
5,667
3.62
And maybe it's just where you're supposed to take attendance or put
5,670.62
3.04
people's names.
5,673.66
0.914
So, if you say, oh, Alice is here today.
5,674.574
1.666
Let me go ahead and hash on Alice's name and put her where the As should go.
5,676.24
4.225
Oh, Zoe is here, Z-O-E, so we'll put her down there.
5,680.465
5.685
And then who else?
5,686.15
1.83
Alex is here.
5,687.98
0.77
Dammit, Alex, no room for you in our hash table,
5,688.75
3.34
because Alice is already there.
5,692.09
1.38
This is stupid.
5,693.47
0.78
If we have data we want to insert into this data structure,
5,694.25
2.47
it would seem that I have 24 available spots into which I could put Alex
5,696.72
6.22
and yet I'm just stubbornly trying to put him where only the As belong.
5,702.94
3.58
So, why don't I, in this kind of scenario, I need to put Alex in here.
5,706.52
3.85
I clearly have space.
5,710.37
0.997
You know what?
5,711.367
0.583
Let me just probe the array looking for the first available spot.
5,711.95
2.91
OK, Alex, you're just going to go here, and if someone else like Erin appears,
5,714.86
5.43
fine.
5,720.29
0.5
You just are going to go over here.
5,720.79
2.29
So, you try to put the letter As where you want them to go,
5,723.08
3.77
but if there's already someone there, just
5,726.85
1.77
probe deeper into the data structure looking for the first available slot.
5,728.62
4.07
So, this is a general technique in programming called linear probing
5,732.69
3.35