1

GRAPH
INTRODUCTION
Introduced in 1736

Leonhard Euler
Solved “Konigsberg Bridge Problem”

2

Eulerian Circuit or Euler Tour
KONIGSBERG BRIDGE
PROBLEM

3

The problem was to find a walk through the city that would
cross each bridge once and only o...
4

KONIGSBERG BRIDGE
PROBLEM
5

DESIGN OF SOLUTION
6

CLASS TASK
7

SOLUTION
CONCLUSION

8

Eularian circuit exists if,
and only if, the graph is
connected, and there
are no nodes of odd
degree at al...
BASIC TERMINOLOGY
Graph : Two sets V(G) & E(G)

Undirected Graph

(u,v)

Directed Graph

<u,v>

Self Edges
Multigraph
No. ...
BASIC TERMINOLOGY
Adjacent Vertices

Subgraph
Path
Length of Path
Simple Path : all vertices are distinct except first & l...
BASIC TERMINOLOGY
Connected Vertices

Connected graph
Connected Components : maximal connected subgraph
Acyclic Graph
Stro...
BASIC TERMINOLOGY
Degree

In-degree
Out-degree

12

Weighted Edges
GRAPH
REPRESENTATION
Adjacency Matrix

13

Adjacency List
OPERATIONS ON
GRAPH
Depth-First Search

Breadth-First Search

Connected Components

14

Shortest Path Algorithm
DEPTH-FIRST SEARCH
Void Graph ::DFS( )
Visited = new boolean[n];
For(int I=0;I<n;I++) visited [I] = false;
DFS(0);
Delete ...
BREADTH-FIRST SEARCH
Void Graph ::BFS(int v)
• Visited = new boolean[n];
• For(int I=0; I<n; I++) visited [I] = false;
• V...
CONNECTED COMPONENT
Void Graph::Components( )
• Visited = new boolean [n];
• For(int I = 0;I < n; I++) visited [I] = false...
SHORTEST PATH
Void Graph::ShortestPath(int n, int v)
• For(int I=0; I<n; I++)
{s[I] =false;dist[I]=length[v][I];}
• S[v] =...
EXAMPLE
1

2

3

4

0

0

5

10

∞

∞

1

∞

0

3

2

9

2

∞

∞

0

6

∞

3

∞

∞

∞

0

4

4

∞

∞

∞

∞

0

19

0
Upcoming SlideShare
Loading in …5
×

Graph

413 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
413
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Graph

  1. 1. 1 GRAPH
  2. 2. INTRODUCTION Introduced in 1736 Leonhard Euler Solved “Konigsberg Bridge Problem” 2 Eulerian Circuit or Euler Tour
  3. 3. KONIGSBERG BRIDGE PROBLEM 3 The problem was to find a walk through the city that would cross each bridge once and only once. The islands could not be reached by any route other than the bridges, and every bridge must have been crossed completely every time; one could not walk halfway onto the bridge and then turn around and later cross the other half from the other side. The walk need to start and end at the same spot.
  4. 4. 4 KONIGSBERG BRIDGE PROBLEM
  5. 5. 5 DESIGN OF SOLUTION
  6. 6. 6 CLASS TASK
  7. 7. 7 SOLUTION
  8. 8. CONCLUSION 8 Eularian circuit exists if, and only if, the graph is connected, and there are no nodes of odd degree at all.
  9. 9. BASIC TERMINOLOGY Graph : Two sets V(G) & E(G) Undirected Graph (u,v) Directed Graph <u,v> Self Edges Multigraph No. of edges = n(n-1)/2(undirected) 9 No. of edges = n(n-1) (directed)
  10. 10. BASIC TERMINOLOGY Adjacent Vertices Subgraph Path Length of Path Simple Path : all vertices are distinct except first & last 10 Cycle
  11. 11. BASIC TERMINOLOGY Connected Vertices Connected graph Connected Components : maximal connected subgraph Acyclic Graph Strongly Connected 11 Strongly Connected Components
  12. 12. BASIC TERMINOLOGY Degree In-degree Out-degree 12 Weighted Edges
  13. 13. GRAPH REPRESENTATION Adjacency Matrix 13 Adjacency List
  14. 14. OPERATIONS ON GRAPH Depth-First Search Breadth-First Search Connected Components 14 Shortest Path Algorithm
  15. 15. DEPTH-FIRST SEARCH Void Graph ::DFS( ) Visited = new boolean[n]; For(int I=0;I<n;I++) visited [I] = false; DFS(0); Delete [] visited; Void Graph ::DFS(const int v) visited [v] = true; for( each vertex w adjacent to v) if(! Visited [w]) DFS(w); 15 • • • •
  16. 16. BREADTH-FIRST SEARCH Void Graph ::BFS(int v) • Visited = new boolean[n]; • For(int I=0; I<n; I++) visited [I] = false; • Visited [v] = true; • Queue<int> q; • Q.insert(v); • While(!q.IsEmpty()) • V= *q.delete(v); • For(all vertices w adjacent to v) • If(!visited [w]) • q.Insert(w); • Visited [w] = true; 16 • Delete [] visited;
  17. 17. CONNECTED COMPONENT Void Graph::Components( ) • Visited = new boolean [n]; • For(int I = 0;I < n; I++) visited [I] = false; • For(I=0; I < n; I++) • If (! Visited [I]) • DFS (I); • OutputNewComponent(); 17 • Delete [ ] visited;
  18. 18. SHORTEST PATH Void Graph::ShortestPath(int n, int v) • For(int I=0; I<n; I++) {s[I] =false;dist[I]=length[v][I];} • S[v] = true; • Dist[v] = 0; • For(I=0; I<=n-2; I++) 18 • Int u=choose(n); • S[u] = true; • For(int w=0; w<n; w++) • If(!s[w]) • If(dist[u] + length[u][w] < dist[w]) • Dist[w] = dist[u] + length[u][w];
  19. 19. EXAMPLE 1 2 3 4 0 0 5 10 ∞ ∞ 1 ∞ 0 3 2 9 2 ∞ ∞ 0 6 ∞ 3 ∞ ∞ ∞ 0 4 4 ∞ ∞ ∞ ∞ 0 19 0

×