SlideShare a Scribd company logo
GRAPHS
AUTHOR:
PRINCE KUMAR
MSC CS
5
1
2
4 3
CONTENTS…
 INTRODUCTION
 START WITH GRAPHS
 BASIC TERMINOLOGIES OF GRAPHS
 VARIANCE OF GRAPHS
 MINIMAL SPANNING TREES
 IMPLEMENTATION OF GRAPHS
 TRAVERSAL IN GRAPHS: BFS, DFS
 KRUSKAL’s ALGORITHM
 PRIM’s ALGORITHM
 DIZKASTRA ALGORITHM OF SHORTEST PATH
INTRODUCTION
 This presentation is prepared as a tutorial package on basic graph
theory and algorithms and its implementation as a data structure.
 It also includes some assignments for practice on algorithms.
 Hope this presentation will help the students to understand the
concepts of elementary graph theory.
 PRINCE KUMAR
START WITH GRAPHS
 A Graph G(V,E) is defined as tuple where_
 V ≠ Φ is a finite set of vertices.
 E is set of edges between given vertices.
 Ex. G(V,E) is a graph as below_
V = {1,2,3,4,5}
E = {
{1,2},{2,3},{3,5},{5,4},{1,4},{2,5}
}
4
5
1
3
2
BASIC TERMINOLOGIES OF GRAPHS
 Adjacent
 In a graph G(V,E) if u and v V such that { u , v } E then u and v are
called adjacent to each other.
 Example: in given figure:
2, 3, 4 are adjacent to 5.
4
5
1
3
2
BASIC TERMINOLOGIES OF GRAPHS
 Degree of a vertex: deg(v)
 No. of adjacent to a given vertex is its degree.
 Example: in given figure:
vertices 2, 3 and 4 are adjacent to vertex 5
so it has degree 3 i.e. deg(5) = 3 .
4
5
1
3
2
BASIC TERMINOLOGIES OF GRAPHS
 On the basis of degree, vertices are called_
 Isolated : 0 degree , e.g. Vertex 6,
 Pendent : 1 degree, e.g. Vertex 3,
 Odd : odd degree, e.g. Vertex 5,
 Even : even degree, e.g. Vertex 1.
4
5
1
3
2
6
BASIC TERMINOLOGIES OF GRAPHS
 In a graph ,
The sum of degrees of all the vertices is twice of no. of
edges.
𝑖=1
𝑛
deg 𝑉𝑖 = 2|𝐸|
VARIANCE OF GRAPHS
 COMPLETE GRAPH
 A graph G(V,E) is called as complete graph and denoted as K|V| if
each vertices have degree |V|-1.
 Fig. K5
5
1
2
4 3
VARIANCE OF GRAPHS
 N-REGULAR GRAPH
 A graph G(V,E) is called as N- regular graph if each vertices have
degree N.
 Fig: 4 Regular Graph
5
1
2
4 3
VARIANCE OF GRAPHS
 CONNECTED GRAPH
 A graph G(V,E) is called connected if in between any two vertices there is a
path else it is disconnected.
Fig: (a) Connected (b) Disconnected
5
1
2
4 3
5
1
2
4 3
6
6
VARIANCE OF GRAPHS
 WEIGHTED GRAPH
 A graph G(V,E) is called weighted if all the edges in the graph
having some cost.
5
1
2
4 3
6
a
b
c
d
ef
g
h
VARIANCE OF GRAPHS
 SUBGRAPH
 A graph S(V’,E’) is called subgraph of graph G(V,E) if V’ is subset of
V and E’ is subset of E.
5
1
2
4 3
6
5
1
2
6
VARIANCE OF GRAPHS
 SPANNING SUBGRAPH
 A graph S(V,E’) is called spanning subgraph of graph G(V,E) if E’ is
subset of E.
5
1
2
4 3
6
5
1
2
4 3
6
VARIANCE OF GRAPHS
 TREE
 A tree is a connected graph with no cycles.
5
1
2
4 3
6
MINIMAL SPANNING TREES
 A spanning subgraph of a given graph is called its minimal
spanning tree if_
 It is a tree.
 The total weight on the all the edges in tree is minimal.
