Dictionaries < > = Dictionaries Dictionaries

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Binary Search Trees
Advertisements

The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
© 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.
Chapter 9: Maps, Dictionaries, Hashing Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided.
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 13 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Binary Search Trees Briana B. Morrison Adapted from Alan Eugenio.
© 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 Binary Search Trees   
CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties and maintenance.
Binary Search Trees1 Part-F1 Binary Search Trees   
© 2004 Goodrich, Tamassia Maps1. © 2004 Goodrich, Tamassia Maps2 A map models a searchable collection of key-value entries The main operations of a map.
CSC 212 – Data Structures Lecture 29: Dictionary ADT.
Binary Search Trees   . 2 Ordered Dictionaries Keys are assumed to come from a total order. New operations: closestKeyBefore(k) closestElemBefore(k)
Binary Search Trees1 ADT for Map: Map stores elements (entries) so that they can be located quickly using keys. Each element (entry) is a key-value pair.
Maps, Hash Tables and Dictionaries Chapter 10.1, 10.2, 10.3, 10.5.
Maps, Dictionaries, Hashing
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
CSC 213 – Large Scale Programming Lecture 17: Binary Search Trees.
CSC401 – Analysis of Algorithms Lecture Notes 6 Dictionaries and Search Trees Objectives: Introduce dictionaries and its diverse implementations Introduce.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
Maps and Dictionaries Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University.
© 2004 Goodrich, Tamassia Binary Search Trees1 CSC 212 Lecture 18: Binary and AVL Trees.
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,
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.
© 2004 Goodrich, Tamassia BINARY SEARCH TREES Binary Search Trees   
1 COMP9024: Data Structures and Algorithms Week Eight: Maps and Dictionaries Hui Wu Session 1, 2014
Algorithms Design Fall 2016 Week 6 Hash Collusion Algorithms and Binary Search Trees.
Maps Rem Collier Room A1.02 School of Computer Science and Informatics
COMP9024: Data Structures and Algorithms
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Binary Search Trees < > =
Binary Search Trees Rem Collier Room A1.02
Binary Search Trees < > = Binary Search Trees
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
COMP9024: Data Structures and Algorithms
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Dictionaries < > = Dictionaries Dictionaries
Data Structures Maps and Hash.
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Part-D1 Priority Queues
Binary Search Trees < > =
Binary Search Trees < > = Binary Search Trees
Dictionaries and Hash Tables
Maps.
Dictionaries < > = /3/2018 8:58 AM Dictionaries
Ordered Maps & Dictionaries
Dictionaries < > = /9/2018 3:06 AM Dictionaries
Dictionaries and Hash Tables
Copyright © Aiman Hanna All rights reserved
"He's off the map!" - Eternal Sunshine of the Spotless Mind
Dictionaries < > = /17/2019 4:20 PM Dictionaries
CH 9 : Maps And Dictionary
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
CS210- Lecture 14 July 5, 2005 Agenda Inserting into Heap
Binary Search Trees < > = Dictionaries
Dictionaries 二○一九年九月二十四日 ADT for Map:
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Dictionaries and Hash Tables
Presentation transcript:

Dictionaries < > = 6 2 9 1 4 8 Dictionaries Dictionaries 7/21/2019 4:29 PM Dictionaries < 6 2 > 9 1 4 = 8 Dictionaries

Dictionary ADT (§ 8.3) Dictionary ADT methods: find(k): if the dictionary has an entry with key k, returns it, else, returns null findAll(k): returns an iterator of all entries with key k insert(k, o): inserts and returns the entry (k, o) remove(e): remove the entry e from the dictionary entries(): returns an iterator of the entries in the dictionary size(), isEmpty() The dictionary ADT models a searchable collection of key-element entries The main operations of a dictionary are searching, inserting, and deleting items Multiple items with the same key are allowed Applications: word-definition pairs credit card authorizations DNS mapping of host names (e.g., datastructures.net) to internet IP addresses (e.g., 128.148.34.101) Dictionaries

Example Operation Output Dictionary insert(5,A) (5,A) (5,A) insert(7,B) (7,B) (5,A),(7,B) insert(2,C) (2,C) (5,A),(7,B),(2,C) insert(8,D) (8,D) (5,A),(7,B),(2,C),(8,D) insert(2,E) (2,E) (5,A),(7,B),(2,C),(8,D),(2,E) find(7) (7,B) (5,A),(7,B),(2,C),(8,D),(2,E) find(4) null (5,A),(7,B),(2,C),(8,D),(2,E) find(2) (2,C) (5,A),(7,B),(2,C),(8,D),(2,E) findAll(2) (2,C),(2,E) (5,A),(7,B),(2,C),(8,D),(2,E) size() 5 (5,A),(7,B),(2,C),(8,D),(2,E) remove(find(5)) (5,A) (7,B),(2,C),(8,D),(2,E) find(5) null (7,B),(2,C),(8,D),(2,E) Dictionaries

A List-Based Dictionary A log file or audit trail is a dictionary implemented by means of an unsorted sequence We store the items of the dictionary in a sequence (based on a doubly-linked list or array), in arbitrary order Performance: insert takes O(1) time since we can insert the new item at the beginning or at the end of the sequence find 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 log file is effective only for dictionaries of small size or for dictionaries on which insertions are the most common operations, while searches and removals are rarely performed (e.g., historical record of logins to a workstation) Dictionaries

The findAll(k) Algorithm Algorithm findAll(k): Input: A key k Output: An iterator of entries with key equal to k Create an initially-empty list L B = D.entries() while B.hasNext() do e = B.next() if e.key() = k then L.insertLast(e) return L.elements() Dictionaries

The insert and remove Methods Algorithm insert(k,v): Input: A key k and value v Output: The entry (k,v) added to D Create a new entry e = (k,v) S.insertLast(e) {S is unordered} return e Algorithm remove(e): Input: An entry e Output: The removed entry e or null if e was not in D {We don’t assume here that e stores its location in S} B = S.positions() while B.hasNext() do p = B.next() if p.element() = e then S.remove(p) return null {there is no entry e in D} Dictionaries

Hash Table Implementation We can also create a hash-table dictionary implementation. If we use separate chaining to handle collisions, then each operation can be delegated to a list-based dictionary stored at each hash table cell. Dictionaries

Binary Search Binary search performs operation find(k) on a dictionary implemented by means of an array-based sequence, sorted by key similar to the high-low game at each step, the number of candidate items is halved terminates after a logarithmic number of steps Example: find(7) 1 3 4 5 7 8 9 11 14 16 18 19 l m h 1 3 4 5 7 8 9 11 14 16 18 19 l m h 1 3 4 5 7 8 9 11 14 16 18 19 l m h 1 3 4 5 7 8 9 11 14 16 18 19 l=m =h Dictionaries

Search Table A search table is a dictionary implemented by means of a sorted array We store the items of the dictionary in an array-based sequence, sorted by key We use an external comparator for the keys Performance: find takes O(log n) time, using binary search insert takes O(n) time since in the worst case we have to shift n/2 items to make room for the new item remove takes O(n) time since in the worst case we have to shift n/2 items to compact the items after the removal A search table is effective only for dictionaries of small size or for dictionaries on which searches are the most common operations, while insertions and removals are rarely performed (e.g., credit card authorizations) Dictionaries