Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)

Slides:



Advertisements
Similar presentations
CSci 143 Sets & Maps Adapted from Marty Stepp, University of Washington
Advertisements

CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
CSE 143 Lecture 15 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
1 The Map ADT © Rick Mercer. 2 The Map ADT  A Map is an abstract data type where a value is "mapped" to a unique key  Also known as Dictionary  Need.
(c) University of Washington14-1 CSC 143 Java Collections.
1 Sets and Maps Starring: keySet Co-Starring: Collections.
The Java Collections Framework (Part 2) By the end of this lecture you should be able to: Use the HashMap class to store objects in a map; Create objects.
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
CSE 143 Lecture 14 (B) Maps and Grammars reading: 11.3 slides created by Marty Stepp
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
CSE 143 Lecture 14 Maps/Sets; Grammars reading: slides adapted from Marty Stepp and Hélène Martin
Maps Nick Mouriski.
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
CSE 143 Lecture 11: Sets and Maps reading:
Lecture14: Hashing Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Linked Data Structures
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
Building Java Programs
Design & Analysis of Algorithm Map
CSc 110, Spring 2017 Lecture 29: Sets and Dictionaries
Wednesday Notecards. Wednesday Notecards Wednesday Notecards.
slides created by Marty Stepp and Hélène Martin
CSc 110, Autumn 2016 Lecture 27: Sets and Dictionaries
Data Structures TreeMap HashMap.
Generic array list and casting C&K s7.7
CSc 110, Spring 2017 Lecture 28: Sets and Dictionaries
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
Lecture 3: Working with Data Structures
COMP 103 Maps, Stacks Thomas Kuehne 2016-T2 Lecture 5
CSc 110, Spring 2018 Lecture 32: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 30: Sets and Dictionaries
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.
Week 2: 10/1-10/5 Monday Tuesday Wednesday Thursday Friday
Road Map CS Concepts Data Structures Java Language Java Collections
TreeSet TreeMap HashMap
Data Structures and Algorithms
Data Structures and Algorithms
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
CSE 373: Data Structures and Algorithms
Part of the Collections Framework
Lecture 5: Master Theorem, Maps, and Iterators
Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind.
EE 422C Sets.
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Implementing Hash and AVL
"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
CSE 373 Java Collection Framework, Part 2: Priority Queue, Map
slides created by Marty Stepp
CSE 373 Separate chaining; hash codes; hash maps
Lecture 3: Maps and Iterators
slides created by Marty Stepp
Fundaments of Game Design
Hashing in java.util
slides adapted from Marty Stepp and Hélène Martin
Lecture 3: Maps and Iterators
CS 240 – Advanced Programming Concepts
CO4301 – Advanced Games Development Week 12 Using Trees
CSE 373 Set implementation; intro to hashing
Dictionary.
Presentation transcript:

Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains) We don't think of a set as having indexes; we just add things to the set in general and don't worry about order set.contains("to") true set "the" "of" "from" "to" "she" "you" "him" "why" "in" "down" "by" "if" set.contains("be") false

Maps (11.3) map: Holds a set of key-value pairs, where each key is unique a.k.a. "dictionary", "associative array", "hash" map.get("the") 56 set key value "at" 43 key value "you" 22 key value "in" 37 key value "why" 14 key value "me" 31 key value "the" 56

Map methods put(key, value) adds a mapping from the given key to the given value; if the key already exists, replaces its value with the given one get(key) returns the value mapped to the given key (null if not found) containsKey(key) returns true if the map contains a mapping for the given key remove(key) removes any existing mapping for the given key clear() removes all key/value pairs from the map size() returns the number of key/value pairs in the map isEmpty() returns true if the map's size is 0 toString() returns a string such as "{a=90, d=60, c=70}" keySet() returns a set of all keys in the map values() returns a collection of all values in the map putAll(map) adds all key/value pairs from the given map to this map equals(map) returns true if given map has the same mappings as this one

Evil Hangman (animation) {ally, beta, cool, deal, else, flew, good, hope, ibex} Guess: ‘e’ Pattern: “- - - -” “- - - -” “- - - -” “- - - -” “- e - -” “- e - -” “- - e -” “- - e -” “e - - e” “- - - e” {ally} {ally, cool} {ally, cool, good} {beta} {beta, deal} {flew, ibex} {flew} {else} {hope} Guess: ‘o’ {ally, cool, good} Pattern: “- - - -” “- o o -” “- - - -” {cool, good} {ally} Guess: ‘d’ {cool, good} Pattern: “- o o -” “- o o -” “- o o d” {cool} {good}