Dictionaries Collection of pairs.  (key, element)  Pairs have different keys  E.g. a pair contains two components, student id and name (1234, Nan)

Slides:



Advertisements
Similar presentations
Linear Lists – Array Representation
Advertisements

1 STL Map & Multimap Ford & Topp Chapter 11 Josuttis Sections: 6.5 & 6.6 CSE Lecture 15 – Maps.
Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
Skip List & Hashing CSE, POSTECH.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  get(theKey)  put(theKey, theElement)  remove(theKey) 5/2/20151.
Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
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.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
1 Associative Containers Gordon College Prof. Brinton.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
Dictionaries Again Collection of pairs.  (key, element)  Pairs have different keys. Operations.  Get(theKey)  Delete(theKey)  Insert(theKey, theElement)
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Data Structures Using C++ 2E
Containers Overview and Class Vector
Linear List Linked Representation. Linked Representation list elements are stored, in memory, in an arbitrary order explicit information (called a link)
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
SNU OOPSLA Lab. Chap17. Standard Containers © copyright 2001 SNU OOPSLA Lab.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
STL-Associative Containers. Associative Containers Sequence containers : "This is item 0, this is item 1, this is item 2…“ Associative containers : –
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  get(theKey)  put(theKey, theElement)  remove(theKey)
Generic Programming Using the C++ Standard Template Library.
C++ STL CSCI 3110.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Built-in Data Structures in Python An Introduction.
Chapter 9: Part 2: Vectors + Maps and STL Overview JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance.
The Utility Class pair All associative containers make use of the pair template, which is defined in. Slightly stripped down, it looks basically like this:
Lecture 11 Standard Template Library Lists Iterators Sets Maps.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
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.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys. Operations.  find(theKey)  erase(theKey)  insert(theKey, theElement)
1 CSC 211 Data Structures Lecture 30 Dr. Iftikhar Azim Niaz 1.
C++ Review STL CONTAINERS.
Associative Containers Sets Maps Section 4.8. Associative Containers.
Collection types CS Chakrabarti Motivation  Thus far the only collection types we have used are vector and matrix  Problem #1: given an input.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
CS212: Object Oriented Analysis and Design Lecture 26: STL Containers.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
Lab 3 Dictionary. Lab 3 SortedArray derived from dictionary will be provided sortedChain (interface) derived from dictionary will be provided Students.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
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.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Dictionaries Collection of items. Each item is a pair. (key, element)
Object-Oriented Programming (OOP) Lecture No. 41
Chapter 16: Linked Lists.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Standard Template Library (STL)
Homework will be announced soon Midterm exam date announced
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Chapter 9 – Sets and Maps 9.1 Associative Container
Associative Structures
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Dictionaries Collection of unordered pairs. Operations. (key, element)
Dictionaries Collection of pairs. Operations. (key, element)
CS212: Object Oriented Analysis and Design
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Recitation Outline C++ STL associative containers Examples
Iterators and STL Containers
Hashing in java.util
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
Chapter 9 – Sets and Maps 9.1 Associative Container
A dictionary lookup mechanism
Presentation transcript:

Dictionaries Collection of pairs.  (key, element)  Pairs have different keys  E.g. a pair contains two components, student id and name (1234, Nan) (2345, Charlie) Etc.

Dictionaries (theKey, theElement) (1234, Nan) (2345, Lauren) Operations.  find(theKey) find the pair with a specified key  erase(theKey) delete the pair with a specified key  insert(theKey, theElement)

Application Collection of student records in this class.  (key, element) = (student name, linear list of assignment and exam scores)  All keys are distinct.  Elements are in ascending order of key Get the element whose key is Stephen. Update the element whose key is Garrick.  insert(Key, element) implemented as update when there is already a pair with the given key. If a pair with the given key exists, return false.  erase() followed by insert().

Application Collection of student records in this class.  (key, element) = (student name, linear list of assignment and exam scores)  All keys are distinct.  Elements are in ascending order of key Get the element whose key is Stephen. Update the element whose key is Garrick.  insert(Key, element) implemented as update when there is already a pair with the given key. If a pair with the given key exists, return false.  erase() followed by insert().

Dictionary With Duplicates Keys are not required to be distinct. Word dictionary.  Pairs are of the form (word, meaning).  May have two or more entries for the same word. (bolt, a threaded pin) (bolt, a crash of thunder) (bolt, to shoot forth suddenly) (bolt, a gulp) (bolt, a standard roll of cloth) etc.

Pair template struct pair { T1 first; T2 second; // constructer pair() : first(T1()), second(T2()) {} pair(const T1& x, const T2& y) : first(x), second(y) {} // copy constructer template pair (const pair &p) : first(p.first), second(p.second) { } }

example

Make_pair template pair make_pair (T1 x, T2 y) { return ( pair (x,y) ); }

Represent As A Linear List L = (e 0, e 1, e 2, e 3, …, e n-1 ) Each e i is a pair (key, element). 5-pair dictionary D = (a, b, c, d, e).  a = (aKey, aElement), b = (bKey, bElement), etc. Array or linked representation.

Array Representation abcde Sorted Array ABCDE elements are in ascending order of key 5-pair dictionary D = (a, b, c, d, e). a = (aKey, aElement), b = (bKey, bElement), etc.

Unsorted Chain abcde NULL firstNode Sorted Chain ABCDE NULL firstNode Elements are in ascending order of Key.

Lab 3 SortedArray derived from dictionary will be provided sortedChain (interface) derived from dictionary will be provided Students will be asked to implement the member functions of sortedChain. Test program will be provided

C++ STL map Unique key values: no two elements in the map have keys that compare equal to each other. A similar associative container allowing for multiple elements with equivalent keys, multimap. multimap

C++ map Maps are a kind of associative containers that stores elements formed by the combination of a key value and a mapped value. the key value is generally used to uniquely identify the element, while the mapped value is some sort of value associated to this key. Types of key and mapped value may differ

C++ map

constructor Element access: operator[]

Operator =

begin() & end()

empty()

size()

[]

Insert()

Erase()

Swap()

Clear()

Find()

Count() a is an element of mymap. b is not an element of mymap. c is an element of mymap. d is not an element of mymap. e is not an element of mymap. f is an element of mymap. g is not an element of mymap.

lower_bound() and upper_bound() a => 20 e => 100

Equal_range()

multimap timap/