text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
What's an upper bound on the running
time of search for a linked list, | 1,065.35 | 5.71 |
even if it is sorted? | 1,071.06 | 1.195 |
1,072.255 | 2.754 | |
Any thoughts? | 1,075.009 | 0.541 |
1,075.55 | 3.07 | |
Is it constant time like big O of 1? | 1,078.62 | 2.38 |
Is it log of n? | 1,081 | 1.4 |
Is it n, n squared? | 1,082.4 | 3.79 |
What's the running time going to be? | 1,086.19 | 1.79 |
Well, they're sorted, and that was this
magical ingredient, this assumption | 1,087.98 | 3.27 |
we've been allowed to make in
the past which was helpful, | 1,091.25 | 2.57 |
but that assumed that
we had random access. | 1,093.82 | 2.4 |
In C, we had square bracket notation,
so that using some simple arithmetic | 1,096.22 | 3.28 |
we could jump roughly to the
middle, and then the next middle, | 1,099.5 | 2.14 |
and the next middle looking for Mike
Smith or whatever element it is we're | 1,101.64 | 3.083 |
looking for. | 1,104.723 | 0.697 |
Unfortunately here, one
price we have already | 1,105.42 | 3.15 |
paid already by taking this step
toward linked lists is linear time. | 1,108.57 | 5.77 |
Big O of n would seem to be the running
time of searching a linked list, | 1,114.34 | 3.71 |
because the only way you can
start is at the beginning, | 1,118.05 | 2.58 |
and the only way you can get through
the list is by following these arrows. | 1,120.63 | 3.9 |
And if there's n nodes
in the list, you're | 1,124.53 | 2.7 |
going to need as many as n steps to
find, something like 22, or 26, or 34, | 1,127.23 | 4.26 |
or any elements all together. | 1,131.49 | 2.277 |
Well, that's not all that great. | 1,133.767 | 1.333 |
What about insert? | 1,135.1 | 2.62 |
What's an upper bound on
the running time of insert? | 1,137.72 | 4.51 |
Well, here too it depends. | 1,142.23 | 1.74 |
Suppose that we don't care
about keeping the list sorted. | 1,143.97 | 4.06 |
That's kind of a nice advantage,
so I can be a little lazy here. | 1,148.03 | 2.98 |
So, what's the running
time going to be if I | 1,151.01 | 2.22 |
want to insert a new number like
the number 50 into this list, | 1,153.23 | 3.54 |
but I don't care about
keeping it sorted? | 1,156.77 | 2.39 |
Well, instinctively, where
would you put this element? | 1,159.16 | 3.44 |
Where would you put it? | 1,162.6 | 2.01 |
You might be inclined-- you kind
of want to put it over here, | 1,164.61 | 2.78 |
because it's the biggest element. | 1,167.39 | 1.54 |
But again, if you don't care
about keeping it sorted, | 1,168.93 | 1.52 |
where is the fastest, the quickest
and dirtiest place to put it? | 1,170.45 | 2.666 |
I would propose let's just put
it at the front of the list. | 1,173.116 | 2.544 |
Let's take this first pointer,
point it at the new number | 1,175.66 | 4.11 |
50 that we've have somehow
added to the picture | 1,179.77 | 2.52 |
as by calling malloc, asking
malloc for a new node. | 1,182.29 | 2.63 |
And then have 50, in turn, point to the
number 9, and then 9 can point to 17, | 1,184.92 | 4.99 |
and 22, and so forth. | 1,189.91 | 1.17 |
What if we want to insert
another number, 42, | 1,191.08 | 1.876 |
and we don't care about where it goes? | 1,192.956 | 1.582 |
Well, why don't we just put it
at the beginning of the list? | 1,194.538 | 2.562 |
Then we have the first
pointers pointing at 42, | 1,197.1 | 2.76 |
which in turn should point at 50, which
in turn can point at 9, then 17, then | 1,199.86 | 3.77 |
22, and so forth. | 1,203.63 | 1.267 |
So, if we're just lazy
about this, we can actually | 1,204.897 | 2.083 |
achieve a great running time
for insert constant time. | 1,206.98 | 3.54 |
Unfortunately, if we want
to keep things sorted then | 1,210.52 | 3.76 |
we're going to have to incur a
linear time cost again, right? | 1,214.28 | 3.55 |
Because if we have to
insert 42 or 50, worst case | 1,217.83 | 2.616 |
they might belong all the way at
the end of the list and that's | 1,220.446 | 2.624 |
Big O of n steps. | 1,223.07 | 2.02 |
And delete, too, unfortunately,
whether it's sorted or unsorted | 1,225.09 | 3.75 |
is also like search
going to be Big O of n | 1,228.84 | 2.175 |
because you don't necessarily know
when you're searching for a number | 1,231.015 | 2.875 |
to delete if it's going to be at the
beginning, the middle, and the end. | 1,233.89 | 2.999 |
So, in the worst case, it
might indeed be at the end. | 1,236.889 | 2.551 |
You know what? | 1,239.44 | 0.94 |
Why don't we instead of
walking through this verbally, | 1,240.38 | 2.59 |
let's see if we can't
get some volunteers? | 1,242.97 | 1.782 |
Can we get seven volunteers to play--
wow, to play the role of numbers here. | 1,244.752 | 4.338 |
1, 2, 3, 4, 5, 6, and
yes, 7, come on up. | 1,249.09 | 4.78 |
All right, so I have here some
printouts for all seven of you | 1,253.87 | 2.93 |
that represent exactly the nodes
that we have here on the screen. | 1,256.8 | 3.35 |
Let's meet one of our first contestants. | 1,260.15 | 1.67 |
What is your name? | 1,261.82 | 0.5 |
AUDIENCE: Scully. | 1,262.32 | 0.59 |
SPEAKER 1: Scully, nice to see you. | 1,262.91 | 1.51 |
So, you shall be literally first
and represent our first pointer. | 1,264.42 | 2.89 |
So, if you want to come and
stand roughly over here. | 1,267.31 | 2.38 |
And then what is your name? | 1,269.69 | 0.64 |
AUDIENCE: Maria. | 1,270.33 | 0.39 |
SPEAKER 1: Maria, nice to see you. | 1,270.72 | 1.416 |
And you can be the number 9 right
next to our first contestant. | 1,272.136 | 4.694 |
And your name? | 1,276.83 | 0.59 |
AUDIENCE: Sarah. | 1,277.42 | 0.36 |
SPEAKER 1: Sarah, nice to see you. | 1,277.78 | 1.416 |
You shall be the number 17. | 1,279.196 | 1.341 |
And your name? | 1,280.537 | 0.583 |
[? AUDIENCE: Satoshi. ?] | 1,281.12 | 0.42 |
[? SPEAKER 1: Satoshi, ?]
nice to see you. | 1,281.54 | 1.75 |
You shall be 20. | 1,283.29 | 1.367 |
And your name? | 1,284.657 | 0.583 |
[? AUDIENCE: Mosof. ?] | 1,285.24 | 0.63 |
[? SPEAKER 1: Mosof, ?] nice to see you. | 1,285.87 | 1.666 |
And you shall be 22. | 1,287.536 | 1.361 |
AUDIENCE: Jed. | 1,288.897 | 0.583 |
SPEAKER 1: Jed, nice to
see you-- 29, formerly 26. | 1,289.48 | 4.85 |
And your name? | 1,294.33 | 0.695 |
AUDIENCE: Erin. | 1,295.025 | 0.625 |
SPEAKER 1: Erin, nice to see you. | 1,295.65 | 1.375 |
You shall be 34. | 1,297.025 | 0.915 |
All right, so what we have here
is seven elements, six of which | 1,297.94 | 4.69 |
are very similar to themselves, one
of which is fundamentally different. | 1,302.63 | 3.63 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.