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.

Slides:



Advertisements
Similar presentations
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Advertisements

Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
1 STL Map & Multimap Ford & Topp Chapter 11 Josuttis Sections: 6.5 & 6.6 CSE Lecture 15 – Maps.
CSE Lecture 16 – Hashing & Tables
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
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 Associative Containers Gordon College Prof. Brinton.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
1 Associative Containers Gordon College Prof. Brinton.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 7 Ming Li Department of.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
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.
Priority Queues Briana B. Morrison Adapted from Alan Eugenio Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Main Index Contents 11 Main Index Contents Storage Containers -GeneralGeneral -Vectors (3 slides)Vectors -ListsLists -MapsMaps ADT’s ADT’s ADT’s (2 slides)Classes.
Main Index Contents 11 Main Index Contents Week 4 – Stacks.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Data Structures Using C++ 2E
HASHING Section 12.7 (P ). HASHING - have already seen binary and linear search and discussed when they might be useful (based on complexity)
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
Containers Overview and Class Vector
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
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.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
A Binary Search Tree Binary Search Trees.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
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:
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Class List { public: // TYPEDEF and MEMBER CONSTANTS enum { CAPACITY = 30 }; // Or: static const size_t CAPACITY = 30; typedef double Item; // CONSTRUCTOR.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Associative Containers Sets Maps Section 4.8. Associative Containers.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 17 B-Trees and the Set Class Instructor: Zhigang Zhu Department of Computer Science.
CS212: Object Oriented Analysis and Design Lecture 26: STL Containers.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
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.
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.
CSC212 Data Structure - Section AB
Data Abstraction: The Walls
Standard Template Library (STL)
Basic Data Structures.
– Introduction to Object Technology
Data Structures Binary Trees.
Associative Structures
A Sorted, Unique Key Container
Recitation Outline C++ STL associative containers Examples
Chapter 10 1 – Binary Trees Tree Structures (3 slides)
Lists - I The List ADT.
Lists - I The List ADT.
Recitation Outline Hash tables in C++ STL Examples Recursive example
Chapter 10: Binary Trees.
The List Container and Iterators
Chapter 9 – Sets and Maps 9.1 Associative Container
A dictionary lookup mechanism
Presentation transcript:

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 Data Key-Value Example Key-Value Example Binary Search Tree Binary Search Tree & R/B Tree & R/B Tree Set API Set API (5 slides) Set API Sieve of Eratosthenes Sieve of Eratosthenes Set Operators Set Operators Maps Multiset API (Multiset API (2 slides) Multiset API ( SummarySummary (4 slides) Summary Chapter 11 – Associative Containers

Main Index Contents 22 Main Index Contents Sets

Main Index Contents 33 Main Index Contents Sets defined by a key along with other data

Main Index Contents 4 Key-Value Data A map stores data as a key-value pair. In a pair, the first component is the key; the second is the value. Each component may have a different data type.

Main Index Contents 55 Main Index Contents Key-Value Example

Main Index Contents 6 Binary Search Tree and Red/Black Tree

Main Index Contents 77 Main Index Contents CLASS set Constructors set(); Create an empty set. This is the Default Constructor. set(T *first, T *last); Initialize the set by using the address range [first, last). CLASS set Operations bool set() const; Is the set empty? int size() const; Return the number of elements in the set.

Main Index Contents 88 Main Index Contents CLASS set Operations int count(const T& key) const; Search for key in the set and return 1 if it is in the set and 0 otherwise. iterator find(const T& key); Search for key in the set and return an iterator pointing at it, or end() if it is not found. Const_iterator find(const T& key) const; Constant version.

Main Index Contents 99 Main Index Contents CLASS set Operations pair insert(const T& key); If key is not in the set, insert it and then return a pair whose first element is an iterator pointing to the new element and whose second element is true. Otherwise, return a pair whose first element is an iterator pointing at the existing element and whose second element is false. Postcondition: The set size increases by 1 if key is not in the set. int erase(const T& key); If key is in the set, erase it and return 1; otherwise, return 0. Postcondition: The set size decreases by 1 if key is in the set.

Main Index Contents 10 Main Index Contents CLASS set Operations void erase(iterator pos); Erase the item pointed to by pos. Preconditions: The set is not empty, and pos points to a valid set element. Postcondition: The set size decreases by 1. void erase(iterator first, iterator last); Erase the elements in the range [first, last). Precondition: The set is not empty. Postcondition: The set size decreases by the number of elements in the range.

Main Index Contents 11 Main Index Contents CLASS set Operations iterator begin(); Return an iterator pointing at the first member in the set. const_iterator begin(const); Constant version of begin(). iterator end(); Return an iterator pointing just past the last member in the set. const_iterator end() const; Constant version of end().

Main Index Contents 12 Main Index Contents Sieve of Eratosthenes

Main Index Contents 13 Main Index Contents Set-Union Operator+ (A + B): The set of all elements x such that x is an element in set A OR x is an element in set B. Example:A + B = { 1, 2, 3, 6, 8, 9, 10} Set-Intersection Operator* (A * B): The set of all elements x such that x is an element in set A and x is an element in set B. Example:A * B = { 3, 9} Set-Difference Operator - (A - B): The set of all elements x such that x is an element in set A but x is not an element in set B. Example:A - B = { 1, 8, 10}

Main Index Contents 14 Main Index Contents Maps

Main Index Contents 15 Main Index Contents CLASS multiset Operations int count(const T& item) const; Return the number of duplicate occurrences of item in the multiset. pair equal_range(const T& item); Return a pair of iterators such that all occurrences of item are in the iterator range[first member of pair, second member of pair). iterator insert(const T& item); Insert item into the multiset and return an iterator pointing at the new element. Postcondition: The element item is added to the multiset.

Main Index Contents 16 Main Index Contents CLASS multiset Operations int erase(const T& item); Erase all occurrences of item from the multiset and return the number of items erased. Postcondition: The size of the multiset is reduced by the number of occurrences of item in the multiset.

Main Index Contents 17 Main Index Contents Summary Slide 1 §- Set and map associative containers -Both store and retrieve data by value rather by position. -A set is a collection of keys, where each key is unique. -A map is a collection of key-value pairs that associate a key with a value. §-In a map, there is only one value associated with a key.

Main Index Contents 18 Main Index Contents Summary Slide 2 §- Set and map implementation -Binary search tree ideal, since it is an associative container and its iterators traverse its value in order.

Main Index Contents 19 Main Index Contents Summary Slide 3 §- Map -Often called an associative array because applying the index operator with the key as its argument accesses the associated value.

Main Index Contents 20 Main Index Contents Summary Slide 4 §- Multiset -Like a set, except a key can occur more than once. -The member function count() and equal_range() deal with duplicate values.