CS261 Data Structures Maps (or Dictionaries). Goals Introduce the Map(or Dictionary) ADT Introduce an implementation of the map with a Dynamic Array.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
CS 261 – Recitation 9 & 10 Graphs & Final review
Lecture 10 Sept 29 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
hashing1 Hashing It’s not just for breakfast anymore!
1 CSE1301 Computer Programming Lecture 31: List Processing (Search)
CSci 143 Sets & Maps Adapted from Marty Stepp, University of Washington
hashing1 Hashing It’s not just for breakfast anymore!
C++ Plus Data Structures
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
CS Winter 2011 Abstract Data Types. Container Classes Over the years, programmers have identified a small number of different ways of organizing.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
CS261 Data Structures Tree Traversals. Goals Euler Tours Recursive Implementation Tree Sort Algorithm.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
1 Search Trees - Motivation Assume you would like to store several (key, value) pairs in a data structure that would support the following operations efficiently.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
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.
CS261 Data Structures Dynamic Arrays Part 2: Implementation.
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.
(c) University of Washington14-1 CSC 143 Java Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
24/3/00SEM107 - © Kamin & ReddyClass 16 - Searching - 1 Class 16 - Searching r Linear search r Binary search r Binary search trees.
Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
COSC 1030 Lecture 11 Sorting. Topics Sorting Themes – Low bound of sorting Priority queue methods – Selection sort – Heap sort Divide-and-conquer methods.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
And other languages….  Array literals/initialization a = [1,2,3] a2 = [-10..0, 0..10] a3 = [[1,2],[3,4]] a4 = [w*h, w, h] a5 = [] empty = Array.new zeros.
CSE 143 Lecture 14 (B) Maps and Grammars reading: 11.3 slides created by Marty Stepp
CS261 Data Structures Ordered Bag Dynamic Array Implementation.
CS261 – Data Structures Iterator ADT Dynamic Array and Linked List.
Chapter 11 Hash Anshuman Razdan Div of Computing Studies
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:
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Data Collections CS 127. Lists Lists are ordered sequences of items All programming languages provide a sequence structure similar to a Python list; in.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Maps Nick Mouriski.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
CS261 Data Structures Linked Lists - Introduction.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Dictionaries Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
CS 261 – Data Structures BuildHeap and Heap Sort.
CSE 373: Data Structures and Algorithms Lecture 16: Hashing III 1.
CSE 143 Lecture 11: Sets and Maps reading:
CS Fall 2009 Linked List Introduction. Characteristics of Linked Lists Elements are held in objects termed Links Links are 1-1 with elements, allocated.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
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.
Programming Abstractions Cynthia Lee CS106B. Today’s Topics ADTs  Map › Example: counting words in text  Containers within containers › Example: reference.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
COMP261 Lecture 23 B Trees.
Efficiency of in Binary Trees
Programming Abstractions
Road Map CS Concepts Data Structures Java Language Java Collections
Abstract Data Types (ADTs)
Linked Lists: Implementation of Queue & Deque
Hash Tables Buckets/Chaining
Hashing in java.util
Priority Queues & Heaps
A dictionary lookup mechanism
Abstract Data Types (ADTs)
Presentation transcript:

CS261 Data Structures Maps (or Dictionaries)

Goals Introduce the Map(or Dictionary) ADT Introduce an implementation of the map with a Dynamic Array

So Far…. Emphasis on values themselves – e.g. store names in an AVL tree to quickly lookup club members – e.g. store numbers in an AVL tree for a tree sort Often, however, we want to associate something else (ie. a value) with the lookup value (ie. a key) – e.g. phonebook, dictionary, student roster, etc.

Map or Dictionary ADT void put (KT key, VT value) VT get (KT key) int containsKey(KT key) void removeKey (KT key) All comparisons done on the key All returned values are VT Can implement with AVLTree, HashTable, DynArr, etc. Struct Association { KT key; VT value; }; A Map stores not just values, but Key-Value pairs

Dynamic Array Map: put void putDynArrayDictionary (struct dyArray *data, KEYTYPE key, VALUETYPE val, comparator compareKey) { struct association * ap; if (containsKeyDynArrayDictionary(vec, key, compareKey)) removeKeyDynArrayDictionary (vec, key, compareKey); ap = (struct association *) malloc(sizeof(struct association)); assert(ap != 0); ap->key = key; ap->value = val; addDynArray(vec, ap); }

Dynamic Array Map: Contains int containsMap (DynArr *v, KT key, comparator compare){ int i = 0; for (i = 0; i size; i++) { if ((*compare)(((struct association *)(v->data[i]))->key, key) == 0 ) /* found it */ return 1; } return 0; }

Map or Dictionary A Map stores not just values, but Key-Value pairs Example Application: Concordance – Count the number of times each word appears in a selection of text Keys: unique words form the text Value: count of each word

Your Turn – Worksheet 36: Dynamic Array Implementation of the Map Internally, store Struct Associations Put – Ensure that each element in the dictionary has a unique key ContainsKey – Loop until you find the ‘key’ and then return true, else false Get – Loop until you find the ‘key’ then return the value RemoveKey – Loop until you find the ‘key’, then remove the entire association