text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
like we just have here, you
store the compressed text | 5,153.44 | 4.59 |
by storing your As, Bs, Cs,
Ds, and Es and other letters | 5,158.03 | 2.69 |
using these new
encoding, but you somehow | 5,160.72 | 2.06 |
have to embed in that file in the
compressed file the tree itself | 5,162.78 | 4.45 |
or this cheat sheet of encodings. | 5,167.23 | 3.66 |
So, with compression-- maybe
you're compressing a Microsoft Word | 5,170.89 | 3.28 |
file, or a dot TXT file,
or any other type of file, | 5,174.17 | 4.03 |
you have to store not just the
compressed text using these shorter | 5,178.2 | 3.88 |
representation-- not 8-bit ASCII, but
these shorter representations-- but you | 5,182.08 | 3.452 |
also somewhere, maybe at the beginning
of the file or at the end of the file, | 5,185.532 | 3.208 |
somewhere where someone else can find
it, you need to store this mapping | 5,188.74 | 3 |
or you need to store the tree
itself in some digital form. | 5,191.74 | 4.85 |
And so, it's possible
by this logic that you | 5,196.59 | 3.65 |
might try to compress
a really small file, | 5,200.24 | 3.09 |
and that file could
actually become bigger | 5,203.33 | 2.76 |
because you're storing a
tree inside the file to-- | 5,206.09 | 3.382 |
with which to recover
the original information. | 5,209.472 | 1.958 |
Or better yet, most
algorithms or most actual | 5,211.43 | 2.077 |
compression programs will realize,
wait a minute, if compressing this file | 5,213.507 | 3.083 |
is actually going to make it bigger,
let's just not compress it at all | 5,216.59 | 2.916 |
and leave it alone untouched. | 5,219.506 | 2.444 |
So, what if you take a compressed file
and compress it again, and compress it | 5,221.95 | 5.42 |
again, and compress it again? | 5,227.37 | 2.89 |
A dangerous assumption to get into
is, well, I could just maybe keep | 5,230.26 | 3.59 |
compressing that video file again,
and again, and again, and again, | 5,233.85 | 3.55 |
and I can maybe compress my big
essay, or my big video file, | 5,237.4 | 3.21 |
or big music file to just maybe one bit. | 5,240.61 | 2.38 |
Right? | 5,242.99 | 0.5 |
That's the logical extreme,
just keep compressing, | 5,243.49 | 1.81 |
compressing, compressing, compressing. | 5,245.3 | 1.583 |
But, of course, that
can't possibly make sense, | 5,246.883 | 2.587 |
because if you compress some file
down to just a single bit, 0 or 1, | 5,249.47 | 3.39 |
you've clearly thrown away information
and can't possibly recover it all. | 5,252.86 | 4.09 |
So, at some point, too, you've hit this
lower bound on the size of the file | 5,256.95 | 5.1 |
until you need to start throwing
actual information away. | 5,262.05 | 2.69 |
At some point, the file just has so
much entropy, appears to be so random, | 5,264.74 | 4.55 |
there really is no pattern to start
to leverage to compress it further. | 5,269.29 | 3.72 |
And so, there generally is some
maximum amount of compression | 5,273.01 | 3.95 |
you can apply to something. | 5,276.96 | 1.837 |
So, how would we represent this? | 5,278.797 | 1.333 |
Let's whip out a C struct here. | 5,280.13 | 1.42 |
So, this time each of the
nodes in a Huffman tree | 5,281.55 | 2.694 |
need a little something different. | 5,284.244 | 1.416 |
They need, at least in the
leaves, some kind of character | 5,285.66 | 2.69 |
to remember the symbol. | 5,288.35 | 0.96 |
Now, technically only the leaves
need to know what symbols they are, | 5,289.31 | 2.64 |
so it's a little redundant
to have this in every node, | 5,291.95 | 2.25 |
but we can keep things simple and use
the same type of node for everything. | 5,294.2 | 3.44 |
Float frequency, I could use an integer
and treat it exactly as a percentage, | 5,297.64 | 4.41 |
or I can use a float as the nodes
were with 0.1 and 0.45 and so forth, | 5,302.05 | 4.29 |
and I'll call that frequency. | 5,306.34 | 1.23 |
And then each of those nodes
needs a left child potentially | 5,307.57 | 2.458 |
and a right child potentially. | 5,310.028 | 1.292 |
And, again, I'll call
these things a node. | 5,311.32 | 2.58 |
So, again, it's getting a little more
involved this node, but it still allows | 5,313.9 | 3.37 |
me to represent it ultimately in C. | 5,317.27 | 6.29 |
And now, it's time to pursue lastly
the holy grail of data structures, | 5,323.56 | 4.51 |
if you will. | 5,328.07 | 0.91 |
Thus far, we've been solving
problems, creating new problems, | 5,328.98 | 4.9 |
trying to solve those again. | 5,333.88 | 1.17 |
And the problems we've been exploring
this week are things like dynamism, | 5,335.05 | 3.222 |
if we want to be able to grow
or shrink our data structure. | 5,338.272 | 2.458 |
Malloc and pointers
give us that flexibility | 5,340.73 | 2.22 |
but might cost us a bit
more time, because we | 5,342.95 | 2.15 |
have to keep things
sorted differently or we | 5,345.1 | 2.53 |
have to follow all of those pointers. | 5,347.63 | 2.06 |
And so, a lot of the algorithms
we've been discussing today | 5,349.69 | 2.89 |
at least have-- like linear time,
searching, or inserting, or deleting | 5,352.58 | 4.14 |
potentially like in a linked list. | 5,356.72 | 1.96 |
Better still would be
something logarithmic | 5,358.68 | 1.87 |
like a balanced binary search tree,
so still preserving that nice binary | 5,360.55 | 5.31 |
aspect from week zero. | 5,365.86 | 1.84 |
But the holy grail of a data
structure for its operations | 5,367.7 | 2.77 |
is Big O of 1 so to
speak, constant time. | 5,370.47 | 3.44 |
If you are searching, or inserting,
or deleting, and somehow changing | 5,373.91 | 5.33 |
a data structure, wouldn't it be
amazing if every darn operation | 5,379.24 | 3.52 |
takes just one step, or
maybe two steps, or three | 5,382.76 | 2.36 |
steps but a constant number of steps? | 5,385.12 | 2.82 |
Now, it might be a little
naive for us to expect | 5,387.94 | 2 |
that we can store an arbitrary
amount of data in some fancy way | 5,389.94 | 3.47 |
that we get constant time,
but maybe just maybe if we're | 5,393.41 | 3.2 |
clever we can get close to that. | 5,396.61 | 2.18 |
So, let's introduce a step toward that. | 5,398.79 | 2.81 |
It turns out there exists in this
world things called hash tables. | 5,401.6 | 3.66 |
And a hash table can be
implemented in any number of ways, | 5,405.26 | 2.75 |
but you can think of it
really as just an array. | 5,408.01 | 2.08 |
So, for instance, this might be a way of
representing a hash table called table, | 5,410.09 | 5.442 |
whose first location is bracket zero
and whose last location is bracket | 5,415.532 | 2.958 |
n minus 1 for however long this is. | 5,418.49 | 1.742 |
And I just left it as blanks. | 5,420.232 | 1.208 |
I don't even know what this
hash table might want to store. | 5,421.44 | 1.77 |
It could be numbers, it could
be names, it could be letters, | 5,423.21 | 1.63 |
it could be anything we want. | 5,424.84 | 1.91 |
But hash table has this
nice theoretical property | 5,426.75 | 3.92 |
that if well-designed
and thought through, | 5,430.67 | 2.64 |
you can maybe just maybe get
constant look up time in it. | 5,433.31 | 4.52 |
And let's do a simple
example of a hash table. | 5,437.83 | 2.22 |
Hash tables are often nicely
thought of as buckets, | 5,440.05 | 2.79 |
so we borrowed these from the loading
dock outside just a little moment ago, | 5,442.84 | 3.36 |
and we've attached thanks to
Arturo some of these signs to them. | 5,446.2 | 5.27 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.