text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
that a fellow educator made and posted online
3,358.2
2.1
that we've abbreviated here to give us a sense of the difference between stacks
3,360.3
3.99
and queues.
3,364.29
0.709
[AUDIO PLAYBACK]
3,364.999
0.666
[MUSIC PLAYING]
3,365.665
4.655
-Once upon a time, there was a guy named Jack.
3,370.32
2.91
When it came to making friends, Jack did not have the knack.
3,373.23
3.36
So, Jack went to talk to the most popular guy he knew.
3,376.59
2.98
He went to Lou and asked what do I do?
3,379.57
2.6
Lou saw that his friend was really distressed.
3,382.17
2.65
Well, Lou, began just look how you're dressed.
3,384.82
2.46
Don't you have any clothes with a different look?
3,387.28
2.73
Yes, said, Jack.
3,390.01
0.97
I sure do.
3,390.98
1.19
Come to my house and I'll show them to you.
3,392.17
2.46
So, they went off to Jack's, and Jack showed Lou the box
3,394.63
2.96
where he kept all his shirts, and his pants, and his socks Lou
3,397.59
3.22
said I see you have all your clothes in a pile.
3,400.81
2.82
Why don't you wear some others once in a while?
3,403.63
2.53
Jack said, well, when I remove clothes and socks,
3,406.16
3.17
I wash them and put them away in the box, then comes the next morning
3,409.33
4
and up I hop.
3,413.33
1.2
I go to the box and get my clothes off the top.
3,414.53
3.18
Lou quickly realized the problem with Jack.
3,417.71
2.73
He kept clothes, CDs, and books in a stack.
3,420.44
2.9
When he reached something to read or to wear
3,423.34
2.45
he chose [? the top ?] book or underwear.
3,425.79
2.62
Then when he was done he would put it right back,
3,428.41
2.41
back it would go on top of the stack.
3,430.82
2.49
I know the solution, said a triumphant Lou.
3,433.31
2.49
You need to learn to start using a queue.
3,435.8
2.59
Lou took Jack's clothes and hung them in a closet,
3,438.39
2.81
and when he had emptied the box he just tossed it.
3,441.2
2.84
Then he said, now, Jack, at the end of the day put your clothes
3,444.04
3.25
on the left when you put them away.
3,447.29
2.01
Then tomorrow morning when you see the sunshine,
3,449.3
2.51
get your clothes from right from the end of the line.
3,451.81
2.96
Don't you see, said Lou.
3,454.77
1.44
It will be so nice.
3,456.21
1.49
You'll wear everything once before you wear something twice.
3,457.7
3.4
And with everything in queues in his closet and shelf,
3,461.1
2.85
Jack started to feel quite sure of himself all thanks
3,463.95
3.06
to Lou and his wonderful queue.
3,467.01
4.576
[END PLAYBACK]
3,471.586
0.982
SPEAKER 1: All right, so let's take a look at another data type,
3,472.568
3.712
this one known as a tree.
3,476.28
1.94
Because now that we have the ability to stitch data structures together much
3,478.22
4.16
like a linked list, we now have the ability
3,482.38
1.89
to stitch things together not just left to right or top to bottom conceptually,
3,484.27
5.78
but in any number of directions.
3,490.05
1.345
And indeed, there's nothing stopping us from having
3,491.395
2.125
one node linked to by way of multiple pointers, multiple nodes.
3,493.52
4.41
So, for instance, this picture here from a textbook is a tree structure.
3,497.93
4.34
And it's very much like the family trees that you might
3,502.27
2.406
have drawn in grade school or the like.
3,504.676
1.624
But in this case, you have just one root node,
3,506.3
2.91
the node at the top of the data structure, so to speak,
3,509.21
2.53
from which everything else descends.
3,511.74
2.01
And that node is said to have children.
3,513.75
2.26
For instance, 2 and 3 are children of the node number 1 here.
3,516.01
4.06
And then there's other semantics in this world of trees in computer science.
3,520.07
3.52
Much like family trees, anything that does not
3,523.59
2.53
have children-- like 5, 6, and 7, or 8 and 9--
3,526.12
2.7
would be called leaves of the tree, because like the leaves
3,528.82
2.995
at the end of the branches, there is nothing beyond them.
3,531.815
2.375
So, nicely enough we borrow a lot of the language
3,534.19
2.53
from family trees and actual trees in order
3,536.72
2.75
to discuss this data structure known as a tree.
3,539.47
3.14
But why in the world would we want to lay out data in a tree structure?
3,542.61
5.05
Now we just seem to be doing things because we can,
3,547.66
3.06
it would seem at first glance.
3,550.72
1.57
Because, for instance, suppose we had these numbers-- 22, 33, 44, 55, 66, 77,
3,552.29
5.14
and 88.
3,557.43
1.1
They're clearly sorted.
3,558.53
1.1
And suppose that I wanted to lay these out in a data structure
3,559.63
3.27
and be able to search them efficiently, assuming the whole time
3,562.9
4.19
that they are indeed sorted.
3,567.09
1.19
Well, if we wanted to do that, we have our old friend arrays from weeks ago.
3,568.28
4.26
And we also have our old algorithm from Mike Smith, our binary search
3,572.54
4.12
algorithm, divide and conquer.
3,576.66
1.53
And we can find nodes in this data structure super,
3,578.19
2.52
super fast in logarithmic time, big O of log n.
3,580.71
4.39
So, we've solved that problem.
3,585.1
1.67
But it turns out we don't necessarily have to use an array laying out data
3,586.77
5.08
from left to right because, again, one of the prices we pay of using arrays
3,591.85
5.97
where as we've realized today is this finiteness.
3,597.82
3.03
At the end of the day, the size of an array is fixed.
3,600.85
2.56
You have to decide in advance how big your array is going to be.
3,603.41
3.35
So, what if you want to add more numbers to it?
3,606.76
1.999
What if you want to remove numbers for efficiency
3,608.759
2.041
and not waste so much memory?
3,610.8
1.46
You can't really do that with an array.
3,612.26
1.67
You can, but have to jump through some hoops.
3,613.93
2.54
You have to reallocate the array, as with a function like [? re-alloc ?]
3,616.47
3.47
if you indeed used malloc in the first place to allocate it.
3,619.94
2.93
But then you have to copy the old array into the new array,
3,622.87
2.65
so it's all possible.
3,625.52
1.29
Nothing's impossible once you have a keyboard at your disposal,
3,626.81
3.96
but it's a lot of work, and it's more time,
3,630.77
1.96
and it's expensive there for both in terms of your time
3,632.73
2.3