notes_COSqueues

Reducing roundoff error fraud detection isolate

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: items. [reducing roundoff error] ・Fraud detection: isolate $$ transactions. ・File maintenance: find biggest files or directories. [Huffman codes] N huge, M large [Dijkstra's algorithm, Prim's algorithm] Constraint. Not enough memory to store N items. [sum of powers] [A* search] % more tinyBatch.txt Turing 6/17/1990 vonNeumann 3/26/2002 Dijkstra 8/22/2007 vonNeumann 1/11/1999 Dijkstra 11/18/1995 Hoare 5/10/1993 vonNeumann 2/12/1994 Hoare 8/18/1992 Turing 1/11/2002 Thompson 2/27/2000 Turing 2/11/1991 Hoare 8/12/2003 vonNeumann 10/13/1993 Dijkstra 9/10/2000 Turing 10/12/1993 Hoare 2/10/2005 [maintain largest M values in a sequence] [load balancing, interrupt handling] [bin packing, scheduling] [Bayesian spam filter] Generalizes: stack, queue, randomized queue. % java TopM Thompson vonNeumann vonNeumann Hoare vonNeumann 644.08 4121.85 2678.40 4409.74 837.42 3229.27 4732.35 4381.21 66.10 4747.08 2156.86 1025.70 2520.97 708.95 3532.36 4050.20 5 < tinyBatch.txt 2/27/2000 4747.08 2/12/1994 4732.35 1/11/1999 4409.74 8/18/1992 4381.21 3/26/2002 4121.85 sort key 5 6 Priority queue client example Priority queue client example Challenge. Find the largest M items in a stream of N items. Challenge. Find the largest M items in a stream of N items. ・Fraud detection: isolate $$ transactions. ・File maintenance: find biggest files or directories. N huge, M large order of growth of finding the largest M in a stream of N items Constraint. Not enough memory to store N items. implementation use a min-oriented pq while (StdIn.hasNextLine()) { String line = StdIn.readLine(); Transaction item = new Transaction(line); pq.insert(item); pq contains if (pq.size() > M) largest M items pq.delMin(); } N MN M binary heap N log M M best in theory 7 N log N elementary PQ Transaction data type is Comparable (ordered by $$) space sort MinPQ<Transaction> pq = new MinPQ<Transaction>(); time N M 8 Priority queue: unordered and ordered array implementation operation argument insert insert insert remove max insert insert insert remove max insert insert insert remove max return value size P Q E 1 2 3 2 3 4 5 4 5 6 7 6 Q X A M X P L E P contents (unordered) P P P P P P P P P P P E Q Q E E E E E E E E M public class UnorderedArrayMaxPQ<Key extends Comparable<Key>> { private Key pq; // pq[i] = ith element on pq private int N; // number of elements on pq contents (ordered) P P E E E A A A A A A A E X X X M M M M A Priority queue: unordered array im...
View Full Document

This document was uploaded on 02/20/2014 for the course COS 226 at Princeton.

Ask a homework question - tutors are online