Maps1 © 2010 Goodrich, Tamassia. Maps2  A map models a searchable collection of key-value entries  The main operations of a map are for searching, inserting,

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Sequences and Iterators1.
Advertisements

© 2004 Goodrich, Tamassia Hash Tables1  
© 2004 Goodrich, Tamassia Dictionaries   
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
9.3 The Dictionary ADT    … 01/25/98, Taipei, … 03/04/98, Yunlin, … 02/15/98, Douliou, … 01/20/98,
Dictionaries1 © 2010 Goodrich, Tamassia m l h m l h m l.
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Data Structures Lecture 12 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Data Structures Lecture 13 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
© 2004 Goodrich, Tamassia Dictionaries   
CSC311: Data Structures 1 Chapter 9: Maps and Dictionaries Objectives: Map ADT Hash tables –Hash functions and hash code –Compression functions and collisions.
Dictionaries and Hash Tables1  
© 2004 Goodrich, Tamassia Priority Queues1. © 2004 Goodrich, Tamassia Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection.
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
Data Structures Hash Table (aka Dictionary) i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, Andreas Veneris, Glenn Brookshear,
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Dictionaries 4/17/2017 3:23 PM Hash Tables  
Maps, Hash Tables and Dictionaries Chapter 10.1, 10.2, 10.3, 10.5.
1Master of Computer Engineering Chiangmai University.
D ESIGN & A NALYSIS OF A LGORITHM 07 – M AP Informatics Department Parahyangan Catholic University.
Hash Tables1   © 2010 Goodrich, Tamassia.
Maps and Dictionaries Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University.
Maps, Hash Tables, Skip Lists, Sets last Update: Nov 4, 2014 EECS2011: Maps, Hash Tables, Skip Lists, Sets1.
Binary Search Trees (10.1) CSE 2011 Winter November 2015.
© 2004 Goodrich, Tamassia Hash Tables1  
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
Map ADT by Dr. Bun Yue Professor of Computer Science CSCI 3333 Data Structures.
Maps & dictionaries Go&Ta A map models a searchable collection of key-value entries The main operations of a map are for searching, inserting,
1 i206: Lecture 12: Hash Tables (Dictionaries); Intro to Recursion Marti Hearst Spring 2012.
Lists1 © 2010 Goodrich, Tamassia. Position ADT  The Position ADT models the notion of place within a data structure where a single object is stored 
CH 9 : MAPS AND DICTIONARIES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
© 2004 Goodrich, Tamassia BINARY SEARCH TREES Binary Search Trees   
1 COMP9024: Data Structures and Algorithms Week Eight: Maps and Dictionaries Hui Wu Session 2, 2014
1 COMP9024: Data Structures and Algorithms Week Nine: Maps and Dictionaries Hui Wu Session 1, 2016
Hashing1 Maps and hashing. Dr.Alagoz Hashing2 Maps A map models a searchable collection of key- value entries Typically a key is a string with an associated.
1 COMP9024: Data Structures and Algorithms Week Eight: Maps and Dictionaries Hui Wu Session 1, 2014
Lecture14: Hashing Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Maps Rem Collier Room A1.02 School of Computer Science and Informatics
Maps 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Binary Search Trees < > =
Design & Analysis of Algorithm Map
Binary Search Trees < > =
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Hash Tables 6/13/2018 Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Cuckoo Hashing.
Binary Search Trees (10.1) CSE 2011 Winter August 2018.
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Priority Queues © 2014 Goodrich, Tamassia, Goldwasser Priority Queues
Dictionaries < > = Dictionaries Dictionaries
Data Structures Maps and Hash.
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Binary Search Trees < > =
Maps.
Ordered Maps & Dictionaries
Dictionaries < > = /9/2018 3:06 AM Dictionaries
Copyright © Aiman Hanna All rights reserved
"He's off the map!" - Eternal Sunshine of the Spotless Mind
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
Dictionaries < > = /17/2019 4:20 PM Dictionaries
Binary Search Trees < > =
CH 9 : Maps And Dictionary
Binary Search Trees < > =
Maps 4/25/2019 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS210- Lecture 15 July 7, 2005 Agenda Median Heaps Adaptable PQ
Lecture 11 CS
Dictionaries < > = Dictionaries Dictionaries
Dictionaries and Hash Tables
Presentation transcript:

Maps1 © 2010 Goodrich, Tamassia

Maps2  A map models a searchable collection of key-value entries  The main operations of a map are for searching, inserting, and deleting items  Multiple entries with the same key are not allowed  Applications: address book student-record database © 2010 Goodrich, Tamassia

Maps3 The Map ADT  get(k): if the map M has an entry with key k, return its associated value; else, return null  put(k, v): insert entry (k, v) into the map M; if key k is not already in M, then return null; else, return old value associated with k  remove(k): if the map M has an entry with key k, remove it from M and return its associated value; else, return null  size(), isEmpty()  entrySet(): return an iterable collection of the entries in M  keySet(): return an iterable collection of the keys in M  values(): return an iterator of the values in M © 2010 Goodrich, Tamassia

Maps4 Example OperationOutputMap isEmpty()trueØ put(5,A)null(5,A) put(7,B)null(5,A),(7,B) put(2,C)null(5,A),(7,B),(2,C) put(8,D)null(5,A),(7,B),(2,C),(8,D) put(2,E)C(5,A),(7,B),(2,E),(8,D) get(7)B(5,A),(7,B),(2,E),(8,D) get(4)null(5,A),(7,B),(2,E),(8,D) get(2)E(5,A),(7,B),(2,E),(8,D) size()4(5,A),(7,B),(2,E),(8,D) remove(5)A(7,B),(2,E),(8,D) remove(2)E(7,B),(8,D) get(2)null(7,B),(8,D) isEmpty()false(7,B),(8,D) © 2010 Goodrich, Tamassia

Maps5 A Simple List-Based Map  We can efficiently implement a map using an unsorted list We store the items of the map in a list S (based on a doubly-linked list), in arbitrary order trailer header nodes/positions entries 9 c 6 c 5 c 8 c © 2010 Goodrich, Tamassia

Maps6 The get(k) Algorithm Algorithm get(k): B = S.positions() {B is an iterator of the positions in S} while B.hasNext() do p = B.next() { the next position in B } if p.element().getKey() = kthen return p.element().getValue() return null {there is no entry with key equal to k} © 2010 Goodrich, Tamassia

Maps7 The put(k,v) Algorithm Algorithm put(k,v): B= S.positions() while B.hasNext() do p = B.next() if p.element().getKey() = k then t = p.element().getValue() S.set(p,(k,v)) return t{return the old value} S.addLast((k,v)) n = n + 1 {increment variable storing number of entries} return null{ there was no entry with key equal to k } © 2010 Goodrich, Tamassia

Maps8 The remove(k) Algorithm Algorithm remove(k): B =S.positions() while B.hasNext() do p = B.next() if p.element().getKey() = k then t = p.element().getValue() S.remove(p) n = n – 1 {decrement number of entries} return t{return the removed value} return null{there is no entry with key equal to k} © 2010 Goodrich, Tamassia

Maps9 Performance of a List-Based Map  Performance: put takes O(1) time since we can insert the new item at the beginning or at the end of the sequence get and remove take O(n) time since in the worst case (the item is not found) we traverse the entire sequence to look for an item with the given key  The unsorted list implementation is effective only for maps of small size or for maps in which puts are the most common operations, while searches and removals are rarely performed (e.g., historical record of logins to a workstation) © 2010 Goodrich, Tamassia