SlideShare una empresa de Scribd logo
1 de 40
Graphs
Steve Paks
Index
•
•
•
•
•

The Graph Abstract Data Type
Elementary Graph Operations
Minimum Cost Spanning Trees
Shortest Paths and Transitive Closure
Activity Networks
Curriculum Model

A

A

A

A

A

CS

Here I am
A

A

A

CS
A
Java Language Base

CS : Computer
Science
A : Application
The Graph Abstract Data Type
• Introduction
–
–
–
–
–

Analysis of electrical circuits
finding shortest routes
project planning
identification of chemical compounds
all mathematical structures
The Graph Abstract Data
Type(Cont’d)
• Definitions
– A graph consists of
• nonempty set of vertices
• empty set of edges

– G = (V, E)
– undirected graph
• (v0, v1) and (v1, v0) represent the same edge

– directed graph
• <v0, v1> represents an edge in which v0 is the tail and v1 is the head
The Graph Abstract Data
Type(Cont’d)
• Definitions(Cont’d)
– Restriction on Graphs
• A graph may not have self loops
• A graph may not have multiple occurrences of the same edge

– A complete graph
• having the maximum number of edges
• undirected graph = n(n-1)/2
• directed graph = n(n-1)

– Adjacent
• Ex) in Graph G2 – vertices 3, 4 and 0 are adjacent to vertex 1

– incident on
• Ex) in Graph G2 – edges (0, 2), (2, 5) and (2, 6) are incident on vertex 2

– directed edge<v0, v1>
• Adjacent – v0 is adjacent to v1, v1 is adjacent from v0
• incident on - <v0, v1> in incident on v0 and v1
• Ex) in Graph G3 – edges<0, 1>, <1, 0> and <1, 2> are incident on vertex 1
The Graph Abstract Data
Type(Cont’d)
• Definitions(Cont’d)
– Subgraphs
• A subgraph of G is a graph G` such that V(G`) ⊆ V(G)
• Ex) Subgraphs of G1

– the length of path
• the number of edges on a path

– simple path
• a path in which all vertices, except the first and the last, are distinct
• Ex) (0, 1), (1, 3), (3, 2) can be written as 0, 1, 3, 2 in graph G1
0, 1, 3, 2 is a simple path, while 0, 1, 3, 1 is not.

– Cycle
• a simple path in which the first and the last vertices are the same
• Ex) in Graph G1 0, 1, 2, 0 is a cycle
The Graph Abstract Data
Type(Cont’d)
• Definitions(Cont’d)
– Connected
• in an undirected graph G, two vertices, v0 and v1, are connected
• in the case of v0 and v1 has a path
• Ex) graph G1 and G2 are connected, while graph G4 is not

– Connected component
• Graph G4 has two components, H1, H2

– Strongly connected
• for a directed graph
The Graph Abstract Data
Type(Cont’d)
The Graph Abstract Data
Type(Cont’d)
• Definitions(Cont’d)
– ADT Graph
The Graph Abstract Data
Type(Cont’d)
The Graph Abstract Data
Type(Cont’d)
• Graph Representation(Cont’d)
– Adjacent Lists
• node structure
Class Node{
int vertex;
Node link;
}
• the starting point of the list for vertex i
– node[i]

• the number of nodes in its adjacency list
– the degree of any vertex in an undirected graph
– the number of edges incident on the vertex
– the out-degree of any vertex in an directed graph

• inverse adjacency list
– the in-degree of a vertex
– all vertices adjacent to a vertex
The Graph Abstract Data
Type(Cont’d)
• Graph Representation(Cont’d)
– Adjacent Lists(Cont’d)
• Changing node structure
– The problem of finding in-degree

Class Node{
int tail;
int head
Node columnLinkForHead;
Node rowLinkForTail;
}
The Graph Abstract Data
Type(Cont’d)
• Graph Representation(Cont’d)
– Adjacent Multilists
The Graph Abstract Data
Type(Cont’d)
• Graph Representation(Cont’d)
– Weighted Edges
• weights may represent
– the distance or the cost

• network
– a graph with weighted edges
Elementary Graph Operations
•

Depth First Search
– similar to a preorder tree traversal
– using a stack
– Process
•
•
•
•
•
•
•
•
•

visit the start vertex v
select an unvisited vertex, w, from v’s adjacency list
v is placed on a stack
reaches a vertex, u, that has no visited vertices on v’s adjacency list
remove a vertex from the stack
processing its adjacency list
previously visited vertices are discarded
unvisited vertices are visited and placed on the stack
terminates the stack is empty

v0v1v3v7v4v5v2v6
void dfs(int v){
visited[v] = true;
System.out.println(v);
for(Node w = graph[v] ; w != null ; w = w.link){
if(!visited[w.vertex])
dfs(w.vertex);
time complexity
}
adjacency list = O(e)
}
adjacency matrix = O(n2)
Elementary Graph
Operations(Cont’d)
• Breath First Search
– resembles a level order traversal
– using a queue
– Process
•
•
•
•
•
•
•
•

