This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1Programming Assignment #2: Using HuffmanEncoding to Compress A FileRead through the input fle and build its HuFFman tree.Traverse the HuFFman tree to create a table containing the encoding oF eachcharacter. Print out the table.Read through the input fle a second time, and write the HuFFman code For eachcharacter to the output fle. Just use characters “0” and “1”, instead oF theactual binary bits in output fle. Compute the space savings.No decompressingHeaps and Priority QueuesEECS 2333Queue ADT RevisitedA queue is a sequence in which:items are added at the rear and removed from the frontFrst in, Frst out (¡I¡O) (vs. a stack, which is last in, Frst out)we can only access the item that is currently at the frontOperations:boolean insert(T item); add an item at the rear of the queueT remove(); remove the item at the front of the queueT peek(); get the item at the front of the queue, but don’t remove itboolean isEmpty(); test if the queue is emptyboolean is¡ull(); test if the queue is full4Priority QueuesA priority queue is a collection of items, each of which has anassociated priority (a number).Applications?Operations:insert: add an item to the priority queue (with a priority value)remove: remove the highestpriority itemthe item in the queue with the largest associated priority value…How can we efFciently implement a priority queue?Unsorted list, sorted list, sorted array?AVLtree?(A new type of binary tree known as a heap)5Tree Types and CharacteristicsStructural constraintsConstraints on number of childrenBinary trees (at most 2 children)Btrees (between M/2 and M children)Balance constraintsBinary search trees  unconstrainedAVLtrees  differ in subtree heights by at most 1Key order constraintsBinary search trees and AVL trees (keys in the leftsubtree are less then, and keys in the right subtreeare greater than or equal to a node’s key)6Structure Types of Binary TreesFull binary treesEvery node has exactly two or zero childrenComplete binary treesBalanced, and at the same level, flled le¡t to rightComplete:7A Large Complete Binary Tree8Array Representation of A Complete Binary TreeA complete binary tree has a simple array representation.The nodes of the tree are stored in thearray in the order in which they wouldbe visited by a levelorder traversal(i.e., top to bottom, left to right).9Navigating in A Complete Binary TreeThe root node is in a[0]Given the node in a[i]:its left child is in a[2*i + 1]its right child is in a[2*i + 2]its parent is in a[(i – 1)/2], i!=0Examples:the left child of the node in a[1] is in a[2*1 + 1] = a[3]...
View
Full Document
 Spring '08
 Rabinovich
 Th, LG, Binary heap

Click to edit the document details