Copyright © Aiman Hanna All rights reserved

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Hash Tables1  
Advertisements

© 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.
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   
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Maps, Hash Tables and Dictionaries Chapter 10.1, 10.2, 10.3, 10.5.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
D ESIGN & A NALYSIS OF A LGORITHM 07 – M AP Informatics Department Parahyangan Catholic University.
Hash Tables1   © 2010 Goodrich, Tamassia.
Binary Search Trees (10.1) CSE 2011 Winter November 2015.
© 2004 Goodrich, Tamassia Hash Tables1  
Map ADT by Dr. Bun Yue Professor of Computer Science CSCI 3333 Data Structures.
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.
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,
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
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,
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Binary Search Trees < > =
Design & Analysis of Algorithm Map
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Ch7. List and Iterator ADTs
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.
Efficiency of in Binary Trees
Binary Search Trees (10.1) CSE 2011 Winter August 2018.
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
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
Bucket-Sort and Radix-Sort
Array Lists, Node Lists & Sequences
Binary Search Trees (10.1) CSE 2011 Winter November 2018.
Data Structures Maps and Hash.
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Copyright © Aiman Hanna All rights reserved
Breadth-First Search (BFS)
Priority Queues 4/6/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Copyright © Aiman Hanna All rights reserved
Maps.
Ordered Maps & Dictionaries
Doubly Linked Lists or Two-way Linked Lists
CS212D: Data Structures Week 5-6 Linked List.
Copyright © Aiman Hanna All rights reserved
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
Recall What is a Data Structure Very Fundamental Data Structures
CH 9 : Maps And Dictionary
Copyright © Aiman Hanna All rights reserved
Copyright © Aiman Hanna All rights reserved
Linked Lists & Iterators
Copyright © Aiman Hanna All rights reserved
Dictionaries 4/5/2019 1:49 AM Hash Tables  
Copyright © Aiman Hanna All rights reserved
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,
Copyright © Aiman Hanna All rights reserved
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
Presentation transcript:

Copyright © 2011-2016 Aiman Hanna All rights reserved Maps Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been extracted, modified and updated from original slides of : Data Structures and Algorithms in Java, 5th edition. John Wiley& Sons, 2010. ISBN 978-0-470-38326-1. Data Structures and the Java Collections Framework by William J. Collins, 3rdedition, ISBN 978-0-470-48267-4. Both books are published by Wiley. Copyright © 2010-2011 Wiley Copyright © 2010 Michael T. Goodrich, Roberto Tamassia Copyright © 2011 William J. Collins Copyright © 2011-2016 Aiman Hanna All rights reserved

Coverage Label (Unique Key) Cabinet (Map) Folders (Values) Section 9.1: Maps Label (Unique Key) Cabinet (Map) Folders (Values) Maps

Maps A map models a searchable collection of key-value entries. A map allows us to store elements in a way that speeds up locating them through the utilization of keys. The main operations of a map are searching, inserting, and deleting items. Multiple entries with the same key are not allowed. In other words, the keys in a map are unique. Applications: address book student-record database Maps

The Map ADT A map supports the following methods: 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, replace the value associated with k with v and return that old value remove(k): if the map M has an entry with key k, remove it from M and return its associated value; else, return null entrySet(): return an iterable collection containing all the key-value entries in M Maps

The Map ADT A map supports the following methods (continues): keySet(): return an iterable collection of all the keys in M values(): return an iterable collection of all the values in M size(): return the number of entries in M isEmpty(): test whether M is empty Maps

Example Operation Output Map 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) Maps

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 5 8 Maps

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() = k then return p.element().getValue() return null {there is no entry with key equal to k} Maps

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 } Maps

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} Maps

Performance of a List-Based Map put takes O(n) time since we need to find out before adding the item if an entry with the key exists (in such case we only replace the value) 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 sizes. Maps