Huffman Coding - Python Implementation and Demo

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024

ความคิดเห็น • 53

  • @yenosibinamakanjuola9249
    @yenosibinamakanjuola9249 3 ปีที่แล้ว +5

    You honestly made my day you are literaly a better teacher than mine by far. You would make it far in life

  • @crypledentity9767
    @crypledentity9767 3 ปีที่แล้ว +5

    That was awesome. You definitely need to do more videos of implementing complex algorithms....

  • @isaacbawangisah6096
    @isaacbawangisah6096 3 ปีที่แล้ว +2

    I have to subscribe to your channel for tutorials of this kind

  • @AhmedAl-Qaffas--
    @AhmedAl-Qaffas-- 3 ปีที่แล้ว +2

    Great video from an AWESOME man, ty

  • @manas1743
    @manas1743 2 ปีที่แล้ว +2

    Heyy man, thanks for this tutorial!
    I am also trying to make something like a huffman compressor, just wanna ask one thing, not a technical question, how much did it took you to code the whole project and how did you knew which function to use when ?

  • @VickyYadav-ig5jj
    @VickyYadav-ig5jj 2 ปีที่แล้ว

    Nice thank you. Can you make videos of all dsa topic in Python. Your Explaination is Excellent

  • @hermanunspieters6969
    @hermanunspieters6969 2 ปีที่แล้ว

    GREAT STUFF THANKS BHRIGU!

  • @oaassy0374
    @oaassy0374 3 ปีที่แล้ว +1

    After using this code decode a text, how can i get the binary data corresponding to each word?

  • @akhilsrivastava149
    @akhilsrivastava149 2 ปีที่แล้ว

    Good. Nice explanation.

  • @HNLLEARN
    @HNLLEARN 3 ปีที่แล้ว +1

    please help me
    when i write from HuffmanCoding import HuffmanCoding this massege appear
    ModuleNotFoundError: No module named 'HuffmanCoding'

    • @BhriguSrivastava
      @BhriguSrivastava  3 ปีที่แล้ว

      Hi, it can happen if the python interpreter is not able to understand the folder as a package. Try creating an empty file named __init__.py (exact same name) in the same directory and try running again.

  • @prashantmishra3460
    @prashantmishra3460 ปีที่แล้ว

    32.15 par jo powershell khola hai aaapne vo powershell hi hai ?? vahan se run nahi ho rha mere comp. me ______________________plzzz help!

  • @vitalyapisushkin8427
    @vitalyapisushkin8427 2 ปีที่แล้ว +1

    Hi! Thank you very much. I want to ask you. What algorithmic complexity does this code have? If we take into account compression and decompression.

    • @Gabriel77888
      @Gabriel77888 10 หลายเดือนก่อน

      O(n log n)

  • @AmitKumar-kj3qd
    @AmitKumar-kj3qd 8 หลายเดือนก่อน

    can you help me to write this code in java

  • @cherish689
    @cherish689 3 ปีที่แล้ว

    if you want to auto compress and decompress the file any idea what will you be using then??

  • @antoninogiangreco386
    @antoninogiangreco386 3 ปีที่แล้ว +1

    is it possible to apply it to images?

  • @selflearner8895
    @selflearner8895 3 ปีที่แล้ว +1

    thank u so much

  • @humeyra127
    @humeyra127 2 ปีที่แล้ว

    Thanks a lot sir.

  • @himanshusoni1512
    @himanshusoni1512 2 ปีที่แล้ว +1

    Smooth.

  • @nikitasinha8181
    @nikitasinha8181 ปีที่แล้ว

    Thank you so much

  • @shashikantchourasia1402
    @shashikantchourasia1402 3 ปีที่แล้ว +2

    Hey can you post the video on how to apply Huffman's coding on image files ?

    • @George-vx1qe
      @George-vx1qe 6 หลายเดือนก่อน

      Images cant be compressed without losing data iirc you can use bilinear interpolation to simply resize the picture

    • @kenzzz3998
      @kenzzz3998 26 วันที่ผ่านมา

      @@George-vx1qe I'm trying to code Huffman compression for images. Wouldn't it work to just simply go pixel by pixel and read the RGB data and perform Huffman's compression on the R, G and B values? While decompressing after finding 3 codes I know I am done with one pixel so I can move on to another one

  • @joketime-g4v
    @joketime-g4v ปีที่แล้ว

    hello sir how can we apply huffman coding in a video file

  • @nohaadel5820
    @nohaadel5820 3 ปีที่แล้ว

    how to make the compression ratio at this please ?

  • @iawicgaming3245
    @iawicgaming3245 3 ปีที่แล้ว

    i get the error "NameError: name 'make_frequency_dict' is not defined"

    • @BhriguSrivastava
      @BhriguSrivastava  3 ปีที่แล้ว

      Ideally you should not be getting this, as that function name is defined in the code. Are you using the code as is or have done some changes? Python code runs from top to bottom so make sure things are defined before they are used.

  • @akeelalbaze594
    @akeelalbaze594 3 ปีที่แล้ว

    are you using Semi-method

  • @theglobalconflict6904
    @theglobalconflict6904 2 ปีที่แล้ว

    do you save the codes in another file plz????

  • @himanshusankhala8633
    @himanshusankhala8633 4 ปีที่แล้ว

    if we want to use it in communication system how to get reverse mapping frequency

    • @BhriguSrivastava
      @BhriguSrivastava  4 ปีที่แล้ว +2

      To get the reverse mapping (by not using same instance of HuffmanCoding), what you can do is that store the mapping information also in the encoded stream. While reading the encoded stream, first you'll extract the padding information and mapping information. You'll use that mapping information to decode the stream.
      (I'm not sure how you're using it in communication system, but this is how you can get the mappings from encoded file anywhere you're using it)

  • @goal5917
    @goal5917 3 ปีที่แล้ว

    For somehow, I cannot import the module Heapq, it just says "Unknow word", have you met this before ?

    • @BhriguSrivastava
      @BhriguSrivastava  3 ปีที่แล้ว

      Haven't seen this before. 'heapq' module should be present in your Python, and should be able to do 'import heapq'. Can you provide the complete error messages ?

    • @goal5917
      @goal5917 3 ปีที่แล้ว +1

      @@BhriguSrivastava Really appreciates when you care so much, but when I downloaded your code and try to run it, it does run. So I guess mine is just a typo

  • @seyeeet8063
    @seyeeet8063 4 ปีที่แล้ว

    any suggestion for book/resources/blog/webpage that do image/video compression completely in python from scratch? I am actually willing to pay for that to learn it lol

    • @BhriguSrivastava
      @BhriguSrivastava  4 ปีที่แล้ว

      Don't have any such resources handy, can try searching. I'm thinking - you can just try looking for compressing a stream of bytes. Because you can read image / video (or any file) in python as bytes. Then apply any compression algo you come across on the bytes.

  • @yashpurohit6988
    @yashpurohit6988 3 ปีที่แล้ว

    In the python shell , it says "No module named 'HuffmanCoding' " found. what have been gone wrong.

    • @BhriguSrivastava
      @BhriguSrivastava  3 ปีที่แล้ว

      Clone the linked repository and open terminal in that directory. You can directly run useHuffman .py from the terminal (no need of opening Python shell) by running the command "python3 useHuffman. py".
      If you're running from a Python shell, you might have to convert it into a module by creating an __init__.py also. You can try it out and search for error, and let me know if the issue is still there.

    • @yashpurohit6988
      @yashpurohit6988 3 ปีที่แล้ว

      @@BhriguSrivastava hey, thanks, I am able locate and execute the program, but i am not able to resolve a NameError , which says "NameError: name 'make_frequency_dict' is not defined", any way to contact you fast...its my first project for data structures , to be submitted quickly.

  • @panjianomherlambang7458
    @panjianomherlambang7458 4 ปีที่แล้ว +1

    can we run in windowsOS and LinuxOS?

    • @BhriguSrivastava
      @BhriguSrivastava  4 ปีที่แล้ว +1

      Yes you can run it in either of windows or Linux also. You just need to install Python on your system and run the code using python.

    • @panjianomherlambang7458
      @panjianomherlambang7458 4 ปีที่แล้ว

      @@BhriguSrivastava can we compress like .docx .xls and .pdf?

    • @BhriguSrivastava
      @BhriguSrivastava  4 ปีที่แล้ว

      Yes you can. You'll have to update the code to read the text from the docx/pdf/xls file instead (you can check if any additional changes required for handling those kind of files instead of txt). You'll encode them into a binary file only. Then while decoding, you again save the output file as the required one.

  • @MrDaniloko23
    @MrDaniloko23 3 ปีที่แล้ว

    Can you apply it on .zip files?

  • @akeelalbaze594
    @akeelalbaze594 3 ปีที่แล้ว

    are this making a binary file or characters

    • @BhriguSrivastava
      @BhriguSrivastava  3 ปีที่แล้ว

      The compressed file will be a binary file.

  • @moose43h
    @moose43h 3 ปีที่แล้ว

    Pray for me . I need to do this with c/c++

  • @ashwinvarma9349
    @ashwinvarma9349 4 ปีที่แล้ว

    what are padded bits?

    • @BhriguSrivastava
      @BhriguSrivastava  4 ปีที่แล้ว +1

      After we've encoded the input data by replacing each character with its huffman code, we will get a bit stream (like "abc" gets encoded to "111001"). Now while storing it as a binary file, it will get stored as bytes, where 1 byte has 8 bits. Now our overall encoded bit stream might not be a multiple of 8, for us to easily convert bits into bytes and vice versa (like 111001 has 6 bits only, and might get corrupted while storing it as byte).
      Hence, we'll add 2 dummy bits of 0s in the end (it'll become 11100100) such that overall it's of length 8. These 00 are the padded bits. We can now convert it to byte while storing. While decoding we'll convert all bytes to bits and we'll first remove the padded bits (by reading the padded bits info from our data), and then move on to decode bits using the huffman codes mapping.

    • @ashwinvarma9349
      @ashwinvarma9349 4 ปีที่แล้ว

      @@BhriguSrivastava Thanks bro! great explanation!

  • @rahajoran5876
    @rahajoran5876 3 ปีที่แล้ว

    do you have a point of contact, I have business proposal