text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
7. | 2,221.39 | 0.5 |
We got a little lucky. | 2,221.89 | 0.916 |
Let's pop you out and insert
you right where you belong. | 2,222.806 | 2.724 |
And then 5, you belong
a few shifts over. | 2,225.53 | 2.8 |
So let's shift three of you. | 2,228.33 | 2.4 |
And then, done. | 2,230.73 | 1.6 |
All right. | 2,232.33 | 0.5 |
So let's give all of you a stress ball. | 2,232.83 | 1.72 |
And maybe a round of applause. | 2,234.55 | 1.249 |
And let's see if we can't tease
apart what just happened here. | 2,235.799 | 3.261 |
All right. | 2,239.06 | 1.59 |
And then you can exit stage
left-- right if you'd like. | 2,240.65 | 3.255 |
All right, thank you. | 2,243.905 | 0.875 |
Derek, you're really
racking them up here. | 2,244.78 | 1.435 |
All right. | 2,246.215 | 0.275 |
AUDIENCE: I'll [INAUDIBLE]. | 2,246.49 | 0.96 |
SPEAKER 1: All right. | 2,247.45 | 0.875 |
Thank you. | 2,248.325 | 0.745 |
All right. | 2,249.07 | 0.771 |
Sure. | 2,249.841 | 0.499 |
So what was the point of this exercise? | 2,250.34 | 1.624 |
And how do we actually now get to
a decision point where one of these | 2,251.964 | 3.806 |
is the way to go? | 2,255.77 | 1.89 |
So in bubble sort, recall that
the key was to do something | 2,257.66 | 2.59 |
again and again until we did no swaps. | 2,260.25 | 2.494 |
At which point we could conclude
that the list was sorted. | 2,262.744 | 2.416 |
So let's do exactly that,
repeat until no swaps. | 2,265.16 | 2.692 |
And then, let's give
ourselves a counter, | 2,267.852 | 1.708 |
just to make things a
little more methodical, | 2,269.56 | 1.874 |
and say for i from 0 to n
minus 1-- rather n minus 2. | 2,271.434 | 4.946 |
Why? | 2,276.38 | 0.68 |
Well, the end of the list
recall is it n minus 1. | 2,277.06 | 3.11 |
Because if you have a list of
size n, the beginning is at 0. | 2,280.17 | 3.12 |
The end is at n minus 1. | 2,283.29 | 1.95 |
And so one shy of the end
is going to be n minus 2. | 2,285.24 | 3.25 |
So we want to do this up through
the second to last element. | 2,288.49 | 3.42 |
If the i-th and the i-th plus
1 elements are out of order. | 2,291.91 | 4.87 |
So if left hand and right hand
are out of order, swap them. | 2,296.78 | 3.62 |
And repeat this again
and again and again. | 2,300.4 | 1.8 |
And thanks to that
outer loop, we're going | 2,302.2 | 1.75 |
to do it again and again and
again until we have no such swaps. | 2,303.95 | 4.04 |
And now to be clear, why this n minus 2? | 2,307.99 | 2.31 |
We want to make sure as we're sort
of walking down our row of volunteers | 2,310.3 | 3.21 |
that my left hand does not actually
point at the last human on stage | 2,313.51 | 4.1 |
because then, where would
my right hand point? | 2,317.61 | 2.04 |
There's no person to beyond that point. | 2,319.65 | 3.264 |
So this then is bubble sort. | 2,322.914 | 1.166 |
Now, let's propose pseudocode for
our other algorithm, selection sort, | 2,324.08 | 4.23 |
wherein we walked through
the list iteratively | 2,328.31 | 2.44 |
trying to select on each
pass the smallest element | 2,330.75 | 3.28 |
and putting it into its place. | 2,334.03 | 1.51 |
So for i from 0 to n
minus 1, we're going | 2,335.54 | 2.77 |
to do this from beginning
through the end, | 2,338.31 | 2.13 |
find the smallest element between
i-th and n-th minus 1 element. | 2,340.44 | 4.69 |
Swap the smallest with
that i-th element. | 2,345.13 | 3.68 |
In other words, walk through the list. | 2,348.81 | 1.78 |
Find the smallest, put it on the end. | 2,350.59 | 1.62 |
Walk through the list, swap
it with the second to the end. | 2,352.21 | 3.58 |
Walk through the list, do the
same, do the same, do the same, | 2,355.79 | 2.74 |
each time grabbing the
then smallest element. | 2,358.53 | 2.87 |
And then lastly, we had insertion sort,
whereby we iterated through the list, | 2,361.4 | 5 |
but we pretty much dealt with
every element as we encountered it. | 2,366.4 | 3.057 |
So let me propose this
pseudocode code here. | 2,369.457 | 1.833 |
For i from 1 to n minus 1. | 2,371.29 | 3.087 |
So let's just assume that the
very beginning of the list | 2,374.377 | 2.333 |
is sort of trivially sorted, no
matter what number he or she is. | 2,376.71 | 3.35 |
Because if that left side of the list
is of size 1, it is, indeed, sorted. | 2,380.06 | 4.09 |
And indeed, let's call the 0-th element
through the i minus [? 1-th ?] element, | 2,384.15 | 4.57 |
wherever we are, the sorted side. | 2,388.72 | 2.26 |
So essentially, call the
left the sorted side. | 2,390.98 | 1.93 |
And you can think of the right-hand
side as the unsorted side. | 2,392.91 | 2.75 |
Remove the i-th element, whatever
element you're dealing with, | 2,395.66 | 3.53 |
and insert it into the
sorted side in order. | 2,399.19 | 3.56 |
In other words, just walk
through the list, one at a time, | 2,402.75 | 2.79 |
plucking out elements, and
then forcibly insert them | 2,405.54 | 2.78 |
into the sorted side of
the list, making room, | 2,408.32 | 2.65 |
as our humans did, for that
list by shuffling everyone over. | 2,410.97 | 4.21 |
This then was bubble sort,
selection sort, and insertion sort. | 2,415.18 | 5.12 |
But which to choose? | 2,420.3 | 1.86 |
So let's introduce now an answer to why. | 2,422.16 | 2.929 |
Not just what these things are, but
why you might use one over the other. | 2,425.089 | 3.041 |
So the running time
of an algorithm might | 2,428.13 | 2.22 |
be the number of seconds
an algorithm takes to run, | 2,430.35 | 2.26 |
or the number of minutes, or the number
of steps, or the number of comparisons. | 2,432.61 | 3.06 |
It doesn't really matter
what your unit of measure | 2,435.67 | 1.78 |
is, so long as you're consistent,
whatever feels the most | 2,437.45 | 2.374 |
expensive or useful to express. | 2,439.824 | 2.346 |
So let's consider an
example, like bubble sort. | 2,442.17 | 2.62 |
If we want to consider the
efficiency of bubble sort | 2,444.79 | 3.432 |
and make a claim as to
whether we should or shouldn't | 2,448.222 | 2.208 |
use it because it's good or bad, let's
consider it a little formulaically. | 2,450.43 | 3.56 |
So a little mathy, but
pretty generically. | 2,453.99 | 2.37 |
So if there are n elements to
store, and a computer scientist, | 2,456.36 | 3.72 |
recall from week 0, will generally just
call n the size of his or her problem. | 2,460.08 | 3.78 |
n is the number of numbers
to sort, or humans to sort. | 2,463.86 | 3.52 |
How many steps is it going to
take to sort that many people? | 2,467.38 | 4.81 |
Well, when I had 8 music stands
and 8 people here before, | 2,472.19 | 3.63 |
I considered a pair, a pair,
a pair, a pair, a pair. | 2,475.82 | 4.737 |
And so if there were n humans up here. | 2,480.557 | 1.583 |
Or let's speak concretely,
8 people initially. | 2,482.14 | 2.53 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.