0% found this document useful (0 votes)
16 views

Sparse Matrix

The document discusses two methods for storing sparse matrices: 1) Coordinate list/three column representation which stores the row number, column number and element of non-zero entries. 2) Compressed sparse row which stores a list of non-zero elements and their row positions.

Uploaded by

mrrobot0987654
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Sparse Matrix

The document discusses two methods for storing sparse matrices: 1) Coordinate list/three column representation which stores the row number, column number and element of non-zero entries. 2) Compressed sparse row which stores a list of non-zero elements and their row positions.

Uploaded by

mrrobot0987654
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Sparsemttrlx

↳ of
Having many number

non -
zero elements

Methods for storing sparse mature

1 Coordinate List / Three column


.

representation
2 .

Compressed sparse row

1 .
coordinatel.is/Thoeecolumnrepresentati#

I 2 3 4 5 6 7 8 9
-
row column element

:/
-

:/
82
I O O O O O O O 3 O 8 9

O O 8 O O 10 O O O l 8 3

3 O O O O O o o o o 2 3 8

: : : : : : : : : : :
G O O O O O O O
6 3

27
z O

O O
O 4
68
O O O G O O
7

O 9 O O 5 O O O O 8 z 9
- -

8×9 72 elements 8 5 5

72×2=144 bytes

Compressedsparserowft
2 .

[ 3,8 4,2 9 5 ] → Non Zero

[
,
10 , , 6 , ,
elements

a[ Oo y } } y y § g
, , , , , , , ,
row number
→ commutative sum of number of non

zero elements in each row

> JA [ 8 , 3,6 ,
I , 3,4 , 2,5]

NO of column in which each non zero element is located

8+9+8 25×2 50 bytes


= =
I .
coordinatel.is/Thoeecolumnrepresentati# ( ADDITION )

I 2 3 4 5 G
-

:/
-

:/
I O O O G O O O l Z 3 4 5

a-
: : : : : : : : : : :
5 5

45
Y O O O O O o 6 7 2

4 O O O O O
-
-

I 2 3 4 5 G
-

/
-

/
I O O O o O O O l Z 3 4 5 G

O 3 O O 5 O 5 2 2 3 3 4 5
B = 2

> o > g z s z g y ,
o o z o

5 9

85
Y O O O 9 O O G 3 2 7

8 O O O O O
-
-

I 2 3 4 5 G
-

/
-

/
I O O O G O O O l 2 3 4 5 6 7 8 9

3 3 4 5
c. = 2 O 10 O O 5 O 5 I 2 2 3 3

> g z s z z y g y ,
o z z s o > y

Y O O O 9 O O G Io S Z Z 5 7 9 12

5 12 O O O O O
-
-
-

/ :/
4 5
Q i 2 3
CREATING SPARSE MATRIX PROGRAM

f
- -

:/
=
-

I O O 7 O O

: : : :
4 O O O O 4
- -

4×5 mxn

: : : : : :
5 7 2 5 9 4
k

Struct Element void create ( struct sparse


*
s )
{ E
int i ; int i
;
int dimensions ) ;
"
j; point fl
"
Enter

Is → m Is → n ) ;
"
int scarf l
''
n
; t . d f. d
, ,

}
point fl
"
Enter number of non
-

zero elements) ;
''
"
struct sparse scarf l t d .

,
Is →
nvm ) ;

{ -

s → e new Elements [s → nvm ];

)
=

" "
);
int m ; print fl Enter all elements
-

int n
;

int nvm ; for li=o ; is s → nvm


; i + t )

Is → e[ i]
* " "
struct Element e; Sanfl Xd Xd Xd ,
-
i
,

ISI
f. main "

,
.

Structsparse s ;

§ /
I

create Cds) ;

} s
D

S→e=(struct Element e) malice ←


f
*
" "" size#"' " "ment"

?
ii#
e -

:
=
ADDINGSPARSEMATRIPROGRAM-123.lt 5

÷::
'
,

t :L
I O O O O 2

: : : :
O G O O O 4 O O O O 9
- -

it:#
5

÷
M O l 2 3 4

Title
i I 2 2 3 3 4

→ → a

i j

add ( struct sparse


*
SI ,
struct
sparse S2) sum

{ Of

!m→
*
street Sumi
sparse

il
'
if ( St → m ! = Sz→ m S1→n ! =
sz→n) n

O 3 4 5
l 2
ZCtU8h 0 ; -

i
Sum new
sparse ;
=

i
sum -sm=s1→m ;

Sum → n
=
S1 → n
;
n
-

sum →
e = new Element [ S1 →
nvm -152

nvm ]; k

while ( is S1 → nvm Id jssz → nvm)


{

is'a→eei+
insane

Irc
;
::p:L:
else if ( S1 → eli] i -
> s2→eE;] -
i )
sum → e[ htt] =
S2→e[jtt] ;
column compared
else

{
if ( s1→ eti] .j a S2 → e

sum → e [ ktt] =
s1→e[ itt ) ;
else if ( S1 → e. Ei] -

j > S2 →
e. [j] j ) -

sum → e[ ktt] =S2→e[ jtt ] ;


else
{
sum → e[ he ] =s1→e[ itt] ;

g
sum → e [ htt ] -
n -1=52 → e [jtt] -
n ;
g
POLYNOMIALREPRESENTATIONI
.

Polynomial Representation pin) =


3ns -12Mt 5n2t2nt7

2 . Evaluation of Polynomial
i::tslu
-

3 .
Addition of two Polynomials 3252€ n = 5

Struct Term Stout Poly


{ E

int coeff ; int n


;
*
int Emp ; struct Term t ;

} }

p
Struct
Poly P ;

of terms ) ;
/
" n

print fl
"

No non -

zero

€11
"
t coeff
Lpn) ;

scarf l
"
Td ,

pit = new Term [ p - n ] ; eup

l
print fl polynomial
" "
Enter terms ;

for li=o ; i
sp -
n ; itt )

{
" "

printfl Term No : Y d .
,
it t );

Lp
" "

scarf ( t d - Id I p -
t [ i] -
coeff , . t [ i ] Emp ) ;
-

EVALUATIONS true Poly P ;

n = 5 ; sum = 0 ;

for ( i=o ; is p -
n ;
itt )

Enp )
*
i]
[i] coeff pow (n p t [
t
sum + p
=
;
-
- -

. ,
POLYNOMIALADDITIONPICN
) =
5u4t2n2 -15 palm )
=
GUY -15ns -19N -
+ 2n -13

p p

A A
n 3
O l 2 3 4 n 5 0 4
I 2 3

coin: #H :*
+ → t - c

i j

while ( is p1 -

n dd jcpz.in )
{
if l PI tci] Emp .
- > pz.tt ;] Enp ) .

p3 t[ htt] p1 t[ itt ] ;
= -
-

if
else lpz.tl's] Emp p1 t[ i] Enp ) > -
-
-

p3 tEkttJ=p2.t[ jtt] ;
-

else

p3 the] Emp =
p1 t [ i) Emp ;
- -
- -

p3
-
t [ htt] -
Coeff =
p1 -
t [ itt ] -

coefftpz.t-jt-D.co eff ;
}
}
P


n 5 o 4
l Z 3

IF
coin:
+ →

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy