{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blogs/huffmanCoding","result":{"data":{"blog":{"frontmatter":{"title":"HUFFMAN CODING","thumbnail":"blog77","date":"June 25, 2021","dsaCppCodeFile":null},"excerpt":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  Huffman Coding is used to encode the words in transmission. If\n                  we use a fixed length encoding, say ASCII codes(ASCII Codes: 0\n                  to 127 = 0 to 2<sup>7</sup>-1 i.e 7 bits for each character)\n                  then for a word of length 10 with 4 characters will take 10 *\n                  7 = 70 bits to be transmitted irrespective of the frequency of\n                  each character.\n                </p>\n                <p>\n                  To reduce this, we can use Huffman coding algorithm(for\n                  variable length encoding) and it is based on the frequency of\n                  occurrence of a character. Most frequently occurring character\n                  will use less number of bits for encoding. Similarly less\n                  frequently occurring character will use more number of bits\n                  for encoding\n                </p>\n                <p>\n                  It generates prefix codes in which no code word generated is a\n                  prefix of another code in the word to be transmitted.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <ol class=\"pl-4\">\n                <li>\n                  Create n node trees where each node corresponds to the\n                  character specifying in the text to be encoded and label with\n                  it's frequency/weight.\n                </li>\n                <li>\n                  Find two trees with smallest frequency, create a new tree with\n                  the label equal to sum of frequency of the two nodes picked.\n                  Make sure the node with smaller frequency(among the two nodes\n                  picked) should be the left child.\n                </li>\n                <li>\n                  Repeat step 2 until one single tree is obtained. All the\n                  characters of the word to be encoded will be the leaf nodes in\n                  this tree.\n                </li>\n                <li>\n                  Then, assign 0's to left edges and 1's to right edges of the\n                  tree.\n                </li>\n                <li>\n                  To get the code words for a character, record the label of the\n                  edge along the path from root to that character.\n                </li>\n              </ol>\n            </div>\n","html":"<div class=\"my-2 p-2\">\n              <h4>Introduction</h4>\n              <div class=\"m-2\">\n                <p>\n                  Huffman Coding is used to encode the words in transmission. If\n                  we use a fixed length encoding, say ASCII codes(ASCII Codes: 0\n                  to 127 = 0 to 2<sup>7</sup>-1 i.e 7 bits for each character)\n                  then for a word of length 10 with 4 characters will take 10 *\n                  7 = 70 bits to be transmitted irrespective of the frequency of\n                  each character.\n                </p>\n                <p>\n                  To reduce this, we can use Huffman coding algorithm(for\n                  variable length encoding) and it is based on the frequency of\n                  occurrence of a character. Most frequently occurring character\n                  will use less number of bits for encoding. Similarly less\n                  frequently occurring character will use more number of bits\n                  for encoding\n                </p>\n                <p>\n                  It generates prefix codes in which no code word generated is a\n                  prefix of another code in the word to be transmitted.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Working Procedure</h4>\n              <ol class=\"pl-4\">\n                <li>\n                  Create n node trees where each node corresponds to the\n                  character specifying in the text to be encoded and label with\n                  it's frequency/weight.\n                </li>\n                <li>\n                  Find two trees with smallest frequency, create a new tree with\n                  the label equal to sum of frequency of the two nodes picked.\n                  Make sure the node with smaller frequency(among the two nodes\n                  picked) should be the left child.\n                </li>\n                <li>\n                  Repeat step 2 until one single tree is obtained. All the\n                  characters of the word to be encoded will be the leaf nodes in\n                  this tree.\n                </li>\n                <li>\n                  Then, assign 0's to left edges and 1's to right edges of the\n                  tree.\n                </li>\n                <li>\n                  To get the code words for a character, record the label of the\n                  edge along the path from root to that character.\n                </li>\n              </ol>\n            </div>"},"thumbnail":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='225'%20viewBox='0%200%20400%20225'%20preserveAspectRatio='none'%3e%3cpath%20d='M23%2097l-1%209c0%203%200%203%202%203s3-1%203-2c0-4%201-4%202-5%202%200%202%200%202%203s0%204%202%204%202-1%202-4v-4l1%203c2%206%207%207%2011%202%203-3%203-15%200-15-2%200-3%203-3%2010%200%202%200%203-2%203l-1-6c0-6%200-7-2-7s-2%200-2%204l-1%205v-5c0-4%200-4-2-4-3%200-3%200-3%203l-1%203c-2%201-2%200-2-3s0-3-2-3c-3%200-3%200-3%206m28-5l-1%209c-1%208-1%208%202%208%202%200%202%200%202-3s0-3%203-3%203%200%203-2-1-2-3-2l-3-1%202-2c3%200%206-2%206-4%200-1-11-2-11%200m12%202l-1%209c0%206%200%206%202%206s2-1%202-3%201-3%204-3c4-1%204-5%200-4l-3-1%202-2c3%200%205-1%205-3s-1-2-5-2c-6%200-6%200-6%203m12%200l-1%209c0%206%200%206%203%206l2-2c0-2%200-2%201-1%201%202%201%202%203%200%202-1%202-1%202%201-1%202%209%203%2010%200%201-1%204-1%204%201l6%201h5v-8l2%204c1%203%202%204%204%204s2%200%202-8v-9l-2-1c-2%200-2%200-2%203v4l-1-4-4-3c-3%200-3%200-4%208%200%208%200%208-1%204-2-10-3-12-6-12-2%200-3%202-5%208l-3%208v-6c0-10-3-13-6-6l-2%203-1-3c-2-5-6-6-6-1m54%200c-7%209%200%2021%208%2012%203-3%201-6-2-3-2%202-3%202-3%200-1-2%201-8%202-8l1%202c-1%202-1%202%201%202%203%200%203%200%203-3%200-5-6-7-10-2m13%200c-4%205-2%2015%204%2015%205%200%208-10%205-16-2-3-6-3-9%201m12-2l-1%209v8h3c4%200%208-3%209-8%201-2%201-2%201%203v5h10v-8l2%204c1%203%202%204%204%204s2%200%202-9c0-8%200-9-2-9s-2%201-2%203v4l-2-4c-2-5-6-4-6%201l-1%205v-5c0-3%200-4-2-4-1%200-2%200-1%201l-1%201-1%202c0%202%200%202-1%200l-2-3h-9m33%201c-2%203-3%2013-1%2015%203%203%209%200%2011-5%201-5-5-6-7-1-1%202-1%202-1%200%200-3%202-8%203-6%200%203%205%203%205%200%200-5-5-7-10-3m112%2013l-1%208v7h9c8%200%209%201%209%203%200%201%200%202-2%202l-2-1c0-2-8%207-13%2015-4%208-8%2017-8%2026-1%207-1%207%205-1%204-5%206-7%209-8%206-3%207-2%207%201%200%202%200%202%201%201h3l-2-5-2-7-1-3v-3c3-2%2013-2%2013%200l-1%201h-2c0%202%203%202%204%201h1l-1%202-1%203-2%207-2%204h3c2%200%202-1%201-3%200-2%200-2%207%200%204%201%205%202%207%205l3%204%201%203%202%206%202%204%201%204c2%207-1%2010-9%208h-4v-24h-15v-3l-1-3-1%203v3h-17v7l-1%208c-2%202-2%203-1%203%202%200%203%204%202%206h-15c-2-3-2-5%201-8%204-6%202-7-2-2-3%203-4%205-4%207%200%203%200%203-9%204-9%200-9%200-9%202s1%203%205%203h5l-1%204v3h97l1-4c1-2%202-3%205-3%205-1%205-4%200-5h-3v-14c0-14-1-21-4-21l-2-2c-1-2-1-2-1%200%200%203-8%203-8-1%200-2%200-2%202-2%202%201%203%200%201-1-2-2-1-4%203-12%206-11%206-14%200-20l-5-3-1-4-1-5c-1-1-1%201-1%204v5l-3-1c-3-1-22%200-24%201-1%201-1-1-1-4v-5l-14-1-13%201m2%208v6h22v-3l1-3v-1l-1-3v-3h-22v7m-31%2027l1%209h12v-18h-13v9m3%2023l-1%205c0%203%200%204-1%203%200-4-2-3-3%200l2%204%202%203%203%201c2%200%202%200%202-3%200-2%200-3%202-3s2-1%202-4l-1-4-1%203c0%203-2%202-2-2%200-3-1-4-4-3'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.7699115044247788,"src":"/static/8b5efda394b69d584656e630c8982db0/ee604/blog77.png","srcSet":"/static/8b5efda394b69d584656e630c8982db0/69585/blog77.png 200w,\n/static/8b5efda394b69d584656e630c8982db0/497c6/blog77.png 400w,\n/static/8b5efda394b69d584656e630c8982db0/ee604/blog77.png 800w,\n/static/8b5efda394b69d584656e630c8982db0/f3583/blog77.png 1200w,\n/static/8b5efda394b69d584656e630c8982db0/e4d72/blog77.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"pageContext":{"blog":"huffmanCoding","thumbnail":"thumbnails/blog77.png"}},"staticQueryHashes":["2987289216","63159454"]}