Reminder: Array Representation In C++

Slides:



Advertisements
Similar presentations
Linear Transformations and Matrices Jim Van Verth Lars M. Bishop
Advertisements

Learning Objectives To apply the summation and product notation To define a matrix To solve problems on matrix summation, subtraction and multiplication.
Sparse Matrices sparse … many elements are zero dense … few elements are zero.
Data Structures: Doubly Linked List1 Doubly linked list l The linear linked list is accessed from the first node each time we want to insert or delete.
Arrays and Matrices CSE, POSTECH. 2 2 Introduction Data is often available in tabular form Tabular data is often represented in arrays Matrix is an example.
Linear Algebra.
Matrices CSE, POSTECH.
Arrays.
Arrays. 1D Array Representation In C 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
Solving Linear Systems (Numerical Recipes, Chap 2)
1.7 Diagonal, Triangular, and Symmetric Matrices.
Matrices & Systems of Linear Equations
Matrices. Special Matrices Matrix Addition and Subtraction Example.
Design of parallel algorithms
Chapter 2 Matrices Definition of a matrix.
Computing Sketches of Matrices Efficiently & (Privacy Preserving) Data Mining Petros Drineas Rensselaer Polytechnic Institute (joint.
Matrix table of values
Group members: M.Shozib, Hasnain Khan, M.Awais, Shahid Rafiq Asad ali.
A matrix having a single row is called a row matrix. e.g.,
1.7 Diagonal, Triangular, and Symmetric Matrices 1.
Little Linear Algebra Contents: Linear vector spaces Matrices Special Matrices Matrix & vector Norms.
Presentation on Matrices and some special matrices In partial fulfillment of the subject Vector calculus and linear algebra ( ) Submitted by: Agarwal.
Matrices King Saud University. If m and n are positive integers, then an m  n matrix is a rectangular array in which each entry a ij of the matrix is.
Arrays and Matrices 황승원 Fall 2010 CSE, POSTECH. 2 2 Any real-life matrix you know?
SNU IDB Lab. Ch8. Arrays and Matrices © copyright 2006 SNU IDB Lab.
Targil 6 Notes This week: –Linear time Sort – continue: Radix Sort Some Cormen Questions –Sparse Matrix representation & usage. Bucket sort Counting sort.
Co. Chapter 3 Determinants Linear Algebra. Ch03_2 Let A be an n  n matrix and c be a nonzero scalar. (a)If then |B| = …….. (b)If then |B| = …..... (c)If.
Data Structure Sang Yong Han Chung-Ang University Spring
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
Matrices and Systems of Equations
Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
2.5 – Determinants and Multiplicative Inverses of Matrices.
LEARNING OUTCOMES At the end of this topic, student should be able to :  D efination of matrix  Identify the different types of matrices such as rectangular,
Section 2.1 Determinants by Cofactor Expansion. THE DETERMINANT Recall from algebra, that the function f (x) = x 2 is a function from the real numbers.
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.
Chapter 1 Section 1.6 Algebraic Properties of Matrix Operations.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Introduction Types of Matrices Operations
Arrays. 1D Array Representation In C++ 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
MATRICES A rectangular arrangement of elements is called matrix. Types of matrices: Null matrix: A matrix whose all elements are zero is called a null.
MTH108 Business Math I Lecture 20.
Data Structure Sang Yong Han
Matrices and Vector Concepts
Matrices Rules & Operations.
1.5 Matricies.
Arrays.
Chapter 7: Array.
Abstract Data Types Sparse Matrices CSCI 240
Chapter 8: Lesson 8.1 Matrices & Systems of Equations
Computer Graphics Matrix
Reminder: Array Representation In C++
Agenda Textbook / Web Based Resource Basics of Matrices Classwork
بردارها و ماتريس ها ساختمان داده ها
Matrix Algebra - Overview
Matrices Introduction.
Determinant of a Matrix
Presented By Farheen Sultana Ist Year I SEM
Algorithms: Design and Analysis
Arrays.
Arrays.
Matrices Introduction.
Linear Algebra Lecture 11.
Matrices An appeaser is one who feeds a crocodile—hoping it will eat him last. Winston Churchhill.
Section 8.1 – Systems of Linear Equations
Reminder: Array Representation In C++
Algorithms CSCI 235, Spring 2019 Lecture 32 Graphs I
Arrays and Matrices Prof. Abdul Hameed.
Presentation transcript:

Reminder: Array Representation In C++ b c d e f g h i j k l x[] This representation is called the array-of-arrays representation. Requires contiguous memory of size 3, 4, 4, and 4 for the 4 1D arrays. 1 memory block of size number of rows and number of rows blocks of size number of columns

Reminder: Row-Major Mapping Example 3 x 4 array: a b c d e f g h i j k l Convert into 1D array y by collecting elements by rows. Within a row elements are collected from left to right. Rows are collected from top to bottom. We get y[] = {a, b, c, d, e, f, g, h, i, j, k, l} Used in Pascal and Fortran for example. row 0 row 1 row 2 … row i

Row-Major Used in Google’s TensorFlow From code comments on GitHub: "For all types other than TF_STRING, the data buffer stores elements in row major order. “ Source: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/c_api.h

sparse … many elements are zero dense … few elements are zero Sparse Matrices sparse … many elements are zero dense … few elements are zero

Example Of Sparse Matrices diagonal tridiagonal lower triangular (?) These are structured sparse matrices. May be mapped into a 1D array so that a mapping function can be used to locate an element. element (i,j) is at position i(i-1)/2 + j -1 for a lower triangular matrix using row-major representation

Unstructured Sparse Matrices Airline flight matrix. airports are numbered 1 through n flight(i,j) = list of nonstop flights from airport i to airport j n = 1000 (say) n x n array of list references => 4 million bytes total number of flights = 20,000 (say) need at most 20,000 list references => at most 80,000 bytes Assume that flight(i,j) = null if there is no flight from i to j. Of the 1 million entries in the flight matrix at most 20,000 can be nonnull as each nonnull entry represents at least 1 different flight. So we need to store at most 20,000 nonnull entries.

Unstructured Sparse Matrices Web page matrix. web pages are numbered 1 through n web(i,j) = number of links from page i to page j Web analysis. authority page … page that has many links to it hub page … links to many authority pages Web page analyses are done using a matrix such as web(*,*). See IEEE Computer, August 1999, p 60, for a paper that describes Web analysis based on such a matrix. Operations such as matrix transpose and multiply are used.

Web Page Matrix n = 2 billion (and growing by 1 million a day) n x n array of ints => 4* 1018 integers = 16* 1018 bytes (16 * 109 GB) each page links to 10 (say) other pages on average on average there are 10 nonzero entries per row space needed for nonzero elements is approximately 20 billion x 4 bytes = 80 billion bytes (80 GB) On average, 10 entries in each row are nonzero.

A Sparse Matrix An example of a sparse matrix: (2 nonzero elements, 10 zero elements) [[1, 0, 0, 0] [0, 0, 2, 0] [0, 0, 0, 0]]

Representation Of Unstructured Sparse Matrices Single linear list in row-major order. scan the nonzero elements of the sparse matrix in row-major order each nonzero element is represented by a triple (row, column, value) the list of triples may be an array list or a linked list (chain)

Single Linear List Example 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 list = row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6 The single linear list has 6 elements. Each list element is a triple (row, column, value).

Array Linear List Representation row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 element 0 1 2 3 4 5 row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6 The list and array linear list representation drawings are essentially the same, because of the identity mapping (element[i] = list element i) that is used.

Chain Representation Node structure. row col next value The drawing, above, assumes a custom class for matrices. This custom class does not use the class chain. If you want to use the class chain, the fields row, col, and value need to be in another class, say data. The elements of chain will have the data type data.

Single Chain row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 1 3 5 4 2 7 6 NULL firstNode

One Linear List Per Row row1 = [(3, 3), (5,4)] 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 Array linear list per row.

Array Of Row Chains Node structure. next value col The above drawing assumes a custom class for sparse matrices. If you want to use the class chain, the col and value fields will be members of some other class (say) data. The data type of the elements in the chains will be data.

Array Of Row Chains 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 row[] 3 4 NULL 4 5 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 5 3 NULL 7 4 NULL Similar to adjacency lists 2 NULL 6 3

Orthogonal List Representation Both row and column lists. Node structure. row col next down value

Row Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 NULL 1 3 5 4 2 7 6 N

Column Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 1 3 5 4 2 7 6 N

Orthogonal Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 row[] 1 3 5 4 NULL row[] 1 3 5 4 2 7 6 N

May use circular lists instead of chains. Variations May use circular lists instead of chains. Or, even doubly linked circular lists.

Approximate Memory Requirements 500 x 500 matrix with 1994 nonzero elements 2D array 500 x 500 x 4 = 1million bytes Single Array List 3 x 1994 x 4 = 23,928 bytes One Chain Per Row 23928 + 500 x 4 = 25,928

Runtime Performance Matrix Transpose 500 x 500 matrix with 1994 nonzero elements 2D array 1.97 ms Single Array List 0.09 ms One Chain Per Row 1.57 ms

Performance Matrix Addition. 500 x 500 matrices with 1994 and 999 nonzero elements 2D array 2.69 ms Single Array List 0.13 ms One Chain Per Row Not Measured