ICOM 4035 – Data Structures Lecture 11 – Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.

Slides:



Advertisements
Similar presentations
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 8 – File Structures.
Advertisements

ICOM 4035 – Data Structures Lecture 15 – Graph ADT
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 11 – Hash-based Indexing.
ICOM 4035 – Data Structures Lecture 12 – Hashtables & Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico,
ICOM 4035 – Data Structures Lecture 8 – Doubly Linked Lists Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
JSON Valery Ivanov.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary Entries and methods Using the ADT Dictionary English Dictionary Telephone.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
COMP T2 Lecture 5 School of Engineering and Computer Science, Victoria University of Wellington Thomas Kuehne Maps, Stacks  Thomas Kuehne, Marcus.
ICOM 4035 – Data Structures Lecture 2 – ADT and Interfaces Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
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.
ICOM 4035 – Data Structures Lecture 9 – Stack ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 4035 – Data Structures Lecture 5 – List ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
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.
The New Zealand Institute for Plant & Food Research Limited Matthew Laurenson Web Services: Introduction & Design Considerations.
ICOM 4035 – Data Structures Lecture 6 – Big-O Notation Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
ICOM 4035 – Data Structures Lecture 13 – Trees ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
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.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
ICOM 4035 – Data Structures Lecture 14 – Binary Search Tree ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico,
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 20.
JSON-LD. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation – It’s really language.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
ICOM 4035 – Data Structures Lecture 1 - Introduction Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
ICOM 4035 – Data Structures Lecture 3 – Bag ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Chapter 11 B Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 B-2 The ADT Binary Search Tree A deficiency of the ADT binary tree which is.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
DAY 15: ACCESS CHAPTER 1 Rahul Kavi October 6,
ICOM 4035 – Data Structures Lecture 7 – Linked Lists Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Google Data Protocol Guy Mark Lifshitz. Motivation Google’s Mission: – Organize the world’s information – Make information universally accessible – Provide.
ICOM 4035 – Data Structures Lecture 10 – Queue ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
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 373: Data Structures and Algorithms Lecture 16: Hashing III 1.
CSE 143 Lecture 11: Sets and Maps reading:
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
COMP 103 Maps and Queues. RECAP  Iterators (for-each loop)  Bag, Sets, and Stacks - a class, not interface TODAY  Maps and Queues 2 RECAP-TODAY QUICK.
The Fat-Free Alternative to XML
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
11 Map ADTs Map concepts. Map applications.
The Fat-Free Alternative to XML
JSON.
Exporting and Importing Data
JSON-LD.
Exporting and Importing Data
A Bag Implementation that Links Data
Copyright © Aiman Hanna All rights reserved
Strings and Serialization
ICOM 5016 – Introduction to Database Systems
A Very Brief Introduction to Relational Databases
JSON for Linked Data: a standard for serializing RDF using JSON
ICOM 5016 – Introduction to Database Systems
JSON-LD.
ICOM 5016 – Introduction to Database Systems
Presentation transcript:

ICOM 4035 – Data Structures Lecture 11 – Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel Rodriguez – All rights reserved

Lecture Organization Part I – Introduction to the Map ADT Part II – Design and implementation of a Map using linked List M. Rodriguez-MartinezICOM

Objectives Introduce the concept of a Map – Key-Value Store Discuss the application of Maps Understand the design and implementation of a map using linked lists Provide motivating examples ICOM 4035M. Rodriguez-Martinez 3

Companion videos Lecture11 videos – Contains the coding process associated with this lecture – Shows how to build the interfaces, concrete classes, and factory classes mentioned here M. Rodriguez-MartinezICOM

Part I Introduction to the Map ADT M. Rodriguez-MartinezICOM

Map ADT Map : – collection of items that can be retrieved through a key Stores key-value pairs : (key, value) Key represents a unique identifier for each item Each item has its key – repetitions are not allowed – Similar to mathematical functions M. Rodriguez-MartinezICOM Folder with label Books with id tags Car with license plate

Map: Keys and Values Keys: – Attributes that uniquely identify values stored Values: – Data to be stored in the map Simple values Complex objects M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map

Accessing data in Map M. Rodriguez-MartinezICOM Jil 24 NY Name Age City Student records Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map Records can be fetched based on key Apu 41 NY key M.get(Apu)

Adding data to Map M. Rodriguez-MartinezICOM Jil 24 NY Name Age City Student records Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map Records can be added and marked with key Moe 32 SJ key put (Moe, {Moe, 32, SJ})

Modeling map with a list Elements in the list are the values The keys must be extracted from the values – Method 1: value implement an interface with a method to get a key – Method 2: map includes an class whose instances are able to extract a key from the value Difference classes for different values M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF

