text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
occur with some frequency in this text. | 4,822.453 | 1.734 |
So, it's meant to be representative
of an essay, or a message, | 4,824.187 | 2.583 |
or whatever that you
want to send to someone. | 4,826.77 | 1.874 |
Indeed, if you count up all of the
As, Bs, Cs, Ds, and Es, and divide | 4,828.644 | 3.876 |
by the total number of
letters, it turns out | 4,832.52 | 1.97 |
that 20% of the characters in that
random string are As, 10% are Bs, | 4,834.49 | 5.39 |
10% are Cs, 15% are
Ds, and 45% are Es, so | 4,839.88 | 3.95 |
it's roughly consistent
with what I'm claiming, | 4,843.83 | 2.17 |
which is that it E is pretty popular. | 4,846 | 1.83 |
So, intuitively, [? it ?]
would be really nice | 4,847.83 | 2.95 |
if I had an algorithm that came up
with some representation of bits | 4,850.78 | 5.83 |
that's not just 8 bits
for every darn letter | 4,856.61 | 2.73 |
but that is a few bits
for the popular letters | 4,859.34 | 3.24 |
and more bits for the
less popular letters, | 4,862.58 | 1.9 |
so I optimize, again, so to
speak, for the common case. | 4,864.48 | 2.77 |
So, by this logic E, hopefully,
should have a pretty short encoding | 4,867.25 | 4.49 |
in binary, and A, and B, and C, and D
should have slightly longer encoding, | 4,871.74 | 5.69 |
so that again if I'm using E a lot I
want to send as few bits as possible. | 4,877.43 | 3.48 |
But I need this algorithm
to be repeatable. | 4,880.91 | 1.829 |
I don't want to just arbitrarily
come up with something | 4,882.739 | 2.291 |
and then have to tell you in advance
that, hey, we're using this David Malan | 4,885.03 | 4.1 |
system for binary. | 4,889.13 | 1.06 |
We want an algorithmic process here. | 4,890.19 | 2.11 |
And what's nice about trees is that
it's one way of seeing and solving | 4,892.3 | 4.2 |
exactly that. | 4,896.5 | 1.04 |
So, Huffman proposed this. | 4,897.54 | 1.67 |
If you have a forest of nodes, so to
speak, a whole bunch of trees-- each | 4,899.21 | 4.48 |
of size one, no children-- think of them
as each having a weight or a frequency. | 4,903.69 | 3.9 |
So, I've drawn five circles
here, per this snippet | 4,907.59 | 2.79 |
from a popular textbook that has 10%,
10%, 15%, 20%, 45% equivalently in each | 4,910.38 | 7.286 |
of those nodes. | 4,917.666 | 0.624 |
And I've just labeled the
leaves as B, C, D, A, E, | 4,918.29 | 3.225 |
deliberately from left to right because
it will make my tree look prettier, | 4,921.515 | 3.125 |
but technically the lines could cross
and it's not a big deal in reality. | 4,924.64 | 3.041 |
We just need to be consistent. | 4,927.681 | 1.419 |
So, Huffman proposed this. | 4,929.1 | 1.82 |
In order to figure out the so-called
Huffman tree for this particular text, | 4,930.92 | 7.39 |
in order to figure out what to encode
it's letters as with zeros and ones, | 4,938.31 | 4.05 |
go ahead and take the two smallest nodes
and combine them with a new root node. | 4,942.36 | 5.27 |
So in other words, B
and C were both 10%. | 4,947.63 | 2.52 |
Those are the smallest nodes. | 4,950.15 | 1.35 |
Let's go ahead and combine
them with a new root node | 4,951.5 | 2.166 |
and add together their weights,
so 10% plus 10% is 20%. | 4,953.666 | 3.384 |
And then arbitrarily,
but consistently, label | 4,957.05 | 3.42 |
the left child's edge or arrow as a
0 and the right arrow's edge as a 1. | 4,960.47 | 7.53 |
Meanwhile, repeat. | 4,968 | 1.61 |
So, now look for the two smallest nodes. | 4,969.61 | 1.99 |
And I see a 20%-- so
ignore the children now. | 4,971.6 | 3.31 |
Only look at the roots of these trees. | 4,974.91 | 1.8 |
And there's now four trees, one of which
has children, three of which don't. | 4,976.71 | 5.14 |
So, now look at the smallest roots
now and you can go left to right here. | 4,981.85 | 4.59 |
There's a 20%, there's a 15%,
there's a 20%, and a 45%. | 4,986.44 | 5.3 |
So, I'm not sure which one
to go with, so you just | 4,991.74 | 2.395 |
have to come up with some
rule to be consistent. | 4,994.135 | 2 |
I'm going to go with
the ones on the left, | 4,996.135 | 1.765 |
and so I'm going to combine the 20%
with the 15%, the 20% on the left. | 4,997.9 | 4.38 |
Combine their weights. | 5,002.28 | 1.14 |
That gives me 35% in a new root,
and again label the left branch 0 | 5,003.42 | 4.05 |
and the right branch a 1. | 5,007.47 | 1.78 |
Now, it's not ambiguous. | 5,009.25 | 1.42 |
Let's combine 35% and 20%
with a new root that's 55%. | 5,010.67 | 4.51 |
Call its left branch
0, its right branch 1. | 5,015.18 | 3.93 |
And now 55% and 45%, combine
those and give us a 1. | 5,019.11 | 7.1 |
So why did I just do this? | 5,026.21 | 2.03 |
Well now I have built up the so-called
Huffman tree for this input text | 5,028.24 | 4.45 |
and Huffman proposed the following. | 5,032.69 | 2.34 |
To figure out what
patterns of zeros and ones | 5,035.03 | 2.15 |
to use to represent
A, B, C, D, E, simply | 5,037.18 | 3.28 |
follow the paths from the
root to each of those leaves. | 5,040.46 | 4.19 |
So what is the encoding for A? | 5,044.65 | 2.21 |
Start at the root and then
look for A-- 0, 1, so 0, | 5,046.86 | 4.3 |
1 shall be my binary
encoding for A in this world. | 5,051.16 | 3.13 |
How about B? | 5,054.29 | 1.19 |
0, 0, 0, 0 shall be my binary
encoding for B. How about C? | 5,055.48 | 5.762 |
0, 0, 0, 1 shall be my
encoding for C. How about D? | 5,061.242 | 6.218 |
0, 0, 1. | 5,067.46 | 1.46 |
And beautifully, how about E? | 5,068.92 | 2.292 |
1. | 5,071.212 | 2.658 |
So, to summarize, what
has just happened? | 5,073.87 | 2.99 |
E was the most popular letter, B and
C, were the least popular letters. | 5,076.86 | 3.44 |
And if we summarize these,
you'll see that, indeed, | 5,080.3 | 3.54 |
B and C got pretty long encodings,
but E got the shortest encoding. | 5,083.84 | 5.21 |
And it turns out
mathematically you will now | 5,089.05 | 2.88 |
have a system for encoding letters
of the alphabet that is optimal, | 5,091.93 | 4.82 |
that is you will use
as few bits as possible | 5,096.75 | 3.26 |
because you are biasing things
toward short representations | 5,100.01 | 2.98 |
for popular letters, longer
representations for less | 5,102.99 | 2.77 |
popular letters. | 5,105.76 | 0.87 |
And mathematically this gives
you the most efficient encoding | 5,106.63 | 3.11 |
for the original text without
losing any information. | 5,109.74 | 5.39 |
In other words, now if Huffman
wanted to send a secret message | 5,115.13 | 3.17 |
to someone in class or over the
internet, he and that recipient | 5,118.3 | 3.69 |
simply have to agree on
this scheme in advance | 5,121.99 | 2.9 |
and then use these encoding
to transmit those messages. | 5,124.89 | 3.58 |
Because when someone receives 0, 1 or 0,
0, 0, 0 or 0, 0, 0, 1 from Mr. Huffman, | 5,128.47 | 8.86 |
they can use that same
look-up table, if you will, | 5,137.33 | 2.45 |
and say, oh, he just sent me an A
or, oh, he just sent me a B or C. So, | 5,139.78 | 4 |
you have to know what
tree Huffman built up. | 5,143.78 | 2.49 |
And, indeed, what typically
happens in actual computers is | 5,146.27 | 3.66 |
when you use Huffman coding
to compress some body of text | 5,149.93 | 3.51 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.