STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.

Slides:



Advertisements
Similar presentations
Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
Advertisements

Dictionaries Again Collection of pairs.  (key, element)  Pairs have different keys. Operations.  Search(theKey)  Delete(theKey)  Insert(theKey, theElement)
Skip List & Hashing CSE, POSTECH.
Project 3, Standard Template Library (STL) Bryce Boe 2013/11/25 CS24, Fall 2013.
Standard Template Library Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Shallow Copy Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
Hash Tables and Associative Containers CS-212 Dick Steflik.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Dictionaries Again Collection of pairs.  (key, element)  Pairs have different keys. Operations.  Get(theKey)  Delete(theKey)  Insert(theKey, theElement)
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Value Iteration 0: step 0. Insertion Sort Array index67 Iteration i. Repeatedly swap element i with.
Data Structures and Algorithms Semester Project – Fall 2010 Faizan Kazi Comparison of Binary Search Tree and custom Hash Tree data structures.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
STL-Associative Containers. Associative Containers Sequence containers : "This is item 0, this is item 1, this is item 2…“ Associative containers : –
Quick Sort Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures.
CSIE Dept., National Taiwan Univ., Taiwan
Hash Tables.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
Singly Linked Lists Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University 1.
Sorting Algorithms Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
CSC 142 P 1 CSC 142 Collections [Reading: Chapter 10]
1 Introduction to Hashing - Hash Functions Sections 5.1, 5.2, and 5.6.
CS201: Data Structures and Discrete Mathematics I Hash Table.
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
Hashing is a method to store data in an array so that sorting, searching, inserting and deleting data is fast. For this every record needs unique key.
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Binary Search Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
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:
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
CISC220 Fall 2009 James Atlas Dec 04: Hashing and Maps K+W Chapter 9.
Hash Tables and Hash Maps. DCS – SWC 2 Hash Tables A Set and a Map are both abstract data types – we need a concrete implemen- tation in order to use.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
C++ Review STL CONTAINERS.
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
1 the BSTree class  BSTreeNode has same structure as binary tree nodes  elements stored in a BSTree are a key- value pair  must be a class (or a struct)
CSE 143 Lecture 11: Sets and Maps reading:
Distance/Similarity Functions for Pattern Recognition J.-S. Roger Jang ( 張智星 ) CS Dept., Tsing Hua Univ., Taiwan
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
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.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Simulation of Stock Trading J.-S. Roger Jang ( 張智星 ) MIR Lab, CSIE Dept. National Taiwan University.
From C to C++ Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
From C to C++ Jyh-Shing Roger Jang (張智星)
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
DP for Optimum Strategies in Games
Now with a speaking professor! (hopefully...)
Chapter 28 Hashing.
Chapter 21 Hashing: Implementing Dictionaries and Sets
Recitation Outline C++ STL associative containers Examples
Circularly Linked Lists and List Reversal
Queues Jyh-Shing Roger Jang (張智星)
Hash Tables By JJ Shepherd.
Insertion Sort Jyh-Shing Roger Jang (張智星)
Examples of Time Complexity
Selection Algorithm Jyh-Shing Roger Jang (張智星)
Game Trees and Minimax Algorithm
Sorting Algorithms Jyh-Shing Roger Jang (張智星)
A dictionary lookup mechanism
Presentation transcript:

STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University

2 Intro to Maps STL map class An easy way to create “associative array” of key-data pairs, for instance: Dictionary  key: word, data: word’s definition Yellow page  key: name, data: phone number Can be viewed as a vector indexed by keys of strings Keys could be strings or numbers Alternatively, we may want to create hash tables, which involves more hassles To create a good hash function To handle collisions Aka dictionary

3 Examples of Maps Examples

4 Summary The Good Maps provide a way of using “associative arrays” that allow you to store data indexed by keys of any type Maps can be accessed using iterators with two members “first” corresponds to the key “second” is the value associated with the key Maps are fast to have O(log(n)) time for insertion and lookup. Internally, the elements in a map are sorted from lower to higher keys The gotchas Lookup in a map requires using the find function. You need to use multimap if a key is associated with multiple pieces of data.

5 References A basic tutorial More working examples