Operations in the Map size() – number of elements isEmpty() – determine if the map is empty get(key) – returns the value associated with a key put(key, value) – adds a new value to the map with a given key (overwrites old one) remove(key) – removes the value with the given key from map makeEmpty() – removes all values from map containsKey(key) – determines if there is a value with the given key getKeys() – returns a list with all keys in the map getValue() – returns a list with all values in the map M. Rodriguez-MartinezICOM

Uses of Maps Databases – Key-value pair stores (CouchDB, MongoDB, Hive, etc) Value – record in the database Key – identifier of the record M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF

Uses of Maps (2) Processing web data with Javascript and JSON Format is – : JSON data string is parsed into a map You can then access the values based on the attribute names (keys) M. Rodriguez-MartinezICOM { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": " " }, { "type": "fax", "number": " " } ] } JSON File

Part II Part II – Design and implementation of a Map using linked List M. Rodriguez-MartinezICOM

Implement a Map with a Linked List Linked list becomes private field of Map M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF currentSize = 5 Map Methods

Getting the Key: Force Interface Method 1 – values of Map must implement an interface with a method to get the Key – Problem: What about String, Integer, or other pre- existing classes M. Rodriguez-MartinezICOM > Keyable Person Car String ???

Getting the Key: Key Extractor class Method 2 (preferred): – Instances of map must include a mechanism to extract the key of value – key extractor Typically a object that does this job One extractor for each different type of value – Some extractors might work for several values M. Rodriguez-MartinezICOM > KeyExtractor PersonKeyExtractor CarKeyExtractor StringKeyExtractor

Example Extractors KeyExtractor exposes: – getKey() Method PersonKeyExtractor: public String getKey (Person P){ return P.getSocialSecurity(); } CarKeyExtractor: public String getKey(Car C){ return C.getLicensePlate(); } StringKeyExtractor: public String getKey (String S){ return S; } IntegerKeyExtractor: public Integer getKey (Integer I){ return I; } M. Rodriguez-MartinezICOM

Map Operations: get M. Rodriguez-MartinezICOM Jil 24 NY Name Age City Student records Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map Records can be fetched based on key Apu 41 NY key get(Apu)

Map Operations: get If not empty, loop thru list until an element with given key is found – If empty return null Complexity: O(n), n = M.size() M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF currentSize = 5 Map M.get(“Li”) Element found

Map operations: put M. Rodriguez-MartinezICOM Jil 24 NY Name Age City Student records Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map Records can be added and marked with key Moe 32 SJ key M.put (Moe, {Moe, 32, SJ})

Map Operations: put(2) M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF currentSize = Map Moe 32 SJ M.put (“Moe”, {Moe, 32, SJ}) 5 6

Map Operations: put(3) If map has value with that key, erase it Add a new node with the new element at position 0 in the list Complexity: O(n), n = M.size() – Need to search map to see if value with same key exists M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF currentSize = 6 Map Moe 32 SJ M.put (“Moe”, {Moe, 32, SJ})

Map Operations: remove M. Rodriguez-MartinezICOM Jil 24 NY Name Age City Student records Bob 21 LA Apu 41 NY Amy 18 SF Li 19 SF Student Map Records can be removed based on key Apu 41 NY key remove (Apu)

Map Operations: remove M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Apu 41 NY Amy 18 SF currentSize= Map M.remove(“Apu”) 5 4

Map Operations: remove (3) First find position i of element within list Then erase element at that position I – Return null if not found Complexity: O(n), n= M.size() M. Rodriguez-MartinezICOM Jil 24 NY Bob 21 LA Li 19 SF Amy 18 SF currentSize = 5 Map

Easy Operations containsKey(key) – return this.get(key) != null – Complexity: O(n), n = M.size() (see all elements) getKeys() – Create a new list and add the key of every value – Complexity: O(n), n = M.size() (see all elements) getValues() – Create a new list and add every value to it – Complexity: O(n), n = M.size() (see all elements) M. Rodriguez-MartinezICOM

Easy operations (2) size() – Return the size of list – Complexity: O(1) isEmpty() – Return size() == 0 – Complexity: O(1) makeEmpty() – Call clear() on the list – Complexity: O(n), n = M.size() M. Rodriguez-MartinezICOM

Summary Introduced the concept of a map – Data store organized based on key and values Key – unique identifier for the value – Map must have a way to extract keys from values Discussed some application of maps – Storing/Fetching data from files/databases – Managing web data in JSON format Described design and implementation with – linked lists (as private field) M. Rodriguez-MartinezICOM

Questions? – ICOM 4035M. Rodriguez-Martinez 30