visit the vertex v and marks it
visit all of the first vertex on v’s adjacency list
each vertex is placed to queue
all of vertices on v’s adjacency list are visited
remove a vertex from the queue
examine the vertex again that is removed from the queue
visited vertices are ignored
the search is finished when the queue is empty
Elementary Graph
Operations(Cont’d)
• Breath First Search(Cont’d)
class Queue{
int vertex;
Queue link;
}
void bfs(int v){
Queue front = null, rear=null;
System.out.println(v);
visited[v] = true;
addq(front, rear, v);
while(front != null){
v = deleteq(front);
v0v1v2v3v4v5v6v7
for(Node w = graph[v] ; w != null ; w = w.link){
if(!visited[w.vertex]){
System.out.println(w.vertex);
addq(front, rear, w.vertex);
visited[w] = true;
}
}
Time complexity
}
adjacency list = O(e)
}
adjacency matrix = O(n2)
Elementary Graph
Operations(Cont’d)
• Connected Component
– determining whether or not an undirected graph is connected
– calling either dfs(0) or bfs(0)
– it determined as an unconnected graph
•
•

we can list up the connected components of a graph
repeated calls to either dfs(v) or bfs(v) whee v is unvisited vertex

void connected(){
for(int i = 0 ; i < n ; i ++){
if(!visited[i]){
dfs(i);
System.out.println();
}
}
}
Time complexity
adjacency list = O(n+e), (dfs takes O(e), for loop takes O(n))
adjacency matrix = O(n2)
Elementary Graph
Operations(Cont’d)
• Spanning Tree
– The search implicitly partitions the edges in G into two sets
•
•

tree edges
nontree edges

– tree edges
•

set of traversed edges

– nontree edges
•

set of remaining edges

– forming a tree
•
•

if clause of either dfs or bfs
it inserts the edge(v, w)

– a spanning tree is any tree
•
•

consists solely of edges in G
includes all the vertices in G

– a dfs and bfs spanning tree
Elementary Graph
Operations(Cont’d)
• Spanning Tree(Cont’d)
– add a nontree edge(v, w)
•
•
•

generating a cycle
used for obtaining an independent set of circuit equations for an electrical network
Ex) adding the nontree edge (7, 6)  7, 6, 2, 5, 7

– minimal subgraph
•
•
•
•

a spanning tree is a minimal subgraph of graph G
any connected graph with n vertices must have at least n-1 edges
all connected graph with n-1 edges are trees
a spanning tree has n-1 edges

– assign weights to the edges
•
•

the cost of constructing the communication links or the length of the links
minimum cost spanning trees
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points
– Articulation Point
•
•

a vertex to produce two connected components
the articulation points 1, 3, 4, and 7 on the right images

– Biconnected Graph
•

a connected graph that has no articulation points

– loss of communication
•

an articulation point fails results a loss of communication

– biconnected components
•

having no more than one vertex in common
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points(Cont’d)
– finding the biconnected components
•

use any depth first spanning tree

– depth first number
•

the sequence of visiting the vertices

– back edge
•
•
•

a nontree edge (u, v)
either u is an ancestor of v or v is an ancestor of u
all nontree edges are back edges

dfs

redrawn
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points(Cont’d)
– finding an articulation point
•
•

the root of the spanning tree and has two or more children
not the root and u has a child w such that low(w) ≥ dfn(u)

low(u) = min{ dfn(u), min{low(w) | w is a child of u}, min{ dfn(w), (u, w) is a back edge} }
void dfnlow(int u, int v){
dfn[u] = low[u] = num++;
for( Node ptr = graph[u] ; ptr != null ; ptr = ptr.link ){
w = ptr.vertex;
if(dfn[w] < 0){
dfnlow(w, u);
low[u] = min(low[w], low[u]);
} else if(w != v){
low[u] = min(low[u], dfn[w]);
}
}
}
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points(Cont’d)
– an articulation point(Cont’d)
low(3) = min{ dfn(3) = 0, min{low(4) = 0}, min{ dfn(1) = 3} } = 0
low(4) = min{ dfn(4) = 1, min{low(2) = 0} } = 0
low(2) = min{ dfn(2) = 2, min{low(1) = 0} } = 0
low(1) = min{ dfn(1) = 3, min{low(0) = 4}, min{ dfn(3) = 0} } = 0
low(0) = min{ dfn(0) = 4 } = 4
low(5) = min{ dfn(5) = 5, min{low(6) = 5}, min{ dfn(7) = 7} } = 5
low(6) = min{ dfn(6) = 6, min{low(7) = 5} } = 5
low(7) = min{ dfn(7) = 7, min{low(8) = 9}, min{ dfn(5) = 5} } = 5
low(8) = min{ dfn(8) = 9 } = 9
low(9) = min{ dfn(9) = 8 } = 8
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points(Cont’d)
– biconnected components of a graph
void bicon(int u, int v){
dfn[u] = low[u] = num++;
for( Node ptr = graph[u] ; ptr != null ; ptr = ptr.link ){
int w = ptr.vertex;
if(v != w && dfn[w] < dfn[u]){
push(top, u, w);
if(dfn[w] < 0){
bicon(w, u);
low[u] = min(low[u], low[w]);
if(low[w] >= dfn[u]){
System.out.println(“New biconnected component:”);
int x, y;
do{
pop(top, x, y);
System.out.println(“<“ + x + “, “ + y + “>”);
}while(!((x == u) && (y == w)));
System.out.println();
}
} else if(w != u) low[u] = min(low[u], dfn[w]);
}
}
}
Elementary Graph
Operations(Cont’d)
• Biconnected Components and Articulation Points(Cont’d)
– biconnected components of a graph(Cont’d)
0