5
1
2
4 3
6
2
3
4
1
25
1
3
5
1
2
4 3
6
2
3
1
2
1
IMPLEMENTATION OF GRAPHS
 A graph is represented in memory by_
 Adjacency Matrix : Through 2D arrays.
 The adjacency matrix of a graph G(V, E) is defined as _
A(G) = { a i,j }
where a i,j = { 1 or w if (vi, vj) E
0 else
}
IMPLEMENTATION OF GRAPHS
 Adjacency matrix for adjacent graph is as below_
5
1
2
4 3
0 1 0 0 1
1 0 1 1 1
0 1 0 1 0
0 1 1 0 1
1 1 0 1 0
IMPLEMENTATION OF GRAPHS
 Adjacency List : Through Linked Lists.
5
1
2
4 3
1
2
3
4
5
2 5
1 3 4 5
2 4
2 3 5
1 2 4
TRAVERSALS IN GRAPHS
 For searching an element in the graph generally
we use two types of traversals as below_
 Breadth First Search (BFS):
It searches a node in adjacent of a given node and so on.
It is used when it is known that the target is near to the
source.
TRAVERSALS IN GRAPHS
 Breadth First Search (BFS) Algorithm:
 Let the algorithm assumes A graph G(V,E) is connected is
given with source say root( r ).
 It maintains a queue to keep track of the nodes which are
traversed or which are not.
 Traversal status or say color of each node shows whether
 It is unseen : WHITE , source is yellow.
 It is seen only : YELLOW
 It is processed : BLACK
TRAVERSALS IN GRAPHS
 Put the root ‘r’ into the queue;
 While(queue ≠ Φ)
 u = dequeuer(queue)
 for all v in adj_list of u
 if color of v is white then
 Color v by Yelow.
 Enqueue v in queue.
 Color u by black
TRAVERSALS IN GRAPHS
5
1
2
4 3
1
2
3
4
5
2 5
1 3 4 5
2 4
2 3 5
1 2 4
 Lets travers using BFS algorithm in following graph Let source is 1.
QUEUE12 5 3 4
TRAVERSALS IN GRAPHS
 Depth First Search (DFS):
It searches a node in the path starting of a given node
and until the end of the path, if the target is not in that
path keep backtrack on that path and select a new path
from predecessor nodes and so on .
It is used when it is known that the target is in the depth
of the path starting from the source.
TRAVERSALS IN GRAPHS
 Depth First Search (BFS) Algorithm:
 Let the algorithm assumes A graph G(V,E) is connected is
given with source say root( r ).
 It maintains a stack to keep track of the nodes which are
traversed or which are not .
 Traversal status or say color of each node shows whether
 It is unseen : WHITE , source is yellow.
 It is seen only : YELLOW
 It is processed : BLACK
TRAVERSALS IN GRAPHS
 DFS(G)
 for each u G.V
 Color u white
 Set u.Π as Null
 for each u G.V
 If color of u is white
 VISIT(u)
 VISIT(u)
 Color u yellow
 for each v adj_list of u
 If color of v is white
 Set v. Π as Null
 VISIT(v)
 Color u black
ASSIGNMENT
 Q. Traverse the following given graph using DFS algorithm assuming
‘F’ as a source vertex.
A
B
G
F D
E
C
6
4
3
4
7
5
3
2
1
KRUSKAL’S ALGORITHM
 This algorithm gives MST for a given graph G(V,E).
 Steps
 Sort all the edges in ascending order by weight and keep then in a Queue.
 Make a spanning subgraph say S(V,Φ) of the given graph with no edges.
 Dequeue an edge from the queue and add in the S if it’s not making cycle
in the resultant graph.
 Follow above step until the queue will be empty.
KRUSKAL’S ALGORITHM
5
1
2
4 3
6
2
3
4
1
25
1
3
5
1
2
4 3
6
2
3
1
2
1
2-6 4-3 2-3 1-5 1-2 5-4 5-2 4-2
1 1 2 2 3 3 4 5
PRIM’S ALGORITHM
 This algorithm also grows a MST of a given graph G(V,E) starting with
a source say root (r).
 It adds an edge of minimal weight and doesn’t making cycle in the
resultant graph to an isolated vertex.
 It uses a min heap(Q) structure to grow vertex with minimal distance
of connecting edge.
 A weight function(w) that gives the weight of the edge between two
vertices if exists.
 Initial configuration
 It assumes that the distance(d) of all other vertices are infinite from the
