0% found this document useful (0 votes)
7 views2 pages

Lab 9 BDS 3B

Download

Uploaded by

engagerabia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Lab 9 BDS 3B

Download

Uploaded by

engagerabia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

National University of Computer and Emerging Sciences

Laboratory Manual 09

for
Data Structures Lab

Course Instructor Ms. Mamoona Majid

Lab Instructor Hadiya Kashif

Lab TA Shais ur Rehman

Section BDS-3B

Semester Fall 2024

Department of Computer Science


FAST-NU, Lahore, Pakistan
Objectives:
In this lab, students will practice:
1. Implementation of Huffman Encoding using Heaps and Binary Trees

Question:
Implement a class Huffman which contains the root Node of Huffman tree. Each node in Huffman is of type
HNode.

struct HNode
{
int freq;
char character;
HNode *left, *right;
}

Note:
a. A valid character is stored only in leaf nodes in a Huffman Tree.
b. In a leaf node, the value in the freq variable corresponds to the frequency of the character that the
node represents.
c. In a non-leaf node, the value in the freq variable is the sum of freq variables stored in its left child and
right child.

1. Implement a member function createHuffman that is passed as a parameter to a filename. The file contains
characters along with their frequencies. The function creates a Huffman tree of the given characters. You
will need a MinHeap data structure for this. Use your previous MinHeap implementation. void
createHuffman(string const filename)

2. Implement a member function printHuffman which prints the Huffman code of each character along with
the character and its frequency. printHuffman() const

3. Destructor

4. Encoding function which takes a string can and replaces each letter in the string with its binary code (the
Huffman code).

5. Decoding function which decodes an encoded string by looking at the bits in the coded string from left to
right until a letter decodes.

6. Create a main function which creates a Huffman object, calls the createHuffman function, and then calls
the printHuffman function to print Huffman code.

7. Print the Encoding for the string “computer science”

8. Print the decoded string of “111111001110111101”

You might also like