1

1

0

2

2

4

1

3

4

1

4

3

2

5

3

6

6

5

7

7

6

9

8

7

9

7

3

5

bicon(3, -1)

7

8

5
Minimum Cost Spanning Trees
•

the cost of a spanning tree
– the sum of the costs(weights)

• greedy method
–
–
–
–

an optimal solution
for a wide variety of programming problems
based on either a least cost or a highest profit criterion
the constraints specified by the problem

• constraints of MCST
– must use only edges within the graph
– must use exactly n-1 edges
– may not use edges that would produce a cycle
Minimum Cost Spanning
Trees(Cont’d)
•

Kruscal’s Algorithm
– Algorithm
•
•
•

selecting the edges in nondecreasing order of their cost
a selected edge does not make a cycle
n-1 edges will be selected for inclusion in T

– forming a forest at each stage of algorithm
– a formal description of Kruscal’s algorithm
T = {};
while( T contains less than n-1 edges && E is not empty){
choose a least cost edge (v, w) from E;
delete (v, w) from E;
if((v, w) does not create a cycle in T){
add (v, w) to T;
} else {
discard(v, w);
}
}
if( T contains fewer than n-1 edges){
print(“No spanning tree”);
}
Minimum Cost Spanning
Trees(Cont’d)
•

Kruscal’s Algorithm(Cont’d)
– a cycle problem
•
•

•

using the union-find operations
adding an edge (v, w)
– using the find operation to see if they are in the same set
– Example) {0}, {1, 2, 3}, {5}, {6}
an edge (2, 3) make a cycle, while an edge (1, 5) does not.
adding an edge (v, w)
Minimum Cost Spanning
Trees(Cont’d)
•

Prim’s Algorithm
– Algorithm
•
•
•

beginning with a tree, T, that contains a single vertex
adding an edge (u, v) to T ( T U {(u, v)} is also a tree )
repeating this edge addition until T contains n-1 edges

– forming a tree at each stage
– a cycle problem
•

choosing the edge (u, v) such that one of u or v is in T