given source and their predecessor(Π) is NULL.
PRIM’S ALGORITHM
Prims_algo(G,w,r)
1. r.d <= 0
2. Q <= G.V
3. while Q is not empty
1. u <= Extract_min(Q)
2. for each v Adj_List[u]
1. If v Q and w(u,v) < v.d
1. v.Π <= u
2. v.d <= w(u,v)
ASSIGNMENT
 Q. Grow MST for the following graph using Prim’s algorithm assuming
the source is ‘C’.
A
B
G
F D
E
C
6
4
3
4
7
5
3
2
1
DIZKASTRA’S ALGORITHM FOR
SHORTEST PATH
 It gives shortest path to all the
target vertices in a given
weighted, connected graph
G(V,E) with respect to a given
source vertex say ‘S’.
 It maintains a min heap let Q
to maintain the traversal in the
graph.
 DIJKASTRA_ALGO(G,S)
 Initialize the cost of all the target vertices ∞.
 Set the predecessor as Null.
 Set cost of S 0.
 Get a set R = Φ
 PUT(Q, G.V)
 WHILE Q is not Null
 u = Extract(Q)
 R = R U u
 For each vertex in adj_list of u
 Maintain the lesser cost of paths for the
adjacents of u.
ASSIGNMENT
 Q.Find out shortest distances for all the vertices in the following graph
assuming the source is ‘C’.
A
B
G
F D
E
C
6
4
3
4
7
5
3
2
1
THANKYOU
MAIL ME: KRPRINCE8888@GMAIL.COM

More Related Content

What's hot

Skiena algorithm 2007 lecture12 topological sort connectivity
Skiena algorithm 2007 lecture12 topological sort connectivitySkiena algorithm 2007 lecture12 topological sort connectivity
Skiena algorithm 2007 lecture12 topological sort connectivity
zukun
 
BFS
BFSBFS
18 Basic Graph Algorithms
18 Basic Graph Algorithms18 Basic Graph Algorithms
18 Basic Graph Algorithms
Andres Mendez-Vazquez
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal Algorithm
MSA Technosoft
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
Praveen Yadav
 
Lecture13
Lecture13Lecture13
Lecture13
vaishali_singh
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
Algorithms of graph
Algorithms of graphAlgorithms of graph
Algorithms of graph
getacew
 
Data structure
Data structureData structure
Data structure
sumit singh
 
Graph
GraphGraph
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysis
garishma bhatia
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
AJAL A J
 
1535 graph algorithms
1535 graph algorithms1535 graph algorithms
1535 graph algorithms
Dr Fereidoun Dejahang
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Hema Kashyap
 
Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
Umme habiba
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
Acad
 
Slides
SlidesSlides
Breadth first search
Breadth first searchBreadth first search
Breadth first search
Sazzad Hossain
 

What's hot (20)

Skiena algorithm 2007 lecture12 topological sort connectivity
Skiena algorithm 2007 lecture12 topological sort connectivitySkiena algorithm 2007 lecture12 topological sort connectivity
Skiena algorithm 2007 lecture12 topological sort connectivity
 
BFS
BFSBFS
BFS
 
18 Basic Graph Algorithms
18 Basic Graph Algorithms18 Basic Graph Algorithms
18 Basic Graph Algorithms
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal Algorithm
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
Lecture13
Lecture13Lecture13
Lecture13
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Algorithms of graph
Algorithms of graphAlgorithms of graph
Algorithms of graph
 
Data structure
Data structureData structure
Data structure
 
Graph
GraphGraph
Graph
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysis
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
1535 graph algorithms
1535 graph algorithms1535 graph algorithms
1535 graph algorithms
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 
Bfs & dfs application
Bfs & dfs applicationBfs & dfs application
Bfs & dfs application
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
Slides
SlidesSlides
Slides
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 

Similar to Graphs

Graphs
GraphsGraphs
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
FCS (graphs).pptx
FCS (graphs).pptxFCS (graphs).pptx
FCS (graphs).pptx
ShubhamBatwani
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint paths
Sujith Jay Nair
 
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHMGRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
himanshumishra19dec
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
nabati
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
meisamstar
 
Graphs
GraphsGraphs
Graphs
Dwight Sabio
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Graphs
GraphsGraphs
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
asimshahzad8611
 
