Professional Documents
Culture Documents
4,
Qb 89 b
7 _7 2
r
'I-
[uiv
L-1 bV 0b89 Sb' 8 LN d'om
d
t
1 I N
-uuJ [uwv
o-
r UtW
4;
'E b ob 8 S G)
Li 4
wob-1V
•
- ccozl i
1
j.! • flo Jx wUT
wn
1
LOt NO}iT3
£-J.M4fl
41
8t
C
4S 682- 3
2q 34 P1
-
'1'
j
ct 44c
ri.\n 4-a
6 10 2. 34
1'
M- 29
a 4S 6 qo .2.9 3L
-j
'1'
mir
[1 Z9
n- \\ 4J
4/
Sct ks 6 .2 17
r1tj1.
P1 4S b qo 29 34 8C
1
3
,a
mn 4-j
S2 34 4s (8 sct
:EJ Q1QIfl
't3ac oFQioi
rCn)
&)BBL DRT
L
com?o)J
yo riuvo.
A LOR1THKL
-0+0 r- aD
t -a /-
4
ci 45 6 o 2- 34
45 LA
2.039'
fg 68 2. 34 11
6 LP
2J1 34 ti
45_
3
4+bi ciCT)'
17
r
\4; \;
Qb L\'E
89 S47
t.
d
1
0, L 'L.
•71 b8 89 S3'
c7 5&
r
Qb Li c' 6' b8 89 S3
1'
oCfl<
Q1,7 L
\-c:
1-i o1,4 b8 Sb'
-Pr
r
L-J - 01, ?°
89 51
p
LI 9' b
b8
4S 68 2 3 8 zi o
4s 6s 34 t1 8 o
Lu
A ALYSI&
fl.2
1=o jO
øCt -2-
nCh-)
2,
CCn-)
A1t
(
1wfl t
t1 .
-1 OCWC —
— oo QCth o
1 -.
YT) -1
-- 'r—i k -TQii
pJ -. -
¶itn
apxw
k,
t— u3 çtc , &
th35i o ko n -rod
QflX ornt ,
C) J(SL&& 2
r1X3LU1
L
jC)3j k4i.
AORITH.
(0.
0 ri-rn
I T
n-ni
0 2 0 rn-i
I tl%l14Q.131
1! rda)r49 )
Ot g c
to it f2 13
cz tW6 QO.LQ,
a\ mx — mk
r1\)cr
O(tfl?cr
cA eCr)
31L
C sw)
A1v3 k- k
., L.fl ', \,
ikuii A[13 k do
1
I* -i-H- (pti3
Lrt LttW1.L
QQ
Q19q 0
—L
DECREASE AND CONQUER-INSERTION SORT
? SO 2: Implement Insertion sort Algorithm (Ap,C)
Insertion Sort
Sorted
List
Insertion Sort(A,n)
{
for i 🡸 1 to n-1
{
value 🡸 a[i]
hole 🡸 i
while(hole>0 &&
A[hole-1]>value
{
A[hole] 🡸 A[hole-1]
hole 🡸 hole-1
}
A[hole] 🡸 value
}
}
? SO 3: Analyse the time complexity of Insertion
sort (Ap,P)
Time
complexity
? SO 4: Compare Divide and Conquer with
Decrease and Conquer (Ap,P)
BFS AND DFS
BINARY TREE
● Binary tree is a special tree data structure.
● In a binary tree, each node can have at
most 2 children.
TREE TRAVERSAL
❖ Tree Traversal refers to the process of
visiting each node in a tree data structure
exactly once
Depth First Search
DFS TRAVERSAL
DFS of the below graph is 1 2 4 6 3 5 7 8
• Implemented using stack
• Push a vertex onto the stack when the vertex is
reached for the first time
• Pop a vertex off the stack when it becomes a
dead end
Tree Edge
Whenever a new unvisited vertex is reached
for the first time, it is attached as a child
from which it is being reached. Such edge is
called Tree edge
Tree Edge:
It is an edge which is present in the tree
obtained after applying DFS on the graph. All
the Green edges are tree edges.
Forward Edge: It is an edge (u, v) such that v is
descendant but not part of the DFS tree. Edge
from 1 to 8 is a forward edge
Back edge
1 2 3
4
5 e-droppe Remove
6 d b
TIME COMPLEXITY
? Time proportional to the size of the data
structure used for representing the graph
? Adjacency matrix representation: O(|v2|)
? Adjacency linked list representation :
O(|V|+|E|)
TRAVERSAL IN DFS
Following three traversal techniques fall under
Depth First Traversal-
1. Preorder Traversal
2. Inorder Traversal
3. Postorder Traversal
PREORDER TRAVERSAL
1. Visit the root
2. Traverse the left sub tree i.e. call Preorder
(left sub tree)
3. Traverse the right sub tree i.e. call Preorder
(right sub tree)