– a formal description Prim’s algorithm
T = { }; /* T is the set of tree edges */
TV = { 0 }; /* TV is the set of tree vertices */
while( T contains fewer than n-1 edges ){
let (u, v) be a least cost edge such that u ∈ TV and v ∈ TV;
if( there is no such edge){
break;
add v to TV;
add (u, v) to T;
}
if( T contains fewer than n-1 edges ){
print(“No spanning tree”);
}
Minimum Cost Spanning
Trees(Cont’d)
•

Prim’s Algorithm(Cont’d)
– a strategy for this algorithm
•
•
•

assuming a vertex v that is not in TV
v has a companion vertex, near(v), such that near(v) ∈ TV
cost(near(v), v) is minimum

– faster implementations
•

using Fibonacci heaps
Minimum Cost Spanning
Trees(Cont’d)
•

Sollin’s Algorithm
– Algorithm
•
•
•
•
•

selecting several edges
eliminating the duplicate edges
selected edges and all vertices in a graph form a spanning forest
selecting an edge from each tree that has the minimum cost in the forest
adding a selected edge
Shortest Paths and Transitive
Closure
• Shortest Paths Problems
– Single Source All Destination
– All Pairs Shortest Paths
Shortest Paths and Transitive
Closure(Cont’d)
• Single Source All Destination
– Dijkstra’s Algorithm

V1

V0

V0

50

V1

>

10

V2

20
15

V3

int cost[][] = {{0, 50, 10, 1000, 45, 1000},
{1000, 0, 15, 1000, 10, 1000},
{20, 1000, 0, 15, 1000, 1000},
{1000, 20, 1000, 0, 35, 1000},
{1000, 1000, 30, 1000, 0, 1000},
{1000, 1000, 1000, 3, 1000, 0}
};

if(distance[u] + cost[u][w] < distance[w]){
distance[w] = distance[u] + cost[u][w];
}
Shortest Paths and Transitive
Closure(Cont’d)
• All Pairs Shortest Paths
if(this.distanceAll[i][j] > this.distanceAll[i][k] + this.distanceAll[k][j]){
this.distanceAll[i][j] = this.distanceAll[i][k] + this.distanceAll[k][j];
}

V0

V0

11

V2

>

4

V1

2

V2
Shortest Paths and Transitive
Closure(Cont’d)
• Transitive Closure
– Transitive Closure
•

A+[i][j] = 1 if there is a path of length > 0 from i to j

– Reflexive Transitive Closure
•

A*[i][j] = 1 if there is a path of length ≥ 0 from i to j

if(this.distanceTrans[i][j] || this.distanceTrans[i][k] && this.distanceTrans[k][j]){
this.distanceTrans[i][j] = true;
this.distanceReflexTrans[i][j] = this.distanceTrans[i][j];
}

0

1

2

3

4
Activity Networks
• AOV(Activity On Vertex)
–
–
–
–

is a directed graph G
vertices represent tasks or activities
the edges represent precedence relations between activities
predecessor
•
•

vertex i is a predecessor of vertex j
if there is a directed path from vertex i to vertex j

– immediate predecessor
•
•

vertex i is an immediate predecessor of vertex j
if <i, j> is an edge

– successor
•
•

j is a successor of i
if i is a predecessor of j

– immediate successor
•
•

j is an immediate successor of i
if i is an immediate predecessor of j
Activity Networks(Cont’d)
• AOV(Activity On Vertex)(Cont’d)
– feasible project
•

the precedence relations must be both transitive and irreflexive

– transitive
•

i∙j and j∙k  i∙k for all triples i, j, k

– irreflexive
•

i∙i is false for all elements

– a directed acyclic graph
•
•

a directed graph with no cycles
a directed acyclic graph is proven that a precedence relation is irreflexive
Activity Networks(Cont’d)
• AOV(Activity On Vertex)(Cont’d)
– a topological order
•
•

a linear ordering of the vertices of a graph
Operations
a. determine if a vertex has any predecessors
(keeping a count of the number of immediate predecessors)
b. delete a vertex and all of its incident edges
(representing the network by adjacency lists)

for( i = 0 ; i < n ; i++){
if every vertex has a predecessor{
print(“Network has a cycle”);
}
pick a vertex v that has no predecessors;
output v;
delete v and all edges leading out of v from the network;
}

Más contenido relacionado

La actualidad más candente

MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsShameer Ahmed Koya
 
Parallel Algorithms for Trees
Parallel Algorithms for TreesParallel Algorithms for Trees
Parallel Algorithms for TreesAhmad Khayyat
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics TutorialCheng-An Yang
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Basics of Dynamic programming
Basics of Dynamic programming Basics of Dynamic programming
Basics of Dynamic programming Yan Xu
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Randa Elanwar
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data framesExternalEvents
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Randa Elanwar
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in ScalaTim Dalton
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islamIslam Alabbasy
 
Graph mining 2: Statistical approaches for graph mining
Graph mining 2: Statistical approaches for graph miningGraph mining 2: Statistical approaches for graph mining
Graph mining 2: Statistical approaches for graph miningtuxette
 
Matrix Product (Modulo-2) Of Cycle Graphs
Matrix Product (Modulo-2) Of Cycle GraphsMatrix Product (Modulo-2) Of Cycle Graphs
Matrix Product (Modulo-2) Of Cycle Graphsinventionjournals
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data StructureMandeep Singh
 
Semantic Data Management in Graph Databases: ESWC 2014 Tutorial
Semantic Data Management in Graph Databases: ESWC 2014 TutorialSemantic Data Management in Graph Databases: ESWC 2014 Tutorial
Semantic Data Management in Graph Databases: ESWC 2014 TutorialMaribel Acosta Deibe
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-onlinelifebreath
 
Semantic Data Management in Graph Databases
Semantic Data Management in Graph DatabasesSemantic Data Management in Graph Databases
Semantic Data Management in Graph DatabasesMaribel Acosta Deibe
 
Chapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel RelationChapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel RelationVarun Ojha
 

La actualidad más candente (20)

2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
 
Parallel Algorithms for Trees
Parallel Algorithms for TreesParallel Algorithms for Trees
Parallel Algorithms for Trees
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics Tutorial
 
10 linescan
10 linescan10 linescan
10 linescan
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Basics of Dynamic programming
Basics of Dynamic programming Basics of Dynamic programming
Basics of Dynamic programming
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data frames
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in Scala
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
Graph mining 2: Statistical approaches for graph mining
Graph mining 2: Statistical approaches for graph miningGraph mining 2: Statistical approaches for graph mining
Graph mining 2: Statistical approaches for graph mining
 
Matrix Product (Modulo-2) Of Cycle Graphs
Matrix Product (Modulo-2) Of Cycle GraphsMatrix Product (Modulo-2) Of Cycle Graphs
Matrix Product (Modulo-2) Of Cycle Graphs
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Semantic Data Management in Graph Databases: ESWC 2014 Tutorial
Semantic Data Management in Graph Databases: ESWC 2014 TutorialSemantic Data Management in Graph Databases: ESWC 2014 Tutorial
Semantic Data Management in Graph Databases: ESWC 2014 Tutorial
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
 
Semantic Data Management in Graph Databases
Semantic Data Management in Graph DatabasesSemantic Data Management in Graph Databases
Semantic Data Management in Graph Databases
 
Chapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel RelationChapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel Relation
 

Destacado

Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
Sentiment Analysis
Sentiment AnalysisSentiment Analysis
Sentiment Analysisishan0019
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)Dr. Ahmed Al Zaidy
 
Fanuc pmc programming manual
Fanuc pmc programming manualFanuc pmc programming manual
Fanuc pmc programming manualAntonio J
 
Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language conceptAfiq Sajuri
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Akshay Nagpurkar
 