Graph.pptx
Graph.pptxGraph.pptx
logic.pptx
logic.pptxlogic.pptx
logic.pptx
KENNEDY GITHAIGA
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
sakthibalabalamuruga
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
Fransiskeran
 
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
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
B.Kirron Reddi
 
DIGITAL TEXT BOOK
DIGITAL TEXT BOOKDIGITAL TEXT BOOK
DIGITAL TEXT BOOK
shinyvarghese1991
 

Similar to Graphs (20)

Graphs
GraphsGraphs
Graphs
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
 
FCS (graphs).pptx
FCS (graphs).pptxFCS (graphs).pptx
FCS (graphs).pptx
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint paths
 
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHMGRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Graphs
GraphsGraphs
Graphs
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Graphs
GraphsGraphs
Graphs
 
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
 
Graph.pptx
Graph.pptxGraph.pptx
Graph.pptx
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
 
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
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
DIGITAL TEXT BOOK
DIGITAL TEXT BOOKDIGITAL TEXT BOOK
DIGITAL TEXT BOOK
 

More from PRINCE KUMAR

RIP vs OSPF
RIP vs OSPFRIP vs OSPF
RIP vs OSPF
PRINCE KUMAR
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
PRINCE KUMAR
 
Fddi
FddiFddi
Binary search tree
Binary search treeBinary search tree
Binary search tree
PRINCE KUMAR
 
basics of php
 basics of php basics of php
basics of php
PRINCE KUMAR
 
php
phpphp
Connectivity devices
Connectivity devicesConnectivity devices
Connectivity devices
PRINCE KUMAR
 
Tcp ip tutorial
Tcp ip tutorialTcp ip tutorial
Tcp ip tutorial
PRINCE KUMAR
 
OSI layers
OSI layersOSI layers
OSI layers
PRINCE KUMAR
 
NETWORKS & TOPOLOGY
NETWORKS & TOPOLOGYNETWORKS & TOPOLOGY
NETWORKS & TOPOLOGY
PRINCE KUMAR
 
BUILDING WEBSITES ON WORDPRESS
BUILDING WEBSITES ON WORDPRESSBUILDING WEBSITES ON WORDPRESS
BUILDING WEBSITES ON WORDPRESS
PRINCE KUMAR
 

More from PRINCE KUMAR (11)

RIP vs OSPF
RIP vs OSPFRIP vs OSPF
RIP vs OSPF
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
 
Fddi
FddiFddi
Fddi
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
basics of php
 basics of php basics of php
basics of php
 
php
phpphp
php
 
Connectivity devices
Connectivity devicesConnectivity devices
Connectivity devices
 
Tcp ip tutorial
Tcp ip tutorialTcp ip tutorial
Tcp ip tutorial
 
OSI layers
OSI layersOSI layers
OSI layers
 
NETWORKS & TOPOLOGY
NETWORKS & TOPOLOGYNETWORKS & TOPOLOGY
NETWORKS & TOPOLOGY
 
BUILDING WEBSITES ON WORDPRESS
BUILDING WEBSITES ON WORDPRESSBUILDING WEBSITES ON WORDPRESS
BUILDING WEBSITES ON WORDPRESS
 

Recently uploaded

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 

Recently uploaded (20)

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 

