Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind.

Slides:



Advertisements
Similar presentations
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary Entries and methods Using the ADT Dictionary English Dictionary Telephone.
Advertisements

© 2006 Pearson Addison-Wesley. All rights reserved12 B-1 Chapter 12 (continued) Tables and Priority Queues.
© 2006 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 Tables and Priority Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
1 Topic 9 Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary A Java Interface Iterators Using the ADT Dictionary A Directory of Telephone.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Sets and Maps Part of the Collections Framework. The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
1 Sets and Maps Starring: keySet Co-Starring: Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
The Java Collections Framework (JCF) Introduction and review 1.
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
CSC 142 P 1 CSC 142 Collections [Reading: Chapter 10]
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
Sets and Maps Sets Maps The Comparator Interface Sets and Maps in Java Collections API – TreeSet – TreeMap Review for Exam Reading:
CS Ananda Gunawardena.  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Maps Nick Mouriski.
Week 9 - Friday.  What did we talk about last time?  Collisions  Open addressing ▪ Linear probing ▪ Quadratic probing ▪ Double hashing  Chaining.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
1 Maps, Stacks and Queues Maps Reading:  2 nd Ed: 20.4, 21.2, 21.7  3 rd Ed: 15.4, 16.2, 16.7 Additional references: Online Java Tutorial at
Collections Dwight Deugo Nesa Matic
CSE 143 Lecture 11: Sets and Maps reading:
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Tables and Priority Queues
Java Collections OOP tirgul No
Using the Java Collection Libraries COMP 103 # T2
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
11 Map ADTs Map concepts. Map applications.
CSC 321: Data Structures Fall 2016 Balanced and other trees
Wednesday Notecards. Wednesday Notecards Wednesday Notecards.
Efficiency of in Binary Trees
Week 8 - Friday CS221.
A tree set Our SearchTree class is essentially a set.
Road Map CS Concepts Data Structures Java Language Java Collections
Introduction to Collections
Introduction to Collections
TCSS 143, Autumn 2004 Lecture Notes
TCSS 342, Winter 2006 Lecture Notes
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
"He's off the map!" Topic 9 Maps
CSE 373: Data Structures and Algorithms
Introduction to Collections
Introduction to Collections
Collections A First Glimpse.
Part of the Collections Framework
Java Collections Framework
A tree set Our SearchTree class is essentially a set.
Arrays .
"He's off the map!" - Eternal Sunshine of the Spotless Mind
Exercise Write a program that counts the number of unique words in a large text file (say, Moby Dick or the King James Bible). Store the words in a collection.
CS2110: Software Development Methods
Introduction to Collections
ArrayLists 22-Feb-19.
Collections Framework
L5. Necessary Java Programming Techniques
Introduction to Collections
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
Containers and Iterators
slides created by Marty Stepp
Collections A First Glimpse 16-Apr-19.
Hashing in java.util
Data Structures II AP Computer Science
Set and Map IS 313,
Week 6 - Monday CS221.
Presentation transcript:

Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind

Other Data Structures Write a program to count the frequency of all the words in a file. Make a simplification: assume words are anything set off by whitespace Maps

Why So Slow Write a contains method for an array based list public boolean contains(E target) { CS 314 Maps

A Faster Way - Maps Also known as: table, search table, dictionary, associative array, or associative container A data structure optimized for a very specific kind of search / access In a map we access by asking "give me the value associated with this key." Recall, in the ArrayList example we did not count the number of occurrences of each word CS 314 Maps

Keys and Values Dictionary Analogy: The key in a dictionary is a word: foo The value in a dictionary is the definition: First on the standard list of metasyntactic variables used in syntax examples A key and its associated value form a pair that is stored in a map To retrieve a value the key for that value must be supplied A List can be viewed as a Map with integer keys CS 314 Maps

More on Keys and Values Keys must be unique, meaning a given key can only represent one value but one value may be represented by multiple keys like synonyms in the dictionary. Example: factor: n.See coefficient of X factor is a key associated with the same value (definition) as the key coefficient of X CS 314 Maps

The Map<K, V> Interface in Java void clear() Removes all mappings from this map (optional operation). boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key. boolean containsValue(Object value) Returns true if this map maps one or more keys to the specified value. Set<K> keySet() Returns a Set view of the keys contained in this map. CS 314 Maps

The Map Interface Continued V get(Object key) Returns the value to which this map maps the specified key. boolean isEmpty() Returns true if this map contains no key-value mappings. V put(K key, V value) Associates the specified value with the specified key in this map CS 314 Maps

The Map Interface Continued V remove(Object key) Removes the mapping for this key from this map if it is present int size() Returns the number of key-value mappings in this map. Collection<V> values() Returns a collection view of the values contained in this map. CS 314 Maps

Other Uses? Maps