Data Representation  Program Representation  
string int x[3] char x 0x9cd0f0ad 01101011 
Objects Arrays Primitive types Addresses bits 
Java code C++ code C code x86 code IBCM hexadecimal 
Highlevel language Lowlevel language Assembly language Machine code 
A binary heap is an almost complete binary tree, which is a binary tree that is completely filled, with the possible exception of the bottom level, which is filled left to right. Examples:
 
 

From node i:
left child: 2*i right child: (2*i)+1 parent: floor(i/2) 
Implicit (array) representation:
A  B  C  D  E  F  G  H  I  J  K  L  
0  1  2  3  4  5  6  7  8  9  10  11  12  13 
Heap ordering property: For every nonroot node X, the key in the parent of X is less than (or equal to) the key in X. Thus, the tree is partially ordered.
not a heap  minheap 
→ 
 
 

→ 


 This is a full binary tree! 
11 100 0 101 0 0 11 = dbacaad
Cost of a file encoded via a Huffman Tree containing n symbols:
\( C(T) = p_1 * r_1 + p_2 * r_2 + p_3 * r_3 + \ldots + p_n * r_n \)
Where:


Determine frequencies of letters
Character  Frequency 

b  1 
e  2 
f  1 
i  5 
m  1 
o  2 
p  1 
s  2 
t  4 
u  1 
, (comma)  1 
(space)  9 
Build a minheap, sorted by frequency 


Character  Frequency  Prefix code  Total bits 

b  1  00000  5 
e  2  0011  8 
f  1  00001  5 
i  5  11  10 
m  1  00010  5 
o  2  1000  8 
p  1  00011  5 
s  2  1001  8 
t  4  101  12 
u  1  00100  5 
, (comma)  1  00101  5 
(space)  9  01  18 
Total is 94 bits


For the lab, you only need to account for the printable characters (0x20 to 0x7e)
Character codes:
