Thread: Problem with Huffman Algo implementation...

  1. #1
    gandhi_rohit
    Guest

    Post Problem with Huffman Algo implementation...

    I am trying to implement the Huffman algorithm,
    The problem that I am facing is that while decompressing I get almost
    95% of the file correct,but it fills up some of the junk characters in between
    the output file at different places.Also I do not see any regular pattern for
    the places and the characters that are filled up in the file,when i tried this on
    various files.
    but it does work perfectly for smaller files,say upto 1KB files,the problem increases with
    larger files.

    I understand that there is no point sending the whole code(which is quite lengthy)

    A general idea abt the data structures used...
    --A 2-d array and a linked list initially contains the character with their respective frequencies.
    --This linked list is then converted to a binary tree,based on the frequency of the characters.
    --A struct which contains the 1/0 traversed code of the character,along with the character.

    Using this struct the compressed file is produced,with bits packed into a byte.

    Can u tell me why that could be happening ?
    Also can u suggest me a way of debugging the code,so that I can know where the exact problem lies,
    as it is not possible to use Trace i.e F7 for larger files.

    Tell me if u need more information on this.

    I am using TurboC 3.0 compiler.

    Thanking You,
    Rohit.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Can u tell me why that could be happening ?
    Do you read the file using the same method?
    I'm thinking that your first scan of the file doesn't count all characters, and when you subsequently perform a lookup, you generate a bogus code.

    Check that your tree is a valid tree - like all leaf nodes have NULL pointers. Write a debug routine to print a text representation of this tree to make sure its valid.
    You can also do this for your frequency distribution array.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    gandhi_rohit
    Guest
    Salem,

    I had checked the whole tree for small files,that is working perfectly,Null pointers r properly assigned,the compressed file is also perfect.

    Pls suggest smthing else.
    Thanx for ur help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 01:59 AM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  4. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM