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: 555-5699 Bill:

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Hash Tables – 1. hashtables - 2 Lin / Devi Comp 122, Fall 2003 Dictionary Dictionary: »Dynamic-set data structure for storing items.
Advertisements

1 STL Map & Multimap Ford & Topp Chapter 11 Josuttis Sections: 6.5 & 6.6 CSE Lecture 15 – Maps.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
Lecture 10 Sept 29 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
1 Associative Containers Gordon College Prof. Brinton.
CSci 143 Sets & Maps Adapted from Marty Stepp, University of Washington
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
Hash Tables. Container of elements where each element has an associated key Each key is mapped to a value that determines the table cell where element.
Chapter 16.  Data structures that take control of organizing elements  Elements not in fixed positions  Advantage – better performance Adding Removing.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
1 Joe Meehean.  Important and common problem  Given a collection, determine whether value v is a member  Common variation given a collection of unique.
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.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Spring 2010 Advanced Programming Section 1-STL Computer Engineering Department Faculty of Engineering Cairo University Advanced Programming Spring 2010.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Data Structures Using C++ 2E
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Data Structures.  Consider storing data for 100 employees by their Social Security Numbers (SSN)  SSN range: –  A fast search:
(c) University of Washington14-1 CSC 143 Java Collections.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
STL-Associative Containers. Associative Containers Sequence containers : "This is item 0, this is item 1, this is item 2…“ Associative containers : –
Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.
Big Java Chapter 16.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
Data structures Abstract data types Java classes for Data structures and ADTs.
Data structures and algorithms in the collection framework 1.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
CSC 212 – Data Structures Lecture 26: Hash Tables.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2004 Associative containers  STL data structures and algorithms  sets: insert, find, erase, empty,
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Data-structure-palooza Checkout DataStructures from SVN.
C++ Review STL CONTAINERS.
Dictionaries and Hashing CSCI 3333 Data Structures.
Associative Containers Sets Maps Section 4.8. Associative Containers.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
CSE 143 Lecture 11: Sets and Maps reading:
Lab 3 Dictionary. Lab 3 SortedArray derived from dictionary will be provided sortedChain (interface) derived from dictionary will be provided Students.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
CPSC 252 Tables / Maps / Dictionaries Page 1 Tables, Maps and Dictionaries A table (or map or dictionary) is a collection of key/value pairs. In general.
Road Map CS Concepts Data Structures Java Language Java Collections
Associative Structures
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
Searching Tables Table: sequence of (key,information) pairs
CSE 373: Data Structures and Algorithms
Recitation Outline C++ STL associative containers Examples
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
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
Iterators and STL Containers
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
Recitation Outline Hash tables in C++ STL Examples Recursive example
Presentation transcript:

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: Will: [Phil, Will, Bill]

 Unordered collection of items without duplicates  List implementation add => O(N): check for uniqueness contains => O(N) bad idea  Balanced tree implementation much better (we’ll see more about this later)

 set  Key is the data type being stored  Compare is a comparator  Ignore Alloc (almost never needed)

 pair insert(const T &key) inserts the key bool is true if key not already in set  size_type erase(const T &key) removes the item from the set  iterator find(const T &key) returns iterator to key  iterator begin(), end()

 Both store collections of objects  Lists are ordered, sets are not items have a position in a list positions are meaningless in sets  Duplicates list can contain duplicates sets cannot

 Implementation lists: array or linked list sets are balanced trees or hash tables  Some operations are faster in a set remove contains  Use a set when… don’t have/want duplicates position does not matter need fast contains and remove

 An unordered collection of unique keys with associated values no duplicate keys allowed  Generalization of an array arrays can only be indexed by ordinal data types maps can be indexed with any comparable type  What is ordinal data types? type with 1-to-1 mapping integers

 Maps verb: a key is associated with stated value e.g., B maps to 2 symbol: B => 2  Mapping noun: key-value pair symbol: B => 2  Associative array, dictionary nouns: other words for map

 map  Key is the data type of the key  Data is the data type of the value  Compare is a comparison functor  Ignore Alloc (almost never needed)

 Map methods  Overloads the [ ] operator  Insert map[“Bill”] = 27  Access cout << map[“Bill”] << endl;  Erase map.erase(“Bill”)

12