{"id":1311,"date":"2026-09-03T07:02:01","date_gmt":"2026-09-03T07:02:01","guid":{"rendered":"https:\/\/ffritze.de\/?p=1311"},"modified":"2026-09-03T07:31:08","modified_gmt":"2026-09-03T07:31:08","slug":"daten-komprimieren-mit-koepfchen-teil-2-huffman-code-in-python-umsetzen","status":"publish","type":"post","link":"https:\/\/ffritze.de\/en\/daten-komprimieren-mit-koepfchen-teil-2-huffman-code-in-python-umsetzen\/","title":{"rendered":"Compressing Data with Smart (Part 2) \u2013 Converting Huffman Code in Python"},"content":{"rendered":"<p class=\"wp-block-paragraph translation-block\">In the first part, the example of <strong>KAFFEPAUSE<\/strong> was shown how the Huffman algorithm uses character frequency to create a binary tree and extract space-saving, unique codes from it. The basics are explained in detail in <a href=\"https:\/\/ffritze.de\/en\/daten-komprimieren-mit-koepfchen-teil-1-der-huffman-algorithmus-einfach-erklaert\/\" target=\"_blank\" rel=\"noopener\">Teil 1<\/a> on ffritze.de.<\/p>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">In this second part, the Huffman algorithm is implemented in <strong>Python<\/strong> and gradually traced in a <strong>Jupyter Notebook<\/strong>. The focus is not only on the finished program. The individual data structures and processing steps are made visible so that the construction of the Huffman tree and the generation of the codes can be tried out directly.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-baaca9a6 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-6e41dddb wp-block-group-is-layout-flex\">\n<div style=\"height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aac11e1d36d7&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aac11e1d36d7\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum.jpg\" alt=\"\" class=\"wp-image-1352\" srcset=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum.jpg 1024w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum-300x300.jpg 300w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum-150x150.jpg 150w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum-768x768.jpg 768w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-binaerbaum-12x12.jpg 12w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<div style=\"height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<p class=\"wp-block-paragraph translation-block\">The abstract data type <strong><code>BinTree<\/code><\/strong> is used to display the tree. This is based on the abstract data types that play a role in the Lower Saxony computer science curriculum. The associated Python implementations and further information on abstract data types, including the binary tree, are described here: <a href=\"https:\/\/ffritze.de\/en\/abstrakte-datentypen-in-der-schule-python-implementierungen-zum-download\/#more-188\" target=\"_blank\" rel=\"noopener\">Abstract data types in school: Python implementations for download<\/a>.<\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The notebook thus combines the theoretical foundations from <a href=\"https:\/\/ffritze.de\/en\/daten-komprimieren-mit-koepfchen-teil-1-der-huffman-algorithmus-einfach-erklaert\/\" target=\"_blank\" rel=\"noopener\">Teil 1<\/a> with a concrete programming. Starting from a text, a frequency analysis is first carried out. On this basis, a Huffman tree is created, on which the coding of the text is subsequently tested.<\/p>\n\n\n\n<div class=\"wp-block-group has-contrast-color has-custom-hellblau-wenig-transparent-background-color has-text-color has-background has-link-color wp-elements-1 has-global-padding is-layout-constrained wp-container-core-group-is-layout-c9a371c5 wp-block-group-is-layout-constrained\" style=\"border-width:1px;border-top-left-radius:25px;border-top-right-radius:25px;border-bottom-left-radius:25px;border-bottom-right-radius:25px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30)\">\n<h2 class=\"wp-block-heading\">Open Jupyter Notebook<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-baaca9a6 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"wp-block-paragraph translation-block\">The entire notebook can be opened directly in JupyterLite and run there. In addition to the frequency analysis and the creation of the Huffman tree, the file also contains other functions for generating the Huffman codes as well as for encoding and decoding texts. Open the notebook and play through the entire process once with the word <strong>\"KAFFEPAUSE\"<\/strong>:<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aac11e1d6763&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aac11e1d6763\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"590\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-KAFFEEPAUSE.png\" alt=\"\" class=\"wp-image-1368\" srcset=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-KAFFEEPAUSE.png 989w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-KAFFEEPAUSE-300x179.png 300w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-KAFFEEPAUSE-768x458.png 768w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-KAFFEEPAUSE-18x12.png 18w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/jupyter.org\/try-jupyter\/notebooks\/?fromURL=https:\/\/raw.githubusercontent.com\/ffritzemedia\/huffman\/refs\/heads\/main\/huffman.ipynb\" target=\"_blank\" rel=\"noopener\">Open Huffman's algorithm in JupyterLite<\/a><a href=\"https:\/\/jupyter.org\/try-jupyter\/notebooks\/?fromURL=https:\/\/raw.githubusercontent.com\/ffritzemedia\/huffman\/refs\/heads\/main\/huffman.ipynb\" target=\"_blank\" rel=\"noopener\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">After opening the code at the top right, first set the code to <strong>\"Trusted\"<\/strong>and then select <strong>Python<\/strong> as the kernel. Each code cell can be executed one after the other with <strong>Shift + Enter<\/strong>.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Determine the frequencies of the characters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">Before the Huffman tree can be created, it is first necessary to examine how often each character occurs in the source text. This frequency analysis is used by the function <code>frequency_analysis_of(text)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">As a result, the function provides a dictionary (<code>dictionary<\/code>). In it, each character is assigned its absolute frequency. The text is scrolled through character by character:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-baaca9a6 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\">\n<ul class=\"wp-block-list\">\n<li>If a character is already included in the dictionary, its numerator is increased by one.<\/li>\n\n\n\n<li class=\"translation-block\">If a character appears for the first time, it is recorded with the value <code>1<\/code>.<\/li>\n\n\n\n<li>At the end, the dictionary contains all the characters that appear in the text with their respective frequency.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\">\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-6e41dddb wp-block-group-is-layout-flex\">\n<div style=\"height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aac11e1d8587&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aac11e1d8587\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse.jpg\" alt=\"\" class=\"wp-image-1355\" srcset=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse.jpg 1024w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse-300x300.jpg 300w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse-150x150.jpg 150w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse-768x768.jpg 768w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-h-analyse-12x12.jpg 12w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<div style=\"height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>def frequency_analysis_of(text):\n    frequencies = {}\n    for char in text:\n        if char in frequencies:\n            frequencies&#91;char] += 1\n        else:\n            frequencies&#91;char] = 1\n    return frequencies<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The variable <code>frequencies<\/code> stores the frequency table. By calling the function with any text, this table can then be used for the structure of the Huffman tree.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Huffman Tree<\/h2>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">For the creation of the Huffman tree, two preparatory steps are first carried out. This is followed by the actual function <code>huffman_tree_from(frequencies)<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading translation-block\">1. Import of the class <code>BinTree<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The class <code>BinTree<\/code> is loaded directly from a GitHub repository. As a result, no additional file has to be stored on your own computer. However, an Internet connection is required to run this code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from urllib.request import urlopen\nfrom types import ModuleType\nimport sys\n\nurl = \"https:\/\/raw.githubusercontent.com\/ffritzemedia\/ADT_Python\/main\/ADT\/adt.py\"\n\nadt_remote = ModuleType(\"adt_remote\")\n\nwith urlopen(url) as antwort:\n    quelltext = antwort.read().decode(\"utf-8\")\n\nexec(compile(quelltext, url, \"exec\"), adt_remote.__dict__)\n\nsys.modules&#91;\"adt_remote\"] = adt_remote\n\nBinTree = adt_remote.BinTree<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Auxiliary class for the tree knots<\/h3>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">Both the sign and its frequency should be stored in the tree nodes. The help class <code>item<\/code> is used for this purpose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class item:\n    def __init__(self, weight, char):\n        self.weight = weight\n        self.char = char\n\n    def __lt__(self, other):\n        return self.weight &lt; other.weight<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The attribute <code>weight<\/code> stores the weight or frequency of a character. The attribute <code>char<\/code> contains the associated character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The <code>__lt__<\/code> method determines how to compare two objects of the <code>item<\/code> class. Their weights are compared. This allows the trees to be sorted later according to their frequency.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Huffman Tree Creation Feature<\/h3>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">The <code>huffman_tree_from(frequencies)<\/code> function creates a Huffman tree from a dictionary with character frequencies. The principle of the Huffman algorithm is implemented: the two trees with the smallest weights are always selected and combined to form a new tree.<\/p>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">First, the class <code>BinTree<\/code> is extended by the comparison function <code>bin_tree_lt<\/code>. As a result, the tree objects can be compared and sorted with each other based on the weight of their contents:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def bin_tree_lt(self, other):\n    return self.getItem() &lt; other.getItem()\n\nBinTree.__lt__ = bin_tree_lt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">Subsequently, a separate tree is created for each character from the dictionary with a content of the class <code>item<\/code>. In this content, the character and its frequency are stored:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>trees = &#91;]\n\nfor char, weight in frequencies.items():\n    tree = BinTree(item(weight, char))\n    trees.append(tree)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The resulting trees are sorted according to their weight. As long as there is more than one tree, the two trees with the smallest weights are removed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>trees = sorted(trees)\n\nwhile len(trees) &gt; 1:\n    left = trees.pop(0)\n    right = trees.pop(0)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph translation-block\">From these two trees a new common tree is created. Its weight is the sum of the two individual weights. Since the new node does not correspond to a single character, its character is specified with <code>None<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>merge = BinTree(\n    item(left.getItem().weight + right.getItem().weight, None),\n    left,\n    right\n)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The new tree will be added back to the list. After that, the list is sorted again so that the two trees with the smallest weights can be selected again in the next run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>trees.append(merge)\ntrees = sorted(trees)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This process is repeated until only a single tree remains. This tree is the complete Huffman tree and will be returned at the end:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return trees.pop(0)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The weight sum of the root node corresponds to the total number of all characters of the text examined. The sheets contain the individual characters, while the inner nodes only store the aggregated weight sums.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-baaca9a6 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<p class=\"wp-block-paragraph\">This makes the path from the frequency analysis to the structure of the Huffman tree to the coding and decoding of a text completely comprehensible. The notebook offers the possibility to try out the individual steps yourself and to explore the principle of lossless data compression in practice. Good luck experimenting with the Huffman algorithm!<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aac11e1db54a&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aac11e1db54a\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss.jpg\" alt=\"\" class=\"wp-image-1365\" srcset=\"https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss.jpg 1024w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss-300x300.jpg 300w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss-150x150.jpg 150w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss-768x768.jpg 768w, https:\/\/ffritze.de\/wp-content\/uploads\/2026\/09\/huffman_2-abschluss-12x12.jpg 12w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Im ersten Teil wurde am Beispiel von&nbsp;KAFFEEPAUSE&nbsp;gezeigt, wie der Huffman-Algorithmus anhand von Zeichenh\u00e4ufigkeiten einen Bin\u00e4rbaum erstellt und daraus platzsparende, eindeutige Codes gewinnt. Die Grundlagen werden in&nbsp;Teil 1 auf ffritze.de&nbsp;ausf\u00fchrlich erkl\u00e4rt. In diesem zweiten Teil wird der Huffman-Algorithmus in&nbsp;Python&nbsp;implementiert und in einem&nbsp;Jupyter Notebook&nbsp;schrittweise nachvollzogen. Dabei steht nicht nur das fertige Programm im Mittelpunkt. Die einzelnen Datenstrukturen [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1314,"comment_status":"open","ping_status":"open","sticky":false,"template":"seite-thoughts-beitrag","format":"standard","meta":{"footnotes":""},"categories":[19,7,21],"tags":[90,88,91,22],"class_list":["post-1311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithms","category-programs","category-python","tag-codes","tag-huffman","tag-jupyter","tag-python"],"_links":{"self":[{"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/posts\/1311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/comments?post=1311"}],"version-history":[{"count":0,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/posts\/1311\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/media\/1314"}],"wp:attachment":[{"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/media?parent=1311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/categories?post=1311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ffritze.de\/en\/wp-json\/wp\/v2\/tags?post=1311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}