Skip to content

Commit 50f1445

Browse files
djeadaCopilot
andauthored
Update notes/greedy_algorithms.md
Co-authored-by: Copilot <[email protected]>
1 parent b75cacf commit 50f1445

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

notes/greedy_algorithms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,13 @@ return order, Lmax
709709

710710
### Huffman coding
711711

712-
You have symbols that occur with known frequencies \$f\_i>0\$ and \$\sum\_i f\_i=1\$ (if you start with counts, first normalize by their total). The goal is to assign each symbol a binary codeword so that no codeword is a prefix of another (a **prefix code**, i.e., uniquely decodable without separators), and the average length
712+
You have symbols that occur with known frequencies $f_i>0$ and $\sum_i f_i=1$ (if you start with counts, first normalize by their total). The goal is to assign each symbol a binary codeword so that no codeword is a prefix of another (a **prefix code**, i.e., uniquely decodable without separators), and the average length
713713

714714
$$
715715
\mathbb{E}[L]=\sum_i f_i\,L_i
716716
$$
717717

718-
is as small as possible. Prefix codes correspond exactly to **full binary trees** (every internal node has two children) whose leaves are the symbols and whose leaf depths equal the codeword lengths \$L\_i\$. The **Kraft inequality** \$\sum\_i 2^{-L\_i}\le 1\$ characterizes feasibility; equality holds for full trees (so an optimal prefix code “fills” the inequality).
718+
is as small as possible. Prefix codes correspond exactly to **full binary trees** (every internal node has two children) whose leaves are the symbols and whose leaf depths equal the codeword lengths $L_i$. The **Kraft inequality** $\sum_i 2^{-L_i}\le 1$ characterizes feasibility; equality holds for full trees (so an optimal prefix code “fills” the inequality).
719719

720720
**Example inputs and outputs**
721721

0 commit comments

Comments
 (0)