Chapter 6m
Chapter 6mChapter 6m
Chapter 6mwafaa_A7
 
1 . introduction to communication system
1 . introduction to communication system1 . introduction to communication system
1 . introduction to communication systemabhijitjnec
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulationHattori Sidek
 
Digital communication viva questions
Digital communication viva questionsDigital communication viva questions
Digital communication viva questionsishan0019
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesVasavi College of Engg
 
PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)vishnudharan11
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Digital communication system
Digital communication systemDigital communication system
Digital communication systembabak danyal
 
Digital modulation
Digital modulationDigital modulation
Digital modulationAnkur Kumar
 
Analog communication
Analog communicationAnalog communication
Analog communicationPreston King
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 

Destacado (20)

Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Sentiment Analysis
Sentiment AnalysisSentiment Analysis
Sentiment Analysis
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)
 
Fanuc pmc programming manual
Fanuc pmc programming manualFanuc pmc programming manual
Fanuc pmc programming manual
 
Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language concept
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Chapter 6m
Chapter 6mChapter 6m
Chapter 6m
 
1 . introduction to communication system
1 . introduction to communication system1 . introduction to communication system
1 . introduction to communication system
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulation
 
Digital communication viva questions
Digital communication viva questionsDigital communication viva questions
Digital communication viva questions
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 
PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)PULSE CODE MODULATION (PCM)
PULSE CODE MODULATION (PCM)
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Digital communication system
Digital communication systemDigital communication system
Digital communication system
 
Digital modulation
Digital modulationDigital modulation
Digital modulation
 
Analog communication
Analog communicationAnalog communication
Analog communication
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 

Similar a 8150.graphs

Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsAakash deep Singhal
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structuresSavit Chandra
 
CS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on GraphsCS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on Graphsssuser034ce1
 
CS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on GraphsCS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on Graphsssuser034ce1
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjtepournima055
 
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 LermaPyData
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________ssuser1989da
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search TechniquesSVijaylakshmi
 
FADML 06 PPC Graphs and Traversals.pdf
FADML 06 PPC Graphs and Traversals.pdfFADML 06 PPC Graphs and Traversals.pdf
FADML 06 PPC Graphs and Traversals.pdfYelah1
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search TechniquesSVijaylakshmi
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxasimshahzad8611
 

Similar a 8150.graphs (20)

ALG5.1.ppt
ALG5.1.pptALG5.1.ppt
ALG5.1.ppt
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
CS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on GraphsCS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on Graphs
 
CS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on GraphsCS-102 Data Structure lectures on Graphs
CS-102 Data Structure lectures on Graphs
 
10.graph
10.graph10.graph
10.graph
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
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
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
 
Graphs
GraphsGraphs
Graphs
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
FADML 06 PPC Graphs and Traversals.pdf
FADML 06 PPC Graphs and Traversals.pdfFADML 06 PPC Graphs and Traversals.pdf
FADML 06 PPC Graphs and Traversals.pdf
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Basic Traversal and Search Techniques
Basic Traversal and Search TechniquesBasic Traversal and Search Techniques
Basic Traversal and Search Techniques
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
lecture11.ppt
lecture11.pptlecture11.ppt
lecture11.ppt
 

Más de Jonghoon Park

Más de Jonghoon Park (14)

Equivalence relations
Equivalence relationsEquivalence relations
Equivalence relations
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Dynamically linked queues
Dynamically linked queuesDynamically linked queues
Dynamically linked queues
 
Dynamically linked stacks
Dynamically linked stacksDynamically linked stacks
Dynamically linked stacks
 
Singly linked lists
Singly linked listsSingly linked lists
Singly linked lists
 
Maze
MazeMaze
Maze
 
Evaluation expression
Evaluation expressionEvaluation expression
Evaluation expression
 
Sdoku
SdokuSdoku
Sdoku
 
N queen
N queenN queen
N queen
 
Hemilton cycle circuit
Hemilton cycle circuitHemilton cycle circuit
Hemilton cycle circuit
 
Good numbers
Good numbersGood numbers
Good numbers
 
Min inconmensurable weight
Min inconmensurable weightMin inconmensurable weight
Min inconmensurable weight
 
Garden for princess
Garden for princessGarden for princess
Garden for princess
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

