https://github.com/bapjiws/huffman-code
https://github.com/bapjiws/huffman-code
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bapjiws/huffman-code
- Owner: bapjiws
- Created: 2015-12-15T11:20:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-15T11:38:04.000Z (over 9 years ago)
- Last Synced: 2025-01-28T16:44:20.400Z (5 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Given a non-empty string s no longer than 104 symbols, encode.py builds an optimal prefix-free code.
The first output line shows how many different k letters are in the string and the encoded string's length.
The next k lines show letters' codes in "letter: code" format. The last line shows the encoded string.Sample Input 1:
a
Sample Output 1:
1 1
a: 0
0
Sample Input 2:
abacabad
Sample Output 2:
4 14
a: 0
b: 10
c: 110
d: 111
01001100100111
decode.py, in turn, restores the string by its prefix-free code. The first input line provides k difrerent letters that are in the string and l, the encoded string's length. The next k lines provide letters' prefix-free codes in "letter: code" format (the letters can go in arbitrary order).
The output line shows string s.Sample Input 1:
1 1
a: 0
0
Sample Output 1:
a
Sample Input 2:
4 14
a: 0
b: 10
c: 110
d: 111
01001100100111
Sample Output 2:
abacabad