Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.
-
Upload
charleen-fleming -
Category
Documents
-
view
213 -
download
0
Transcript of Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.
![Page 1: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/1.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-1
Lesson 2
More uses of Matrices Arrays
![Page 2: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/2.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-2
Lesson 2 Overview
Building arrays from raw dataAdding rows or columnsArray arithmeticArrays for pricingMore about matrices
An array exampleBinary treesBack and trace pointersNetworksNetworks as arrays
![Page 3: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/3.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-3
Building arrays from raw data
One dimension arrayArr: array[1..3] of Real=
(10.25, -20.15, 30.85);
Multi-dimension array Arr: array[1..2,1..3] of Real=
((10.25, -20.15, 30.85), (14.50, 14.45, 10.75));
![Page 4: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/4.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-4
Adding rows or columns
Var arr:Array[1..2,1..3] of Integer;…(* adding row 2 *)Result:=0;For i:=1 to 3 do
Result:=Result + arr[2][i];
![Page 5: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/5.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-5
Array arithmetic
Add/Subtract arrays: Arrays must be same format (same number of columns and number of rows) “Scalar" multiplication: Multiply the “scalar” with all elements of the array Multiply two array: in order to multiply arrays A and B the number of columns in A must equal the number of rows in B
![Page 6: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/6.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-6
Arrays for pricing
Array multiplication for order costing
178
106
205
195
6
9
2
13
8
201983
38401
212734
82457
![Page 7: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/7.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-7
More about matrices
The common operations on a matrix Add a constant vector/matrix to a matrix Multiply/divide a scalar to a matrix Add/Subtract from another matrix Cell-by-cell multiplication Multiply by a row/column vector Multiply, selectively, by a square matrix Multiply by another matrix
![Page 8: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/8.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-8
An array example
“A manufacturing company, in factories at Andover and Bristol respectively, employs the following numbers of people in 4 grades for each of 6 job-categories and at different monthly pay scales”
![Page 9: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/9.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-9
Binary trees
1
2
3
4
5
![Page 10: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/10.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-10
Binary treesGreat-Great-Grand-parents
Great-Grand-parents
Grand-parents
Parents
Sons and Daughters
![Page 11: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/11.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-11
Back and trace pointers
BACK POINTERS can be added to each node so that it is possible to work up the tree from any node to trace its ancestors.TRACE POINTER can also be added which, from any node, would allow to trace the next in alphabetical (or numerical) sequence.
![Page 12: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/12.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-12
Networks
A
B
C
D
![Page 13: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/13.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-13
Networks as arrays
Star networkA B C D
A 0 1 1 1S = B 1 0 0 0
C 1 0 0 0D 1 0 0 0
![Page 14: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/14.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-14
Networks as arrays
RingA B C D
A 0 0 0 0R = B 0 0 1 1
C 0 1 0 1D 0 1 1 0
![Page 15: Discrete Math 2-1 Copyright © Genetic Computer School 2007 Lesson 2 More uses of Matrices Arrays.](https://reader036.fdocuments.in/reader036/viewer/2022082904/56649e1b5503460f94b09677/html5/thumbnails/15.jpg)
Copyright © Genetic Computer School 2007 Discrete Math 2-15
Networks as arrays
LANA B C D
A 0 0 1 1L = B 0 0 0 0
C 1 0 0 1D 1 0 1 0