8150.graphs

  • 2. Index • • • • • The Graph Abstract Data Type Elementary Graph Operations Minimum Cost Spanning Trees Shortest Paths and Transitive Closure Activity Networks
  • 3. Curriculum Model A A A A A CS Here I am A A A CS A Java Language Base CS : Computer Science A : Application
  • 4. The Graph Abstract Data Type • Introduction – – – – – Analysis of electrical circuits finding shortest routes project planning identification of chemical compounds all mathematical structures
  • 5. The Graph Abstract Data Type(Cont’d) • Definitions – A graph consists of • nonempty set of vertices • empty set of edges – G = (V, E) – undirected graph • (v0, v1) and (v1, v0) represent the same edge – directed graph • <v0, v1> represents an edge in which v0 is the tail and v1 is the head
  • 6. The Graph Abstract Data Type(Cont’d) • Definitions(Cont’d) – Restriction on Graphs • A graph may not have self loops • A graph may not have multiple occurrences of the same edge – A complete graph • having the maximum number of edges • undirected graph = n(n-1)/2 • directed graph = n(n-1) – Adjacent • Ex) in Graph G2 – vertices 3, 4 and 0 are adjacent to vertex 1 – incident on • Ex) in Graph G2 – edges (0, 2), (2, 5) and (2, 6) are incident on vertex 2 – directed edge<v0, v1> • Adjacent – v0 is adjacent to v1, v1 is adjacent from v0 • incident on - <v0, v1> in incident on v0 and v1 • Ex) in Graph G3 – edges<0, 1>, <1, 0> and <1, 2> are incident on vertex 1
  • 7. The Graph Abstract Data Type(Cont’d) • Definitions(Cont’d) – Subgraphs • A subgraph of G is a graph G` such that V(G`) ⊆ V(G) • Ex) Subgraphs of G1 – the length of path • the number of edges on a path – simple path • a path in which all vertices, except the first and the last, are distinct • Ex) (0, 1), (1, 3), (3, 2) can be written as 0, 1, 3, 2 in graph G1 0, 1, 3, 2 is a simple path, while 0, 1, 3, 1 is not. – Cycle • a simple path in which the first and the last vertices are the same • Ex) in Graph G1 0, 1, 2, 0 is a cycle
  • 8. The Graph Abstract Data Type(Cont’d) • Definitions(Cont’d) – Connected • in an undirected graph G, two vertices, v0 and v1, are connected • in the case of v0 and v1 has a path • Ex) graph G1 and G2 are connected, while graph G4 is not – Connected component • Graph G4 has two components, H1, H2 – Strongly connected • for a directed graph
  • 9. The Graph Abstract Data Type(Cont’d)
  • 10. The Graph Abstract Data Type(Cont’d) • Definitions(Cont’d) – ADT Graph
  • 11. The Graph Abstract Data Type(Cont’d)
  • 12. The Graph Abstract Data Type(Cont’d) • Graph Representation(Cont’d) – Adjacent Lists • node structure Class Node{ int vertex; Node link; } • the starting point of the list for vertex i – node[i] • the number of nodes in its adjacency list – the degree of any vertex in an undirected graph – the number of edges incident on the vertex – the out-degree of any vertex in an directed graph • inverse adjacency list – the in-degree of a vertex – all vertices adjacent to a vertex
  • 13. The Graph Abstract Data Type(Cont’d) • Graph Representation(Cont’d) – Adjacent Lists(Cont’d) • Changing node structure – The problem of finding in-degree Class Node{ int tail; int head Node columnLinkForHead; Node rowLinkForTail; }
  • 14. The Graph Abstract Data Type(Cont’d) • Graph Representation(Cont’d) – Adjacent Multilists
  • 15. The Graph Abstract Data Type(Cont’d) • Graph Representation(Cont’d) – Weighted Edges • weights may represent – the distance or the cost • network – a graph with weighted edges
  • 16. Elementary Graph Operations • Depth First Search – similar to a preorder tree traversal – using a stack – Process • • • • • • • • • visit the start vertex v select an unvisited vertex, w, from v’s adjacency list v is placed on a stack reaches a vertex, u, that has no visited vertices on v’s adjacency list remove a vertex from the stack processing its adjacency list previously visited vertices are discarded unvisited vertices are visited and placed on the stack terminates the stack is empty v0v1v3v7v4v5v2v6 void dfs(int v){ visited[v] = true; System.out.println(v); for(Node w = graph[v] ; w != null ; w = w.link){ if(!visited[w.vertex]) dfs(w.vertex); time complexity } adjacency list = O(e) } adjacency matrix = O(n2)
  • 17. Elementary Graph Operations(Cont’d) • Breath First Search – resembles a level order traversal – using a queue – Process • • • • • • • • visit the vertex v and marks it visit all of the first vertex on v’s adjacency list each vertex is placed to queue all of vertices on v’s adjacency list are visited remove a vertex from the queue examine the vertex again that is removed from the queue visited vertices are ignored the search is finished when the queue is empty
  • 18. Elementary Graph Operations(Cont’d) • Breath First Search(Cont’d) class Queue{ int vertex; Queue link; } void bfs(int v){ Queue front = null, rear=null; System.out.println(v); visited[v] = true; addq(front, rear, v); while(front != null){ v = deleteq(front); v0v1v2v3v4v5v6v7 for(Node w = graph[v] ; w != null ; w = w.link){ if(!visited[w.vertex]){ System.out.println(w.vertex); addq(front, rear, w.vertex); visited[w] = true; } } Time complexity } adjacency list = O(e) } adjacency matrix = O(n2)
  • 19. Elementary Graph Operations(Cont’d) • Connected Component – determining whether or not an undirected graph is connected – calling either dfs(0) or bfs(0) – it determined as an unconnected graph • • we can list up the connected components of a graph repeated calls to either dfs(v) or bfs(v) whee v is unvisited vertex void connected(){ for(int i = 0 ; i < n ; i ++){ if(!visited[i]){ dfs(i); System.out.println(); } } } Time complexity adjacency list = O(n+e), (dfs takes O(e), for loop takes O(n)) adjacency matrix = O(n2)
  • 20. Elementary Graph Operations(Cont’d) • Spanning Tree – The search implicitly partitions the edges in G into two sets • • tree edges nontree edges – tree edges • set of traversed edges – nontree edges • set of remaining edges – forming a tree • • if clause of either dfs or bfs it inserts the edge(v, w) – a spanning tree is any tree • • consists solely of edges in G includes all the vertices in G – a dfs and bfs spanning tree
  • 21. Elementary Graph Operations(Cont’d) • Spanning Tree(Cont’d) – add a nontree edge(v, w) • • • generating a cycle used for obtaining an independent set of circuit equations for an electrical network Ex) adding the nontree edge (7, 6)  7, 6, 2, 5, 7 – minimal subgraph • • • • a spanning tree is a minimal subgraph of graph G any connected graph with n vertices must have at least n-1 edges all connected graph with n-1 edges are trees a spanning tree has n-1 edges – assign weights to the edges • • the cost of constructing the communication links or the length of the links minimum cost spanning trees
  • 22. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points – Articulation Point • • a vertex to produce two connected components the articulation points 1, 3, 4, and 7 on the right images – Biconnected Graph • a connected graph that has no articulation points – loss of communication • an articulation point fails results a loss of communication – biconnected components • having no more than one vertex in common
  • 23. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points(Cont’d) – finding the biconnected components • use any depth first spanning tree – depth first number • the sequence of visiting the vertices – back edge • • • a nontree edge (u, v) either u is an ancestor of v or v is an ancestor of u all nontree edges are back edges dfs redrawn
  • 24. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points(Cont’d) – finding an articulation point • • the root of the spanning tree and has two or more children not the root and u has a child w such that low(w) ≥ dfn(u) low(u) = min{ dfn(u), min{low(w) | w is a child of u}, min{ dfn(w), (u, w) is a back edge} } void dfnlow(int u, int v){ dfn[u] = low[u] = num++; for( Node ptr = graph[u] ; ptr != null ; ptr = ptr.link ){ w = ptr.vertex; if(dfn[w] < 0){ dfnlow(w, u); low[u] = min(low[w], low[u]); } else if(w != v){ low[u] = min(low[u], dfn[w]); } } }
  • 25. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points(Cont’d) – an articulation point(Cont’d) low(3) = min{ dfn(3) = 0, min{low(4) = 0}, min{ dfn(1) = 3} } = 0 low(4) = min{ dfn(4) = 1, min{low(2) = 0} } = 0 low(2) = min{ dfn(2) = 2, min{low(1) = 0} } = 0 low(1) = min{ dfn(1) = 3, min{low(0) = 4}, min{ dfn(3) = 0} } = 0 low(0) = min{ dfn(0) = 4 } = 4 low(5) = min{ dfn(5) = 5, min{low(6) = 5}, min{ dfn(7) = 7} } = 5 low(6) = min{ dfn(6) = 6, min{low(7) = 5} } = 5 low(7) = min{ dfn(7) = 7, min{low(8) = 9}, min{ dfn(5) = 5} } = 5 low(8) = min{ dfn(8) = 9 } = 9 low(9) = min{ dfn(9) = 8 } = 8
  • 26. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points(Cont’d) – biconnected components of a graph void bicon(int u, int v){ dfn[u] = low[u] = num++; for( Node ptr = graph[u] ; ptr != null ; ptr = ptr.link ){ int w = ptr.vertex; if(v != w && dfn[w] < dfn[u]){ push(top, u, w); if(dfn[w] < 0){ bicon(w, u); low[u] = min(low[u], low[w]); if(low[w] >= dfn[u]){ System.out.println(“New biconnected component:”); int x, y; do{ pop(top, x, y); System.out.println(“<“ + x + “, “ + y + “>”); }while(!((x == u) && (y == w))); System.out.println(); } } else if(w != u) low[u] = min(low[u], dfn[w]); } } }
  • 27. Elementary Graph Operations(Cont’d) • Biconnected Components and Articulation Points(Cont’d) – biconnected components of a graph(Cont’d) 0 1 1 0 2 2 4 1 3 4 1 4 3 2 5 3 6 6 5 7 7 6 9 8 7 9 7 3 5 bicon(3, -1) 7 8 5
  • 28. Minimum Cost Spanning Trees • the cost of a spanning tree – the sum of the costs(weights) • greedy method – – – – an optimal solution for a wide variety of programming problems based on either a least cost or a highest profit criterion the constraints specified by the problem • constraints of MCST – must use only edges within the graph – must use exactly n-1 edges – may not use edges that would produce a cycle
  • 29. Minimum Cost Spanning Trees(Cont’d) • Kruscal’s Algorithm – Algorithm • • • selecting the edges in nondecreasing order of their cost a selected edge does not make a cycle n-1 edges will be selected for inclusion in T – forming a forest at each stage of algorithm – a formal description of Kruscal’s algorithm T = {}; while( T contains less than n-1 edges && E is not empty){ choose a least cost edge (v, w) from E; delete (v, w) from E; if((v, w) does not create a cycle in T){ add (v, w) to T; } else { discard(v, w); } } if( T contains fewer than n-1 edges){ print(“No spanning tree”); }
  • 30. Minimum Cost Spanning Trees(Cont’d) • Kruscal’s Algorithm(Cont’d) – a cycle problem • • • using the union-find operations adding an edge (v, w) – using the find operation to see if they are in the same set – Example) {0}, {1, 2, 3}, {5}, {6} an edge (2, 3) make a cycle, while an edge (1, 5) does not. adding an edge (v, w)
  • 31. Minimum Cost Spanning Trees(Cont’d) • Prim’s Algorithm – Algorithm • • • beginning with a tree, T, that contains a single vertex adding an edge (u, v) to T ( T U {(u, v)} is also a tree ) repeating this edge addition until T contains n-1 edges – forming a tree at each stage – a cycle problem • choosing the edge (u, v) such that one of u or v is in T – a formal description Prim’s algorithm T = { }; /* T is the set of tree edges */ TV = { 0 }; /* TV is the set of tree vertices */ while( T contains fewer than n-1 edges ){ let (u, v) be a least cost edge such that u ∈ TV and v ∈ TV; if( there is no such edge){ break; add v to TV; add (u, v) to T; } if( T contains fewer than n-1 edges ){ print(“No spanning tree”); }
  • 32. Minimum Cost Spanning Trees(Cont’d) • Prim’s Algorithm(Cont’d) – a strategy for this algorithm • • • assuming a vertex v that is not in TV v has a companion vertex, near(v), such that near(v) ∈ TV cost(near(v), v) is minimum – faster implementations • using Fibonacci heaps
  • 33. Minimum Cost Spanning Trees(Cont’d) • Sollin’s Algorithm – Algorithm • • • • • selecting several edges eliminating the duplicate edges selected edges and all vertices in a graph form a spanning forest selecting an edge from each tree that has the minimum cost in the forest adding a selected edge
  • 34. Shortest Paths and Transitive Closure • Shortest Paths Problems – Single Source All Destination – All Pairs Shortest Paths
  • 35. Shortest Paths and Transitive Closure(Cont’d) • Single Source All Destination – Dijkstra’s Algorithm V1 V0 V0 50 V1 > 10 V2 20 15 V3 int cost[][] = {{0, 50, 10, 1000, 45, 1000}, {1000, 0, 15, 1000, 10, 1000}, {20, 1000, 0, 15, 1000, 1000}, {1000, 20, 1000, 0, 35, 1000}, {1000, 1000, 30, 1000, 0, 1000}, {1000, 1000, 1000, 3, 1000, 0} }; if(distance[u] + cost[u][w] < distance[w]){ distance[w] = distance[u] + cost[u][w]; }
  • 36. Shortest Paths and Transitive Closure(Cont’d) • All Pairs Shortest Paths if(this.distanceAll[i][j] > this.distanceAll[i][k] + this.distanceAll[k][j]){ this.distanceAll[i][j] = this.distanceAll[i][k] + this.distanceAll[k][j]; } V0 V0 11 V2 > 4 V1 2 V2
  • 37. Shortest Paths and Transitive Closure(Cont’d) • Transitive Closure – Transitive Closure • A+[i][j] = 1 if there is a path of length > 0 from i to j – Reflexive Transitive Closure • A*[i][j] = 1 if there is a path of length ≥ 0 from i to j if(this.distanceTrans[i][j] || this.distanceTrans[i][k] && this.distanceTrans[k][j]){ this.distanceTrans[i][j] = true; this.distanceReflexTrans[i][j] = this.distanceTrans[i][j]; } 0 1 2 3 4
  • 38. Activity Networks • AOV(Activity On Vertex) – – – – is a directed graph G vertices represent tasks or activities the edges represent precedence relations between activities predecessor • • vertex i is a predecessor of vertex j if there is a directed path from vertex i to vertex j – immediate predecessor • • vertex i is an immediate predecessor of vertex j if <i, j> is an edge – successor • • j is a successor of i if i is a predecessor of j – immediate successor • • j is an immediate successor of i if i is an immediate predecessor of j
  • 39. Activity Networks(Cont’d) • AOV(Activity On Vertex)(Cont’d) – feasible project • the precedence relations must be both transitive and irreflexive – transitive • i∙j and j∙k  i∙k for all triples i, j, k – irreflexive • i∙i is false for all elements – a directed acyclic graph • • a directed graph with no cycles a directed acyclic graph is proven that a precedence relation is irreflexive
  • 40. Activity Networks(Cont’d) • AOV(Activity On Vertex)(Cont’d) – a topological order • • a linear ordering of the vertices of a graph Operations a. determine if a vertex has any predecessors (keeping a count of the number of immediate predecessors) b. delete a vertex and all of its incident edges (representing the network by adjacency lists) for( i = 0 ; i < n ; i++){ if every vertex has a predecessor{ print(“Network has a cycle”); } pick a vertex v that has no predecessors; output v; delete v and all edges leading out of v from the network; }