From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_05,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4e1d151165b800f2 X-Google-Attributes: gid103376,public From: Roy Grimm Subject: Re: Huffman Encoding? Date: 1999/04/05 Message-ID: <3708B1B2.715FC009@bigfoot.com>#1/1 X-Deja-AN: 462853435 Content-Transfer-Encoding: 7bit References: <37083AFF.AD3306A2@bellatlantic.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Me, Myself and I (Not representing my company) Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-04-05T00:00:00+00:00 List-Id: Mark wrote: > > I'm currently writing a program that produces Huffman Encoding for text > input. I'm trying to determine the best data structure to utilize for > sorting the character frequencies. I used a linked-list of records to > store 1)character, > 2)frequency, and 3) marked/unmarked. (with the linked-list sorted > according to character) From here I intended to populate the binary > tree, but must first sort according to frequency. I feel that there must > be a cleaner alternative. Has anyone done this, and if so what did you > find to be the best approach? When I wrote my Huffman encoder for my graduate algorithms class (which is the only reason most people would bother doing it...), I used a method of storing the bounded list of character frequency in a data structure that had O(1) lookup time. I'll leave the implementation as an exercise for the reader. p.s. If you're looking to optimise space, there is a way to eliminate one field from your list of elements. That's an exercise for the advanced students... -- Roy A. Grimm Mathematics and alcohol don't mix. Don't drink and derive.