st - Robert Sedgewick and Kevin Wayne Copyright 2005

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Robert Sedgewick and Kevin Wayne Copyright 2005 http://www.Princeton.EDU/~cos226 Elementary Symbol Tables Reference: Chapter 12, Algorithms in Java, 3 rd Edition, Robert Sedgewick. 2 Symbol Table Symbol table: key-value pair abstraction. ! Insert a value with specified key. ! Given a key, search for the corresponding value. DNS lookup. ! Insert URL with specified IP address. ! Given URL, find corresponding IP address. key value www.cs.princeton.edu URL IP address 128.112.136.11 www.princeton.edu 128.112.128.15 www.yale.edu 130.132.143.21 www.harvard.edu 128.103.060.55 www.simpsons.com 209.052.165.60 3 Symbol Table Applications Application Purpose Key Value Phone book Look up phone number Name Phone number Bank Process transaction Account number Transaction details File share Find song to download Name of song Computer ID Dictionary Look up word Word Definition Web search Find relevant documents Keyword List of documents Genomics Find markers DNA string Known positions DNS Find IP address given URL URL IP address Reverse DNS Find URL given IP address IP address URL Book index Find relevant pages Keyword List of pages Web cache Download Filename File contents Compiler Find properties of variable Variable name Value and type File system Find file on disk Filename Location on disk Routing table Route Internet packets Destination Best route 4 Symbol Table Client: DNS Lookup DNS lookup client program. ! st.put(key, val) inserts a key-value pair into symbol table. ! st.get(key) searches for the given key and returns the value. public static void main ( String args ) { ST < String , String > st = new ST < String , String > (); st . put ( "www.cs.princeton.edu" , "128.112.136.11" ); st . put ( "www.princeton.edu" , "128.112.128.15" ); st . put ( "www.yale.edu" , "130.132.143.21" ); st . put ( "www.simpsons.com" , "209.052.165.60" ); System . out . println ( st . get ( "www.cs.princeton.edu" )); System . out . println ( st . get ( "www.harvardsucks.com" )); System . out . println ( st . get ( "www.simpsons.com" )); } 128.112.136.11 null 209.052.165.60 st["www.simpsons.com"] = "209.052.165.60" st["www.simpsons.com"] 5 Symbol Table Client: Frequency Counter Frequency counter. [e.g., web traffic analysis] ! Read in a key....
View Full Document

This document was uploaded on 06/10/2011.

Page1 / 6

st - Robert Sedgewick and Kevin Wayne Copyright 2005

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