Professional Documents
Culture Documents
shortest
-
-
v Graphs 2 1
Bipartite Graphs, Dijkstra, Bellman Ford
-- -
↓
70 -Priyansh Agarwal
5
Dijkstra
Beiman
"
-
-
-
⑧ and
-
&
-
I ↳ O
·
-
⑧ da
Bi-partite Graphs
~
- Definition
- Algorithm
A colorable
-
- Odd Length Cycle -> bi-partitely
not
v
- Tree Property
v
- Problem: Link
-- H.W
-
-
-
Bi artite Graphs: Every 2
adj.
have different
- -
-
nodes
⑧ ↳
②m
↓
③
↓
⑧
I ⑧
-2
R G
*↓to
- Fionnected
graph
9 it
. Given an
3 Y
an
only have
2 possisy colorings
(ti-partites
-
-
-
⑰
-
⑧. ⑪
catal
A aloed in
graph can be a
if
Di-partite
manner
it
does not
ungte cycl
o d
connected have either
A graph can
0 Sipartitecolorings CO
-
2
-
⑧ ⑧
①
-> 8 doo.·
If a
graph contains a
connected components
how many
have
si-partity coloring can you
⑲
·orwaterre
R G
-
Choose a random node and color
↓
↓
-
⑧
·
⑧
vector [int (n, 0);
>
co
W 1 =
tool true
I
ans=
for lint
neighbour:edges/cur)
if (colors (night)
0)
=
=
↳saurian
I
re
else if (Coles (neighbours colon
==
(cur))
return fabe;
retur uns;
y true
0(n)
-
-
book ans=
((o(v(i)
#
=
=
c)
Colors (i) = I
- Proof/Intuition:
~
- On every iteration the marked vertex is the one that can never have
-
- Code
=
a better distance later on.
o
Y
-
n
>0
kon-negative
sa
a
d-
· -b
do-
to
or
50
↑
suc
-
⑧
⑧
-
-I
woodImine
⑩ coming
e
I 582
② the
offic
0
y
La
IED
-
Dijkstra Visualization
dist.
⑳
=.
·
.
+ distin)
weight
.
.
.
.
.
. edge
.
-
-
-
- >
->
-
0 5 1
⑲. N
=
↓
= 2 +
T
100
Dijkstra Visualization dist
I O -
.
-
- -
X atio
·
⑭
5 10
+
->N=
D
weight -> disting
-
4
/
M3),(20,4) Set
↓
-
4
o
-
0
-
vis/3)= true 2 3
-
-
①Given a
weighted undirected connected Graph
-
~find the
out from
shortestpath source
X
Y entralt
to
↳ I Consides all
-
paths
shortest
from
all the
and
find out
W -
-
-
20 10
-- Y
0
6
-
%
R
- dist(X,Y) = 20
o
⑧
10
10
X y
E
10
12
0(n)
-
⑧ =>
20
A
- -
⑧ ->
to - t
-
X
-
E Y
dist(A, B) 15
=
↓ -
-
->>.
⑰
e
⑬
& is/y,B3 15
dist (A, us
=
t
-
-
-
dest(A,B)
- =
dijkstra from A
① I
↳
-
-
% -
-
!
-
-
--
-
dist -
->
> >
>
> =
=>
>
Mot -- d
I10
l
↑
OC
is
&
5/10 B
A
0-00
Lo
7
22
23
5
=
from A
⑪ Run dijkstra
from
⑧
a
Run dijtestry
distA(n)
if distal
remove is
from the goupy
from A
③ Rud &inal dijkstra
- --
- -
-
Bellman Ford
- Single Source Shortest Path Algorithm - Idea + Intuition
- Negative edge weights (in directed) without negative cycles
- Proof/Intuition:
- Principle of Mathematical Induction
- Code
- Breaking Early
- Retrieving the shortest path?
- Finding a negative cycle
Bellman Ford Visualization