SlideShare a Scribd company logo
INTRODUCTION TO GRAPHS
Partha P Chakrabarti
Indian Institute of Technology Kharagpur
Graphs
A Graph G = (V, E) consists of the
following:
• A set of Vertices or Nodes V
– Nodes may have one or more labels
• A set of Edges E where each edge
connects vertices of V
– An edge usually defines a connection or
relationship between vertices or nodes
– The edges can be undirected or directed
– Each edge can have one or more labels
– Usually there is at most one edge between
vertices, there could be multiple edges
between the same nodes.
– Normally an edge connects two vertices, but
in general we could have hyper-edges
Graphs
A Graph G = (V, E) consists of the
following:
• A set of Vertices or Nodes V
– Nodes may have one or more labels
• A set of Edges E where each edge
connects vertices of V
– An edge usually defines a connection or
relationship between vertices or nodes
– The edges can be undirected or directed
– Each edge can have one or more labels
– Usually there is at most one edge between
vertices, there could be multiple edges
between the same nodes.
– Normally an edge connects two vertices, but
in general we could have hyper-edges
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Some Applications of Graphs
• Maps, Routes
• Layouts
• Circuits and Networks
• Relationships
• Constraints
• Dependencies
• Flow Charts
• State Machines
Graph Representation
Adjacency Matrix
Adjacency List
Graph Representation
Adjacency Matrix
Adjacency List
Some Algorithms on Graphs
• Paths
• Reachability
• Connected
Components
• Trees, Cycles,
ordering
• Costs & Distances
• Spanning Trees
• Shortest Paths
• Flows
Some Algorithms on Graphs
• Paths
• Reachability
• Trees, Cycles,
ordering
• Connected
Components
• Costs & Distances
• Spanning Trees
• Shortest Paths
• Flows
Some Algorithms on Graphs
• Paths
• Reachability
• Cycles, ordering
• Connected
Components
• Costs & Distances
• Spanning Trees
• Shortest Paths
• Flows
Some Algorithms on Graphs
• Paths
• Reachability
• Cycles, ordering
• Connected
Components
• Costs & Distances
• Spanning Trees
• Shortest Paths
• Flows
Some Algorithms on Graphs
• Paths
• Reachability
• Cycles, ordering
• Connected
Components
• Costs & Distances
• Spanning Trees
• Shortest Paths
• Flows
Thank you
TRAVERSAL OF UNDIRECTED GRAPHS
Partha P Chakrabarti
Indian Institute of Technology Kharagpur
Undirected Graph
An Undirected Graph G = (V, E) consists of
the following:
• A set of Vertices or Nodes V
• A set of Edges E where each edge
connects two vertices of V
Example: Figure 1
V = {0,1,2,3,4,5,6,7,8}
E = {(0,1), (0,8), (0,3),(1,7), (2,3), (2,5), (2,7),
(3,4), (4,8), (5,6)}
Successor Function: succ(i) = {set of nodes
to which node i is connected}
Example: Succ(2) = {3,5,7}
Weighted Undirected Graphs: Such Graphs
may have weights on edges (Figure 2)
Figure 1
Figure 2
Problems on Undirected Graphs
Reachability, Path, Cycle / Tree Detection,
Connected Components, Bi-Connected
Components, Spanning Tree, Shortest
Path, Maximum Flow, Vertex Cover, Edge
Cover, Travelling Salesperson,
Figure 1
Figure 2
Basic Traversal Algorithm (Depth First Search) I
Global Data: G = (V,E)
visited [i] indicates if node i is visited. For
all nodes j visited [j] is initialized to 0
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) Dfs(j)
}
}
Basic Traversal Algorithm (Depth First Search) II
Global Data: G = (V,E)
visited [i] indicates if node i is visited. For
all nodes j visited [j] is initialized to 0
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) Dfs(j)
}
}
Basic Traversal Algorithm (Depth First Search) III
Global Data: G = (V,E)
visited [i] indicates if node i is visited. For
all nodes j visited [j] is initialized to 0
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) Dfs(j)
}
}
Cycle Detection
Global Data: G = (V,E)
visited [i] indicates if node i is visited. For all
nodes j visited [j] is initialized to 0
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) Dfs(j)
}
}
// Cycle Detection //
Path Finding
Global Data: G = (V,E)
visited [i] indicates if node i is visited. For all nodes
j visited [j] is initialized to 0
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) {
Dfs(j) }
}
}
// Tree Edge, Back Edge, Parent Links, Tracing
Paths //
Connected Components
Global Data: G = (V,E)
Visited[i], comp[i] all initialized to 0
count = 0;
Algorithm components() {
for each node k do {
if visited [k] == 0 { count = count + 1;
DfComp_S(k) }
DfComp(node) {
visited[node] = 1; comp[node] = count;
for each j in succ(node) do {
if (visited [j] ==0) DfComp(j)
}
}
Depth-First Numbering & Time Stamping
Global Data: G = (V,E)
Visited[i], comp[i] all initialized to 0
count = 0;
Algorithm components() {
for each node k do {
if visited [k] == 0 { count = count + 1;
DfComp_S(k) }
DfComp(node) {
visited[node] = 1; comp[node] = count;
for each j in succ(node) do {
if (visited [j] ==0) {
DfComp(j)
}
}
}
Breadth-First Search
Global Data: G = (V,E)
Visited[i] all initialized to 0
Queue Q initially {}
BFS(k) {
visited [k] = 1; Q = {k};
While Q != {} {
j = DeQueue (Q);
if visited[j] == 0 {
visited [j] = 1;
For each k in succ (j) EnQueue(Q,k);
}
}
/Parent links, Shortest Length Path Finding in
unweighted graphs/
Pathfinding in Weighted Undirected Graphs I
Global Data: G = (V,E)
Visited[i] all initialized to 0,
Cost[j] all initialized to INFINITY
Ordered Queue Q initially {}
BFSW(k) {
visited [k] = 1; cost [k] = 0; Q = {k};
While Q != {} {
j = DeQueue (Q);
if visited[j] == 0 {
visited [j] = 1;
For each k in succ (j) {
if cost[k] > cost[j] + c[j,k]
cost[k] = cost[j] + c[j,k];
EnQueue(Q,k);}
}
}
Pathfinding in Weighted Undirected Graphs II
Global Data: G = (V,E)
Visited[i] all initialized to 0,
Cost[j] all initialized to INFINITY
Ordered Queue Q initially {}
BFSW(k) {
visited [k] = 1; cost [k] = 0; Q = {k};
While Q != {} {
j = DeQueue (Q);
if visited[j] == 0 {
visited [j] = 1;
For each k in succ (j) {
if cost[k] > cost[j] + c[j,k]
cost[k] = cost[j] + c[j,k];
EnQueue(Q,k);}
}
}
Thank you
TRAVERSAL OF DIRECTED GRAPHS
Partha P Chakrabarti
Indian Institute of Technology Kharagpur
Directed Graphs
An Undirected Graph G = (V, E) consists of
the following:
• A set of Vertices or Nodes V
• A set of DIRECTED Edges E where each
edge connects two vertices of V. The
edge is an ORDERED pair of vertices
Successor Function: succ(i) = {set of nodes
to which node i is connected}
Directed Acyclic Graphs (DAGs): Such
Graphs have no cycles (Figure 2)
Weighted Undirected Graphs: Such Graphs
may have weights on edges (Figure 3). We
can also have Weighted DAGs
Figure 1
Figure 3
Figure 2
Basic Traversal Algorithm (Depth First Search)
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
}
}
Traversing the Complete Graph by DFS
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
succ(i) = {set of nodes to which node i is
connected}
Dfs(node) {
visited[node] = 1;
for each j in succ(node) do {
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
}
}
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
Entry[i] = node entry sequence / initially 0 /
Exit[i] = node exit sequence / initially 0 /
succ(i) = {set of nodes to which node i is connected}
numb = 0;
Dfs(node) {
visited[node] = 1; numb = numb+1;
Entry[node] = numb;
for each j in succ(node) do
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
numb = numb + 1;
Exit[node] = numb;
}
Entry-Exit Numbering
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially NULL
/
Entry[i] = node entry sequence / initially 0 /
Exit[i] = node exit sequence / initially 0 /
succ(i) = {set of nodes to which node i is connected}
numb = 0;
Dfs(node) {
visited[node] = 1; numb = numb+1;
Entry[node] = numb;
for each j in succ(node) do
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
numb = numb + 1;
Exit[node] = numb;
}
Tree Edge, Back Edge, Forward Edge, Cross Edge
Edge (u,v) is
Tree Edge or Forward Edge: if & only if
Entry[u] < Entry[v] < Exit[v] < Exit[u]
Back Edge: if & only if
Entry[v] < Entry [u] < Exit [u] < Exit [v]
Cross Edge: if & only if
Entry [v] < Exit [v] < Entry [u] < Exit [u]
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
Entry[i] = node entry sequence / initially 0 /
Exit[i] = node exit sequence / initially 0 /
succ(i) = {set of nodes to which node i is connected}
numb = 0;
Dfs(node) {
visited[node] = 1; numb = numb+1;
Entry[node] = numb;
for each j in succ(node) do
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
numb = numb + 1;
Exit[node] = numb;
}
Reachability, Paths, Cycles, Components
Edge (u,v) is
Tree Edge or Forward Edge: if & only if
Entry[u] < Entry[v] < Exit[v] < Exit[u]
Back Edge: if & only if
Entry[v] < Entry [u] < Exit [u] < Exit [v]
Cross Edge: if & only if
Entry [v] < Exit [v] < Entry [u] < Exit [u]
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
Entry[i] = node entry sequence / initially 0 /
Exit[i] = node exit sequence / initially 0 /
succ(i) = {set of nodes to which node i is connected}
numb = 0;
Dfs(node) {
visited[node] = 1; numb = numb+1;
Entry[node] = numb;
for each j in succ(node) do
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
numb = numb + 1;
Exit[node] = numb;
}
Directed Acyclic Graphs
Global Data: G = (V,E)
visited [i] indicates if node i is visited. / initially 0 /
Parent[i] = parent of a node in the Search / initially
NULL /
Entry[i] = node entry sequence / initially 0 /
Exit[i] = node exit sequence / initially 0 /
succ(i) = {set of nodes to which node i is connected}
numb = 0; numb1 = 0;
Dfs(node) {
visited[node] = 1; numb = numb+1;
Entry[node] = numb;
for each j in succ(node) do
if (visited [j] ==0) { Parent[j] = node;
Dfs(j) }
numb1 = numb1 + 1;
Exit[node] = numb1;
}
Topological Ordering, Level Values
Shortest Cost Path in Weighted DAGs
Breadth-First Search
Global Data: G = (V,E)
Visited[i] all initialized to 0
Queue Q initially {}
BFS(k) {
visited [k] = 0; Q = {k};
While Q != {} {
j = DeQueue (Q);
if visited[j] == 0 {
visited [j] = 1;
For each k in succ (j) {
if (visited[k]==0) EnQueue(Q,k); }
}
}
/Parent links, Shortest Length Path Finding in
unweighted directed graphs/
Pathfinding in Weighted Directed Graphs
Global Data: G = (V,E)
Visited[i] all initialized to 0,
Cost[j] all initialized to INFINITY
Ordered Queue Q initially {}
BFSW(k) {
visited [k] = 0; cost [k] = 0; Q = {k};
While Q != {} {
j = DeQueue (Q);
if visited[j] == 0 {
visited [j] = 1;
For each k in succ (j) {
if cost[k] > cost[j] + c[j,k]
cost[k] = cost[j] + c[j,k];
EnQueue(Q,k);}
}
}
Thank you

More Related Content

Similar to FADML 06 PPC Graphs and Traversals.pdf

Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
SigSegVSquad
 
Graph
GraphGraph
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
Edhole.com
 
lecture 17
lecture 17lecture 17
lecture 17
sajinsc
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
Joe OntheRocks
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
SVijaylakshmi
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
SVijaylakshmi
 
Lecture set 5
Lecture set 5Lecture set 5
Lecture set 5
Gopi Saiteja
 
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam LermaGraph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
PyData
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
Graph
GraphGraph
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7
Traian Rebedea
 
Graphs
GraphsGraphs
Distributed computation and reconfiguration in actively dynamic networks
Distributed computation and reconfiguration in actively dynamic networksDistributed computation and reconfiguration in actively dynamic networks
Distributed computation and reconfiguration in actively dynamic networks
Peter Kos
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
Damien Seguy
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
Tribhuvan University
 
lecture 18
lecture 18lecture 18
lecture 18
sajinsc
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
Graph
GraphGraph

Similar to FADML 06 PPC Graphs and Traversals.pdf (20)

Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
Graph
GraphGraph
Graph
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
 
lecture 17
lecture 17lecture 17
lecture 17
 
Social network-analysis-in-python
Social network-analysis-in-pythonSocial network-analysis-in-python
Social network-analysis-in-python
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Lecture set 5
Lecture set 5Lecture set 5
Lecture set 5
 
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam LermaGraph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Graph
GraphGraph
Graph
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7
 
Graphs
GraphsGraphs
Graphs
 
Distributed computation and reconfiguration in actively dynamic networks
Distributed computation and reconfiguration in actively dynamic networksDistributed computation and reconfiguration in actively dynamic networks
Distributed computation and reconfiguration in actively dynamic networks
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
lecture 18
lecture 18lecture 18
lecture 18
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Graph
GraphGraph
Graph
 

Recently uploaded

一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
mzpolocfi
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
dwreak4tg
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 

Recently uploaded (20)

一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 

FADML 06 PPC Graphs and Traversals.pdf

  • 1. INTRODUCTION TO GRAPHS Partha P Chakrabarti Indian Institute of Technology Kharagpur
  • 2. Graphs A Graph G = (V, E) consists of the following: • A set of Vertices or Nodes V – Nodes may have one or more labels • A set of Edges E where each edge connects vertices of V – An edge usually defines a connection or relationship between vertices or nodes – The edges can be undirected or directed – Each edge can have one or more labels – Usually there is at most one edge between vertices, there could be multiple edges between the same nodes. – Normally an edge connects two vertices, but in general we could have hyper-edges
  • 3. Graphs A Graph G = (V, E) consists of the following: • A set of Vertices or Nodes V – Nodes may have one or more labels • A set of Edges E where each edge connects vertices of V – An edge usually defines a connection or relationship between vertices or nodes – The edges can be undirected or directed – Each edge can have one or more labels – Usually there is at most one edge between vertices, there could be multiple edges between the same nodes. – Normally an edge connects two vertices, but in general we could have hyper-edges
  • 4. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 5. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 6. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 7. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 8. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 9. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 10. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 11. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 12. Some Applications of Graphs • Maps, Routes • Layouts • Circuits and Networks • Relationships • Constraints • Dependencies • Flow Charts • State Machines
  • 15. Some Algorithms on Graphs • Paths • Reachability • Connected Components • Trees, Cycles, ordering • Costs & Distances • Spanning Trees • Shortest Paths • Flows
  • 16. Some Algorithms on Graphs • Paths • Reachability • Trees, Cycles, ordering • Connected Components • Costs & Distances • Spanning Trees • Shortest Paths • Flows
  • 17. Some Algorithms on Graphs • Paths • Reachability • Cycles, ordering • Connected Components • Costs & Distances • Spanning Trees • Shortest Paths • Flows
  • 18. Some Algorithms on Graphs • Paths • Reachability • Cycles, ordering • Connected Components • Costs & Distances • Spanning Trees • Shortest Paths • Flows
  • 19. Some Algorithms on Graphs • Paths • Reachability • Cycles, ordering • Connected Components • Costs & Distances • Spanning Trees • Shortest Paths • Flows
  • 21. TRAVERSAL OF UNDIRECTED GRAPHS Partha P Chakrabarti Indian Institute of Technology Kharagpur
  • 22. Undirected Graph An Undirected Graph G = (V, E) consists of the following: • A set of Vertices or Nodes V • A set of Edges E where each edge connects two vertices of V Example: Figure 1 V = {0,1,2,3,4,5,6,7,8} E = {(0,1), (0,8), (0,3),(1,7), (2,3), (2,5), (2,7), (3,4), (4,8), (5,6)} Successor Function: succ(i) = {set of nodes to which node i is connected} Example: Succ(2) = {3,5,7} Weighted Undirected Graphs: Such Graphs may have weights on edges (Figure 2) Figure 1 Figure 2
  • 23. Problems on Undirected Graphs Reachability, Path, Cycle / Tree Detection, Connected Components, Bi-Connected Components, Spanning Tree, Shortest Path, Maximum Flow, Vertex Cover, Edge Cover, Travelling Salesperson, Figure 1 Figure 2
  • 24. Basic Traversal Algorithm (Depth First Search) I Global Data: G = (V,E) visited [i] indicates if node i is visited. For all nodes j visited [j] is initialized to 0 succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) Dfs(j) } }
  • 25. Basic Traversal Algorithm (Depth First Search) II Global Data: G = (V,E) visited [i] indicates if node i is visited. For all nodes j visited [j] is initialized to 0 succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) Dfs(j) } }
  • 26. Basic Traversal Algorithm (Depth First Search) III Global Data: G = (V,E) visited [i] indicates if node i is visited. For all nodes j visited [j] is initialized to 0 succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) Dfs(j) } }
  • 27. Cycle Detection Global Data: G = (V,E) visited [i] indicates if node i is visited. For all nodes j visited [j] is initialized to 0 succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) Dfs(j) } } // Cycle Detection //
  • 28. Path Finding Global Data: G = (V,E) visited [i] indicates if node i is visited. For all nodes j visited [j] is initialized to 0 succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) { Dfs(j) } } } // Tree Edge, Back Edge, Parent Links, Tracing Paths //
  • 29. Connected Components Global Data: G = (V,E) Visited[i], comp[i] all initialized to 0 count = 0; Algorithm components() { for each node k do { if visited [k] == 0 { count = count + 1; DfComp_S(k) } DfComp(node) { visited[node] = 1; comp[node] = count; for each j in succ(node) do { if (visited [j] ==0) DfComp(j) } }
  • 30. Depth-First Numbering & Time Stamping Global Data: G = (V,E) Visited[i], comp[i] all initialized to 0 count = 0; Algorithm components() { for each node k do { if visited [k] == 0 { count = count + 1; DfComp_S(k) } DfComp(node) { visited[node] = 1; comp[node] = count; for each j in succ(node) do { if (visited [j] ==0) { DfComp(j) } } }
  • 31. Breadth-First Search Global Data: G = (V,E) Visited[i] all initialized to 0 Queue Q initially {} BFS(k) { visited [k] = 1; Q = {k}; While Q != {} { j = DeQueue (Q); if visited[j] == 0 { visited [j] = 1; For each k in succ (j) EnQueue(Q,k); } } /Parent links, Shortest Length Path Finding in unweighted graphs/
  • 32. Pathfinding in Weighted Undirected Graphs I Global Data: G = (V,E) Visited[i] all initialized to 0, Cost[j] all initialized to INFINITY Ordered Queue Q initially {} BFSW(k) { visited [k] = 1; cost [k] = 0; Q = {k}; While Q != {} { j = DeQueue (Q); if visited[j] == 0 { visited [j] = 1; For each k in succ (j) { if cost[k] > cost[j] + c[j,k] cost[k] = cost[j] + c[j,k]; EnQueue(Q,k);} } }
  • 33. Pathfinding in Weighted Undirected Graphs II Global Data: G = (V,E) Visited[i] all initialized to 0, Cost[j] all initialized to INFINITY Ordered Queue Q initially {} BFSW(k) { visited [k] = 1; cost [k] = 0; Q = {k}; While Q != {} { j = DeQueue (Q); if visited[j] == 0 { visited [j] = 1; For each k in succ (j) { if cost[k] > cost[j] + c[j,k] cost[k] = cost[j] + c[j,k]; EnQueue(Q,k);} } }
  • 35. TRAVERSAL OF DIRECTED GRAPHS Partha P Chakrabarti Indian Institute of Technology Kharagpur
  • 36. Directed Graphs An Undirected Graph G = (V, E) consists of the following: • A set of Vertices or Nodes V • A set of DIRECTED Edges E where each edge connects two vertices of V. The edge is an ORDERED pair of vertices Successor Function: succ(i) = {set of nodes to which node i is connected} Directed Acyclic Graphs (DAGs): Such Graphs have no cycles (Figure 2) Weighted Undirected Graphs: Such Graphs may have weights on edges (Figure 3). We can also have Weighted DAGs Figure 1 Figure 3 Figure 2
  • 37. Basic Traversal Algorithm (Depth First Search) Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) { Parent[j] = node; Dfs(j) } } }
  • 38. Traversing the Complete Graph by DFS Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / succ(i) = {set of nodes to which node i is connected} Dfs(node) { visited[node] = 1; for each j in succ(node) do { if (visited [j] ==0) { Parent[j] = node; Dfs(j) } } }
  • 39. Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / Entry[i] = node entry sequence / initially 0 / Exit[i] = node exit sequence / initially 0 / succ(i) = {set of nodes to which node i is connected} numb = 0; Dfs(node) { visited[node] = 1; numb = numb+1; Entry[node] = numb; for each j in succ(node) do if (visited [j] ==0) { Parent[j] = node; Dfs(j) } numb = numb + 1; Exit[node] = numb; } Entry-Exit Numbering
  • 40. Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / Entry[i] = node entry sequence / initially 0 / Exit[i] = node exit sequence / initially 0 / succ(i) = {set of nodes to which node i is connected} numb = 0; Dfs(node) { visited[node] = 1; numb = numb+1; Entry[node] = numb; for each j in succ(node) do if (visited [j] ==0) { Parent[j] = node; Dfs(j) } numb = numb + 1; Exit[node] = numb; } Tree Edge, Back Edge, Forward Edge, Cross Edge Edge (u,v) is Tree Edge or Forward Edge: if & only if Entry[u] < Entry[v] < Exit[v] < Exit[u] Back Edge: if & only if Entry[v] < Entry [u] < Exit [u] < Exit [v] Cross Edge: if & only if Entry [v] < Exit [v] < Entry [u] < Exit [u]
  • 41. Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / Entry[i] = node entry sequence / initially 0 / Exit[i] = node exit sequence / initially 0 / succ(i) = {set of nodes to which node i is connected} numb = 0; Dfs(node) { visited[node] = 1; numb = numb+1; Entry[node] = numb; for each j in succ(node) do if (visited [j] ==0) { Parent[j] = node; Dfs(j) } numb = numb + 1; Exit[node] = numb; } Reachability, Paths, Cycles, Components Edge (u,v) is Tree Edge or Forward Edge: if & only if Entry[u] < Entry[v] < Exit[v] < Exit[u] Back Edge: if & only if Entry[v] < Entry [u] < Exit [u] < Exit [v] Cross Edge: if & only if Entry [v] < Exit [v] < Entry [u] < Exit [u]
  • 42. Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / Entry[i] = node entry sequence / initially 0 / Exit[i] = node exit sequence / initially 0 / succ(i) = {set of nodes to which node i is connected} numb = 0; Dfs(node) { visited[node] = 1; numb = numb+1; Entry[node] = numb; for each j in succ(node) do if (visited [j] ==0) { Parent[j] = node; Dfs(j) } numb = numb + 1; Exit[node] = numb; } Directed Acyclic Graphs
  • 43. Global Data: G = (V,E) visited [i] indicates if node i is visited. / initially 0 / Parent[i] = parent of a node in the Search / initially NULL / Entry[i] = node entry sequence / initially 0 / Exit[i] = node exit sequence / initially 0 / succ(i) = {set of nodes to which node i is connected} numb = 0; numb1 = 0; Dfs(node) { visited[node] = 1; numb = numb+1; Entry[node] = numb; for each j in succ(node) do if (visited [j] ==0) { Parent[j] = node; Dfs(j) } numb1 = numb1 + 1; Exit[node] = numb1; } Topological Ordering, Level Values
  • 44. Shortest Cost Path in Weighted DAGs
  • 45. Breadth-First Search Global Data: G = (V,E) Visited[i] all initialized to 0 Queue Q initially {} BFS(k) { visited [k] = 0; Q = {k}; While Q != {} { j = DeQueue (Q); if visited[j] == 0 { visited [j] = 1; For each k in succ (j) { if (visited[k]==0) EnQueue(Q,k); } } } /Parent links, Shortest Length Path Finding in unweighted directed graphs/
  • 46. Pathfinding in Weighted Directed Graphs Global Data: G = (V,E) Visited[i] all initialized to 0, Cost[j] all initialized to INFINITY Ordered Queue Q initially {} BFSW(k) { visited [k] = 0; cost [k] = 0; Q = {k}; While Q != {} { j = DeQueue (Q); if visited[j] == 0 { visited [j] = 1; For each k in succ (j) { if cost[k] > cost[j] + c[j,k] cost[k] = cost[j] + c[j,k]; EnQueue(Q,k);} } }