Graphs

  • 2. CONTENTS…  INTRODUCTION  START WITH GRAPHS  BASIC TERMINOLOGIES OF GRAPHS  VARIANCE OF GRAPHS  MINIMAL SPANNING TREES  IMPLEMENTATION OF GRAPHS  TRAVERSAL IN GRAPHS: BFS, DFS  KRUSKAL’s ALGORITHM  PRIM’s ALGORITHM  DIZKASTRA ALGORITHM OF SHORTEST PATH
  • 3. INTRODUCTION  This presentation is prepared as a tutorial package on basic graph theory and algorithms and its implementation as a data structure.  It also includes some assignments for practice on algorithms.  Hope this presentation will help the students to understand the concepts of elementary graph theory.  PRINCE KUMAR
  • 4. START WITH GRAPHS  A Graph G(V,E) is defined as tuple where_  V ≠ Φ is a finite set of vertices.  E is set of edges between given vertices.  Ex. G(V,E) is a graph as below_ V = {1,2,3,4,5} E = { {1,2},{2,3},{3,5},{5,4},{1,4},{2,5} } 4 5 1 3 2
  • 5. BASIC TERMINOLOGIES OF GRAPHS  Adjacent  In a graph G(V,E) if u and v V such that { u , v } E then u and v are called adjacent to each other.  Example: in given figure: 2, 3, 4 are adjacent to 5. 4 5 1 3 2
  • 6. BASIC TERMINOLOGIES OF GRAPHS  Degree of a vertex: deg(v)  No. of adjacent to a given vertex is its degree.  Example: in given figure: vertices 2, 3 and 4 are adjacent to vertex 5 so it has degree 3 i.e. deg(5) = 3 . 4 5 1 3 2
  • 7. BASIC TERMINOLOGIES OF GRAPHS  On the basis of degree, vertices are called_  Isolated : 0 degree , e.g. Vertex 6,  Pendent : 1 degree, e.g. Vertex 3,  Odd : odd degree, e.g. Vertex 5,  Even : even degree, e.g. Vertex 1. 4 5 1 3 2 6
  • 8. BASIC TERMINOLOGIES OF GRAPHS  In a graph , The sum of degrees of all the vertices is twice of no. of edges. 𝑖=1 𝑛 deg 𝑉𝑖 = 2|𝐸|
  • 9. VARIANCE OF GRAPHS  COMPLETE GRAPH  A graph G(V,E) is called as complete graph and denoted as K|V| if each vertices have degree |V|-1.  Fig. K5 5 1 2 4 3
  • 10. VARIANCE OF GRAPHS  N-REGULAR GRAPH  A graph G(V,E) is called as N- regular graph if each vertices have degree N.  Fig: 4 Regular Graph 5 1 2 4 3
  • 11. VARIANCE OF GRAPHS  CONNECTED GRAPH  A graph G(V,E) is called connected if in between any two vertices there is a path else it is disconnected. Fig: (a) Connected (b) Disconnected 5 1 2 4 3 5 1 2 4 3 6 6
  • 12. VARIANCE OF GRAPHS  WEIGHTED GRAPH  A graph G(V,E) is called weighted if all the edges in the graph having some cost. 5 1 2 4 3 6 a b c d ef g h
  • 13. VARIANCE OF GRAPHS  SUBGRAPH  A graph S(V’,E’) is called subgraph of graph G(V,E) if V’ is subset of V and E’ is subset of E. 5 1 2 4 3 6 5 1 2 6
  • 14. VARIANCE OF GRAPHS  SPANNING SUBGRAPH  A graph S(V,E’) is called spanning subgraph of graph G(V,E) if E’ is subset of E. 5 1 2 4 3 6 5 1 2 4 3 6
  • 15. VARIANCE OF GRAPHS  TREE  A tree is a connected graph with no cycles. 5 1 2 4 3 6
  • 16. MINIMAL SPANNING TREES  A spanning subgraph of a given graph is called its minimal spanning tree if_  It is a tree.  The total weight on the all the edges in tree is minimal. 5 1 2 4 3 6 2 3 4 1 25 1 3 5 1 2 4 3 6 2 3 1 2 1
  • 17. IMPLEMENTATION OF GRAPHS  A graph is represented in memory by_  Adjacency Matrix : Through 2D arrays.  The adjacency matrix of a graph G(V, E) is defined as _ A(G) = { a i,j } where a i,j = { 1 or w if (vi, vj) E 0 else }
  • 18. IMPLEMENTATION OF GRAPHS  Adjacency matrix for adjacent graph is as below_ 5 1 2 4 3 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0
  • 19. IMPLEMENTATION OF GRAPHS  Adjacency List : Through Linked Lists. 5 1 2 4 3 1 2 3 4 5 2 5 1 3 4 5 2 4 2 3 5 1 2 4
  • 20. TRAVERSALS IN GRAPHS  For searching an element in the graph generally we use two types of traversals as below_  Breadth First Search (BFS): It searches a node in adjacent of a given node and so on. It is used when it is known that the target is near to the source.
  • 21. TRAVERSALS IN GRAPHS  Breadth First Search (BFS) Algorithm:  Let the algorithm assumes A graph G(V,E) is connected is given with source say root( r ).  It maintains a queue to keep track of the nodes which are traversed or which are not.  Traversal status or say color of each node shows whether  It is unseen : WHITE , source is yellow.  It is seen only : YELLOW  It is processed : BLACK
  • 22. TRAVERSALS IN GRAPHS  Put the root ‘r’ into the queue;  While(queue ≠ Φ)  u = dequeuer(queue)  for all v in adj_list of u  if color of v is white then  Color v by Yelow.  Enqueue v in queue.  Color u by black
  • 23. TRAVERSALS IN GRAPHS 5 1 2 4 3 1 2 3 4 5 2 5 1 3 4 5 2 4 2 3 5 1 2 4  Lets travers using BFS algorithm in following graph Let source is 1. QUEUE12 5 3 4
  • 24. TRAVERSALS IN GRAPHS  Depth First Search (DFS): It searches a node in the path starting of a given node and until the end of the path, if the target is not in that path keep backtrack on that path and select a new path from predecessor nodes and so on . It is used when it is known that the target is in the depth of the path starting from the source.
  • 25. TRAVERSALS IN GRAPHS  Depth First Search (BFS) Algorithm:  Let the algorithm assumes A graph G(V,E) is connected is given with source say root( r ).  It maintains a stack to keep track of the nodes which are traversed or which are not .  Traversal status or say color of each node shows whether  It is unseen : WHITE , source is yellow.  It is seen only : YELLOW  It is processed : BLACK
  • 26. TRAVERSALS IN GRAPHS  DFS(G)  for each u G.V  Color u white  Set u.Π as Null  for each u G.V  If color of u is white  VISIT(u)  VISIT(u)  Color u yellow  for each v adj_list of u  If color of v is white  Set v. Π as Null  VISIT(v)  Color u black
  • 27. ASSIGNMENT  Q. Traverse the following given graph using DFS algorithm assuming ‘F’ as a source vertex. A B G F D E C 6 4 3 4 7 5 3 2 1
  • 28. KRUSKAL’S ALGORITHM  This algorithm gives MST for a given graph G(V,E).  Steps  Sort all the edges in ascending order by weight and keep then in a Queue.  Make a spanning subgraph say S(V,Φ) of the given graph with no edges.  Dequeue an edge from the queue and add in the S if it’s not making cycle in the resultant graph.  Follow above step until the queue will be empty.
  • 29. KRUSKAL’S ALGORITHM 5 1 2 4 3 6 2 3 4 1 25 1 3 5 1 2 4 3 6 2 3 1 2 1 2-6 4-3 2-3 1-5 1-2 5-4 5-2 4-2 1 1 2 2 3 3 4 5
  • 30. PRIM’S ALGORITHM  This algorithm also grows a MST of a given graph G(V,E) starting with a source say root (r).  It adds an edge of minimal weight and doesn’t making cycle in the resultant graph to an isolated vertex.  It uses a min heap(Q) structure to grow vertex with minimal distance of connecting edge.  A weight function(w) that gives the weight of the edge between two vertices if exists.  Initial configuration  It assumes that the distance(d) of all other vertices are infinite from the given source and their predecessor(Π) is NULL.
  • 31. PRIM’S ALGORITHM Prims_algo(G,w,r) 1. r.d <= 0 2. Q <= G.V 3. while Q is not empty 1. u <= Extract_min(Q) 2. for each v Adj_List[u] 1. If v Q and w(u,v) < v.d 1. v.Π <= u 2. v.d <= w(u,v)
  • 32. ASSIGNMENT  Q. Grow MST for the following graph using Prim’s algorithm assuming the source is ‘C’. A B G F D E C 6 4 3 4 7 5 3 2 1
  • 33. DIZKASTRA’S ALGORITHM FOR SHORTEST PATH  It gives shortest path to all the target vertices in a given weighted, connected graph G(V,E) with respect to a given source vertex say ‘S’.  It maintains a min heap let Q to maintain the traversal in the graph.  DIJKASTRA_ALGO(G,S)  Initialize the cost of all the target vertices ∞.  Set the predecessor as Null.  Set cost of S 0.  Get a set R = Φ  PUT(Q, G.V)  WHILE Q is not Null  u = Extract(Q)  R = R U u  For each vertex in adj_list of u  Maintain the lesser cost of paths for the adjacents of u.
  • 34. ASSIGNMENT  Q.Find out shortest distances for all the vertices in the following graph assuming the source is ‘C’. A B G F D E C 6 4 3 4 7 5 3 2 1