Data Compression Compression is a high-profile application

Slides:



Advertisements
Similar presentations
CMSC 341 Binary Heaps Priority Queues. 8/3/2007 UMBC CSMC 341 PQueue 2 Priority Queues Priority: some property of an object that allows it to be prioritized.
Advertisements

Priority Queues. 2 Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The “smallest” element.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
1 Chapter 6 Priority Queues (Heaps) General ideas of priority queues (Insert & DeleteMin) Efficient implementation of priority queue Uses of priority queues.
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
Priority Queues. Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out –The “smallest” element.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
CSE 373 Data Structures and Algorithms Lecture 13: Priority Queues (Heaps)
CSC 172 DATA STRUCTURES. Priority Queues Model Set with priorities associatedwith elements Priorities are comparable by a < operator Operations Insert.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
CPS 100, Fall YAQ, YAQ, haha! (Yet Another Queue) l What is the dequeue policy for a Queue?  Why do we implement Queue with LinkedList Interface.
data ordered along paths from root to leaf
Outline Priority Queues Binary Heaps Randomized Mergeable Heaps.
CompSci 100E 24.1 Data Compression  Compression is a high-profile application .zip,.mp3,.jpg,.gif,.gz, …  What property of MP3 was a significant factor.
CPS Heaps, Priority Queues, Compression l Compression is a high-profile application .zip,.mp3,.jpg,.gif,.gz, …  What property of MP3 was a significant.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
PRIORITY QUEUES AND HEAPS Slides of Ken Birman, Cornell University.
Data StructuresData Structures Priority Queue. Recall Queues FIFO:First-In, First-Out Some contexts where this seems right? Some contexts where some things.
CompSci 100e 8.1 Scoreboard l What else might we want to do with a data structure? AlgorithmInsertionDeletionSearch Unsorted Vector/array Sorted vector/array.
CPS Heaps, Priority Queues, Compression l Compression is a high-profile application .zip,.mp3,.jpg,.gif,.gz, …  Why is compression important?
Properties: -The value in each node is greater than all values in the node’s subtrees -Complete tree! (fills up from left to right) Max Heap.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
CSE373: Data Structures & Algorithms Priority Queues
CS 201 Data Structures and Algorithms
Heaps (8.3) CSE 2011 Winter May 2018.
Priority Queues An abstract data type (ADT) Similar to a queue
Heapsort CSE 373 Data Structures.
Topics covered (since exam 1):
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Hashing Exercises.
Source: Muangsin / Weiss
Compsci 201 Priority Queues & Autocomplete
Bohyung Han CSE, POSTECH
Heaps, Priority Queues, Compression
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Heaps and Priority Queue
Building Java Programs
CMSC 341: Data Structures Priority Queues – Binary Heaps
Part-D1 Priority Queues
Heapsort Heap & Priority Queue.
Priority Queues.
CSE 373: Data Structures and Algorithms
Topics covered (since exam 1):
CMSC 341 Lecture 14 Priority Queues & Heaps
Priority Queues.
ITEC 2620M Introduction to Data Structures
Priority Queues.
Ch. 8 Priority Queues And Heaps
Priority Queues (Chapter 6.6):
Building Java Programs
Priority Queues An abstract data type (ADT) Similar to a queue
Heapsort CSE 373 Data Structures.
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Priority Queues & Heaps
Binary and Binomial Heaps
CSE 12 – Basic Data Structures
Definition Applications Implementations Heap Comparison
Priority Queues.
1 Lecture 10 CS2013.
CSE 373 Data Structures and Algorithms
Priority Queues.
Priority Queues CSE 373 Data Structures.
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
Topics covered (since exam 1):
Data Structures for Shaping and Scheduling
CSE 373 Data Structures Lecture 12
Scoreboard What else might we want to do with a data structure?
Presentation transcript:

Data Compression Compression is a high-profile application .zip, .mp3, .jpg, .gif, .gz, … What property of MP3 was a significant factor in what made Napster work (why did Napster ultimately fail?) Why do we care? Secondary storage capacity doubles every year Disk space fills up quickly on every computer system More data to compress than ever before

More on Compression What’s the difference between compression techniques? .mp3 files and .zip files? .gif and .jpg? Lossless and lossy Is it possible to compress (lossless) every file? Why? Lossy methods Good for pictures, video, and audio (JPEG, MPEG, etc.) Lossless methods Run-length encoding, Huffman, LZW, … 11 3 5 3 2 6 2 6 5 3 5 3 5 3 10

Priority Queue Compression motivates the study of the ADT priority queue Supports two basic operations insert -– an element into the priority queue delete – the minimal element from the priority queue Implementations may allow getmin separate from delete Analogous to top/pop, front/dequeue in stacks, queues See PQDemo.java and UsePQ.java, code below sorts, complexity? Scanner s; PriortyQueue pq = new PriorityQueue(); while (s.hasNext()) pq.add(s.next()); while (pq.size() > 0) { System.out.println(pq.remove()); }

Priority Queue implementations Implementing priority queues: average and worst case Insert average Getmin (delete) worst Unsorted vector Sorted vector Search tree Balanced tree Heap O(n) O(1) O(n) O(1) log n O(n) log n O(1) log n Heap has O(1) find-min (no delete) and O(n) build heap

PriorityQueue.java (Java 5) What about objects inserted into pq? If deletemin is supported, what properties must inserted objects have, e.g., insert non-comparable? Change what minimal means? Implementation uses heap If we use a Comparator for comparing entries we can make a min-heap act like a max-heap, see PQDemo Where is class Comparator declaration? How used? What's a static inner class? A non-static inner class? In Java 5 there is a Queue interface and PriorityQueue class The PriorityQueue class also uses a heap

Sorting w/o Collections.sort(…) public static void sort(ArrayList a) { PriorityQueue pq = new PriorityQueue(); for(int k=0; k < a.size(); k++) pq.add(a.get(k)); for(int k=0; k < a.size(); k++) a.set(k,pq.remove()); } How does this work, regardless of pqueue implementation? What is the complexity of this method? add O(1), remove O(log n)? If add O(log n)? heapsort uses array as the priority queue rather than separate pq object. From a big-Oh perspective no difference: O(n log n) Is there a difference? What’s hidden with O notation?

Priority Queue implementation PriorityQueue uses heaps, fast and reasonably simple Why not use inheritance hierarchy as was used with Map? Trade-offs when using HashMap and TreeMap: Time, space Ordering properties, e.g., what does TreeMap support? Changing method of comparison when calculating priority? Create object to replace, or in lieu of compareTo Comparable interface compares this to passed object Comparator interface compares two passed objects Both comparison methods: compareTo() and compare() Compare two objects (parameters or self and parameter) Returns –1, 0, +1 depending on <, ==, >

Heap Definition Heap is an array-based implementation of a binary tree used for implementing priority queues, supports: insert, findmin, deletemin: complexities? Using array minimizes storage (no explicit pointers), faster too --- children are located by index/position in array Heap is a binary tree with shape property, heap/value property shape: tree filled at all levels (except perhaps last) and filled left-to-right (complete binary tree) each node has value smaller than both children