Lecture12 - -1-Programming Assignment #2: Using...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: -1-Programming 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 233-3-Queue ADT RevisitedA queue is a sequence in which:items are added at the rear and removed from the frontFrst in, Frst out (IO) (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 dont remove itboolean isEmpty(); test if the queue is emptyboolean isull(); test if the queue is full-4-Priority 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 highest-priority itemthe item in the queue with the largest associated priority valueHow can we efFciently implement a priority queue?Unsorted list, sorted list, sorted array?AVL-tree?(A new type of binary tree known as a heap)-5-Tree Types and CharacteristicsStructural constraintsConstraints on number of childrenBinary trees (at most 2 children)B-trees (between M/2 and M children)Balance constraintsBinary search trees - unconstrainedAVL-trees - 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 nodes key)-6-Structure Types of Binary TreesFull binary treesEvery node has exactly two or zero childrenComplete binary treesBalanced, and at the same level, flled let to rightComplete:-7-A Large Complete Binary Tree-8-Array 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 level-order traversal(i.e., top to bottom, left to right).-9-Navigating 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

This note was uploaded on 04/07/2008 for the course EECS 233 taught by Professor Rabinovich during the Spring '08 term at Case Western.

Page1 / 32

Lecture12 - -1-Programming Assignment #2: Using...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online