st-applications

st-applications - S et A DT 4 .5 S y m b o l T a b le A p p...

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

View Full Document Right Arrow Icon
Robert Sedgewick and Kevin Wayne • Copyright © 2005 • http://www.Princeton.EDU/~cos226 4.5 Symbol Table Applications 2 Set ADT Set. Unordered collection of distinct keys. API for SET. ! add(key) insert the key into the set ! contains(key) is the given key in the set? ! remove(key) remove the key from the set ! iterator() return iterator over all keys Q. How to implement? Java library. java.util.HashSet . 3 Set Client: Remove Duplicates Remove duplicates. [e.g., from commercial mailing list] ! Read in a key. ! If key is not in set, insert and print it out. public class DeDup { public static void main ( String [] args ) { SET < String > set = new SET < String > (); while (! StdIn . isEmpty ()) { String key = StdIn . readString (); if (! set . contains ( key )) { set . add ( key ); System . out . println ( key ); } } } } 4 More Set Applications Application Purpose Key Spell checker Identify misspelled words Word Browser Highlight previously visited pages URL Chess Detect repetition draw Board position Spam blacklist Prevent spam IP address Security whitelist Allow trusted traffic IP address Credit card fraud Identify stolen credit cards Credit card number
Background image of page 1

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

View Full DocumentRight Arrow Icon
Robert Sedgewick and Kevin Wayne • Copyright © 2005 • http://www.Princeton.EDU/~cos226 Inverted Index 6 Inverted Index Inverted index. Given a list of page, preprocess so that you can quickly find all pages containing a given query. Ex 1. Book index. Ex 2. Web search engine index. Ex 3. File index, e.g., Spotlight. Key.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/10/2011.

Page1 / 5

st-applications - S et A DT 4 .5 S y m b o l T a b le A p p...

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

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