You are on page 1of 14

Arrays 2D Matrices

Jan 19,2023

AGENDA

2D Arrays Matrices basics


Some interesting problems

Friday so Jan 9p
Y
optionalclass
Subarrays
Repeat
What are 2D Arrays Matrices

away of integers
fhello
G this
is
Mei

arr
1 IT
5
92,112,57
an Co2 i 0,33

an Co Co2 1

an 11122 9

an CIT IT a O
ar OJ IT O
Mat o I 2 3 4 2DArray
0 2 dimensional
I
2
3
um

mat.su
matC2TC
matC3JCo3

0 Mcolumns
jogged
o Co Ma
I
bij
2 2j
a

it p

Nti Q im D
N 1,0 q
Questions

I Given matCNICMI print low wise sum

j
i 15
15
17
f NXM 3 4
Arri 4,3 1,77 6 2 3,47 5,3 2,77

int n mat length I No of rows


int m mat lol length 11No of columns

forcint iso ien itt

I mattis ith row

sum O

sumt matlilli
S.c old

sum
print
Q Given mat NIEM find the cot wise sum

15 8 6 18

first
to'Étiotjing
I
pMfÉo i nite

sumt anfiles
3
3 printesum

Tory Do this que by iterating over


rows
Q Given asquare matrix NCN print the
diagonals diagonal E R leading
anti diagonal trailing
r D

0 I 2 3
o

I
2

3
4 4

Main
go C D Gn did i

And
0,3 1,2 2,1 3,0 in

itis
IF I N 2

E
L
3 N D
J
i matfild
forlinti orieniitt

print mat ill


3 to match
its matrix
Trc 01N in match
i 0,5 0

while in 22
jan
7157
print mate
itt
jet
3

It o j N l

while i N
2257 0

print mat CITED


itj N I itt
j TC
ON
j M

mafijw
mat NIEMI
I Given a print all diagonals
CL R

Gentry
o NXM matrix
260 G 1 I
no
o 2,11 213.2 of
diagonals
ooo CD 2 4,33
CO D 42 633 3 4 11
2 1,3 2,47 43,57 Ntm I
did 4,4 Gs
6,4 4,57
ED
Observations

1 If the start point


of a diagonal is
rest of the elements itt jtt
j

2 Diagonal continues until we hit boundary


in jam

3 Start point of first diagonal N 1,0

q Timotent starts untie i o.io

Moreright jet until izo.fm


Ystart point
I not 3
while ca m

I
while ien 22 jam

IS print matlin D
itt
jet

if r o
Breath
10 53
r
else
cat TL O Inam
3 S.c Old
Q Given a mat N ncalculate transpose of
the matrix with S.c Old

0 I 2 3 4
0
1 6 11 16 21
2 7
2 3 8 13 18
49 in
Ey
3 a
g y

1st row 1stcol

math Co matCold
mat 6393 maths

matti 157 matej Jli

Swap matfixsematGT.li

O
int i 0 ioniitt
for
for int jeo janistt

Ilswap matti j
ÉI
mat Colli
temps matches
Matti 57 matCJTC

É y
matchcin temp

Iid
a
to.int oiianies
Jet

TC O NY forcintisIII
is
i

iz
or
is
1
in Either iterate in lower triangle
or upper triangle
but not both
D Dimensions
change
D

for rectangular
matrix

Interviewquestion

A Given a mat INTENT rotate the matrix clockwise


so
by

JRotated
by
go
Transpose Gcn
0 I 2 3 4
0 11 16 21
1 6

ÉÉ
I 2 7 12 17 22 Reverse
2 3 8 13 18 23

3 4 9 14 19 24
4 5 10 15 20 25

T C O N N2 O 2ND
O NY
How to reverse a row

matitrow
I
Reverse the
away using swapping

x x

Doubts

col sire is
7 same for all
D rows

rt
13H 3 260
prefix

A7
spit

You might also like