ENERGY 211 / CME 211 Lecture 20 November 5, 2008.

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

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.
Chapter 2 Matrices Definition of a matrix.
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.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Section 8.1 – Systems of Linear Equations
CSE 332: C++ Associative Containers II Associative Containers’ Associated Types Associative containers declare additional types –A key_type gives the type.
259 Lecture 14 Elementary Matrix Theory. 2 Matrix Definition  A matrix is a rectangular array of elements (usually numbers) written in rows and columns.
ECON 1150 Matrix Operations Special Matrices
Data Structures Using C++ 2E
Lesson 5.4 Solving System of Equations Using Matrices.
Section 3.6 – Solving Systems Using Matrices
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Class Opener:. Identifying Matrices Student Check:
4.6: Rank. Definition: Let A be an mxn matrix. Then each row of A has n entries and can therefore be associated with a vector in The set of all linear.
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:
Copyright © 2011 Pearson Education, Inc. Solving Linear Systems Using Matrices Section 6.1 Matrices and Determinants.
Solve a system of linear equations By reducing a matrix Pamela Leutwyler.
8.2 Operations With Matrices
1.7 Linear Independence. in R n is said to be linearly independent if has only the trivial solution. in R n is said to be linearly dependent if there.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved More Linking.
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
Collection types CS Chakrabarti Motivation  Thus far the only collection types we have used are vector and matrix  Problem #1: given an input.
2.5 – Determinants and Multiplicative Inverses of Matrices.
 Recall that when you wanted to solve a system of equations, you used to use two different methods.  Substitution Method  Addition Method.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
2 2.5 © 2016 Pearson Education, Ltd. Matrix Algebra MATRIX FACTORIZATIONS.
(4-2) Adding and Subtracting Matrices Objectives: To Add and subtract Matrices To solve certain Matrix equations.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
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.
 Matrix Operations  Inverse of a Matrix  Characteristics of Invertible Matrices …
Object-Oriented Programming (OOP) Lecture No. 41
REVIEW Linear Combinations Given vectors and given scalars
Elementary Matrix Theory
Sets and Maps Chapter 9.
13.4 Product of Two Matrices
Design & Analysis of Algorithm Map
Unit 1: Matrices Day 1 Aug. 7th, 2012.
More Linking Up with Linked Lists
Slides by Steve Armstrong LeTourneau University Longview, TX
Standard Template Library (STL)
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
Matrix Operations SpringSemester 2017.
Agenda Textbook / Web Based Resource Basics of Matrices Classwork
Associative Structures
4-2 Adding & Subtracting Matrices
4.6: Rank.
CSCI N207 Data Analysis Using Spreadsheet
Recitation Outline C++ STL associative containers Examples
Sparse matrices, hash tables, cell arrays
Recursive Linked List Operations
1.3 Vector Equations.
Multidimensional array
Arrays Week 2.
Linear Algebra Lecture 21.
Iterators and STL Containers
Sets and Maps Chapter 9.
3.6 Multiply Matrices.
Matrices in MATLAB Dr. Risanuri Hidayat.
Matrices An appeaser is one who feeds a crocodile—hoping it will eat him last. Winston Churchhill.
Matrix Operations SpringSemester 2017.
Section 8.1 – Systems of Linear Equations
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
ENERGY 211 / CME 211 Lecture 18 October 31, 2008.
Linear Algebra Lecture 16.
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
A dictionary lookup mechanism
Presentation transcript:

ENERGY 211 / CME 211 Lecture 20 November 5, 2008

Iterators and Pointers Iterators extend convenience and efficiency of pointer operations to non-array collections Can perform standard pointer operations such as dereferencing, pointer arithmetic, and incrementing/decrementing For iteration, random access is less efficient than incrementing a pointer!

Sets set<T> contains elements of type T must be unique; duplicates ignored s.insert(const T& value) member function adds value to set s can use = to assign sets s.clear() member function empties s multiset<T> allows duplicates insert(), clear() available count(const T& value) member function returns number of occurrences of value

Maps map<T1,T2> contains key-value pairs unique key of type T1, value of type T2 overloads [] for retrieving value with key multimap<T1,T2>: duplicate keys lower_bound(T1), upper_bound(T1) member functions return iterators defining sequence of values matching key iterators are pointers to pair objects insert( make_pair( key, value) ) adds key-value pair to multimap erase( key ) removes key

Pairs A pair represents an ordered pair To declare: std::pair<T1,T2> p(x1,x2) where xi is of type Ti A pair has members first and second, so p.first is x1 and p.second is x2 An iterator i from a map points to a pair, where i->first is the key and i->second is the value

Working with Collections s.erase(i) erases element pointed to by the iterator i from the collection s s.erase(x) erases all elements equal to x from the collection s, where x is a key for a map or multimap, not a value i = s.find(x) looks up an element x (or key, for map or multimap) in a collection and returns iterator i pointing to matching elements, or pairs for maps (equal to end() if x is not found)

Sparse Matrices In many applications that require solution of systems of linear equations of the form Ax = b, the matrix A is large but sparse (most entries are zero) Inefficient to represent such matrices using a two-dimensional array Can only use vectors in certain cases An alternative data structure is required Must be able to quickly access elements, iterate over rows, columns

Sparse Matrices with Maps Can represent a sparse matrix using a map<pair<int,int>,double> Internally, map uses a hash table for efficient element access Can use a map<int,set<int>> to keep track of locations of nonzero entries in row/column Matrix operations should only require work proportional to number of nonzero entries

Next Time Catch-up day! Project 6 preview