Bhagwan Mahavir College Of Engineering &Technology
ļ‚” BHAM RAHELA A (150063131003)
ļ‚” AGRAVAT DIVYA H (150063131001)
ļ‚” BODRA BHUMI A (150063131004)
ļ‚” CHODVADIYA JYOTSNA B (150063131005)
ļ‚” Traversing a Graph
ļ‚§ Breadth First search(BFS)
ļ‚§ Depth first search(DFS)
ļ‚” Topological sort
ļ‚” Connected component
ļ‚” A graph search (or traversal) technique visits every
node exactly one in a systematic fashion.
ļ‚” Two standard graph search techniques have been
widely used:
ļ‚§ DFS
ļ‚§ BFS
ļ‚” In the case of rooted binary trees, three recursive
traversal techniques are widely used:
ļ‚§ InorderTraversal
ļ‚§ PreorderTraversal
ļ‚§ PostorderTraversal
ļ‚” Can be used to attempt to visit all nodes of a
graph in a systematic manner
ļ‚” The basic idea behind this algorithm is that it
traverses the graph using recursion
ļ‚” In DFS, go as far as possible along a single
path until reach a dead end (a vertex with no
edge out or no neighbor unexplored) then
backtrack
DFS-iterative (G, s): //where G is graph and s is source vertex.
let S be stack
S.push( s ) // inserting s in stack
mark s as visited.
while ( S is not empty): // pop a vertex from stack to visit next
v = S.top( )
S.pop( )
//push all the neighbours of v in stack that are not visited
for all neighbours w of v in Graph G:
If w is not visited :
S.push( w )
mark w as visited DFS-recursive(G, s):
mark s as visited
for all neighbours w of s in Graph G:
if w is not visited:
DFS-recursive(G, w)
ļ‚” In BFS, one explore a graph level by level away (explore all
neighbors first and then move on)
The breath first forest is a collection of a tree in which
the traversal starting vertex serve as a root of first tree.
ļ‚” Rule 1 āˆ’Visit unvisited vertex. Mark it visited.
Display it. Insert it in a queue.
ļ‚” Rule 2 āˆ’ If no vertex found, remove the first
vertex from queue.
ļ‚” Rule 3 āˆ’ Repeat Rule 1 and Rule 2 until queue
is empty.
BFS (G, s)
//where G is graph and s is source node.
let Q be queue.
Q.enqueue( s )
//inserting s in queue until all its neighbor vertices are marked.
mark s as visited.
while ( Q is not empty)
// removing that vertex from queue, whose neighbor will be visited now.
v = Q.dequeue( )
//processing all the neighbors of v
for all neighbors w of v in Graph G
if w is not visited
Q.enqueue(w)
//stores w in Q to further visit its neighbor
mark w as visited.
node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3
node Level
[ node ]
s(source node) 0
1 1
2 1
3 2
4 2
5 2
6 2
7 3
ļ‚” Topological sorting of vertices of
a Directed Acyclic Graph is an
ordering of the vertices
v1,v2,...vn in such a way, that if
there is an edge directed
towards vertex vj from vertex vi,
then vi comes before vj
ļ‚” To understand the sorting with the help of
two algorithm
ļ‚§ DFS based algorithm (using stack)
ļ‚§ Source removal algorithm (removing source)
ļ‚” Use divide and conquer method
ļ‚” Find node with no incoming vertex and
remove it with its out going edges(if more
then such vertex then select randomly)
ļ‚” Note that vertex which is deleted
ļ‚” All the recorded vertexes gives
topologically sorted list
ļ‚”A topological sorting
of this graph is:
0-1-2-3-4-5
ļ‚” Articulation point: An Articulation point in a
connected graph is a vertex that, if delete,
would break the graph into two or more
pieces
1
After removing articulation point 1
two disjoint graph
ļ‚” Biconnected graph: A graph with no
articulation point called biconnected. In
other words, a graph is biconnected if and
only if any vertex is deleted, the graph
remains connected.
ļ‚” Biconnected component:
A biconnected component of a graph is a
maximal biconnected subgraph- a
biconnected subgraph that is not properly
contained in a larger biconnected
subgraph.
A graph that is not biconnected can divide
into biconnected components, sets of
nodes mutually accessible via two distinct
paths.
ļ‚” Steps to find articulation points
ļ‚” The root of the DFS tree is an articulation
point.
ļ‚” A leaf node of DFS tree is not an articulation
point
ļ‚” If u is an internal node then it is not
articulation point if and only if from every
child w and u is possible to reach an ancestor
of u using only a pathmade up of descendant
of w and back edge
ļ‚” www.hackerearth.com
ļ‚” www.csie.ntu.edu.tw
ļ‚” www.boost.org
ļ‚” www.khanacademy.org
Analysis & design of algorithm

Analysis & design of algorithm

  • 1.
    Bhagwan Mahavir CollegeOf Engineering &Technology
  • 2.
    ļ‚” BHAM RAHELAA (150063131003) ļ‚” AGRAVAT DIVYA H (150063131001) ļ‚” BODRA BHUMI A (150063131004) ļ‚” CHODVADIYA JYOTSNA B (150063131005)
  • 3.
    ļ‚” Traversing aGraph ļ‚§ Breadth First search(BFS) ļ‚§ Depth first search(DFS) ļ‚” Topological sort ļ‚” Connected component
  • 4.
    ļ‚” A graphsearch (or traversal) technique visits every node exactly one in a systematic fashion. ļ‚” Two standard graph search techniques have been widely used: ļ‚§ DFS ļ‚§ BFS ļ‚” In the case of rooted binary trees, three recursive traversal techniques are widely used: ļ‚§ InorderTraversal ļ‚§ PreorderTraversal ļ‚§ PostorderTraversal
  • 5.
    ļ‚” Can beused to attempt to visit all nodes of a graph in a systematic manner ļ‚” The basic idea behind this algorithm is that it traverses the graph using recursion ļ‚” In DFS, go as far as possible along a single path until reach a dead end (a vertex with no edge out or no neighbor unexplored) then backtrack
  • 6.
    DFS-iterative (G, s)://where G is graph and s is source vertex. let S be stack S.push( s ) // inserting s in stack mark s as visited. while ( S is not empty): // pop a vertex from stack to visit next v = S.top( ) S.pop( ) //push all the neighbours of v in stack that are not visited for all neighbours w of v in Graph G: If w is not visited : S.push( w ) mark w as visited DFS-recursive(G, s): mark s as visited for all neighbours w of s in Graph G: if w is not visited: DFS-recursive(G, w)
  • 8.
    ļ‚” In BFS,one explore a graph level by level away (explore all neighbors first and then move on) The breath first forest is a collection of a tree in which the traversal starting vertex serve as a root of first tree. ļ‚” Rule 1 āˆ’Visit unvisited vertex. Mark it visited. Display it. Insert it in a queue. ļ‚” Rule 2 āˆ’ If no vertex found, remove the first vertex from queue. ļ‚” Rule 3 āˆ’ Repeat Rule 1 and Rule 2 until queue is empty.
  • 9.
    BFS (G, s) //whereG is graph and s is source node. let Q be queue. Q.enqueue( s ) //inserting s in queue until all its neighbor vertices are marked. mark s as visited. while ( Q is not empty) // removing that vertex from queue, whose neighbor will be visited now. v = Q.dequeue( ) //processing all the neighbors of v for all neighbors w of v in Graph G if w is not visited Q.enqueue(w) //stores w in Q to further visit its neighbor mark w as visited.
  • 11.
    node level[ node] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3node level[ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3 node Level [ node ] s(source node) 0 1 1 2 1 3 2 4 2 5 2 6 2 7 3
  • 12.
    ļ‚” Topological sortingof vertices of a Directed Acyclic Graph is an ordering of the vertices v1,v2,...vn in such a way, that if there is an edge directed towards vertex vj from vertex vi, then vi comes before vj
  • 13.
    ļ‚” To understandthe sorting with the help of two algorithm ļ‚§ DFS based algorithm (using stack) ļ‚§ Source removal algorithm (removing source) ļ‚” Use divide and conquer method
  • 14.
    ļ‚” Find nodewith no incoming vertex and remove it with its out going edges(if more then such vertex then select randomly) ļ‚” Note that vertex which is deleted ļ‚” All the recorded vertexes gives topologically sorted list
  • 16.
    ļ‚”A topological sorting ofthis graph is: 0-1-2-3-4-5
  • 17.
    ļ‚” Articulation point:An Articulation point in a connected graph is a vertex that, if delete, would break the graph into two or more pieces
  • 18.
    1 After removing articulationpoint 1 two disjoint graph
  • 19.
    ļ‚” Biconnected graph:A graph with no articulation point called biconnected. In other words, a graph is biconnected if and only if any vertex is deleted, the graph remains connected.
  • 20.
    ļ‚” Biconnected component: Abiconnected component of a graph is a maximal biconnected subgraph- a biconnected subgraph that is not properly contained in a larger biconnected subgraph. A graph that is not biconnected can divide into biconnected components, sets of nodes mutually accessible via two distinct paths.
  • 21.
    ļ‚” Steps tofind articulation points ļ‚” The root of the DFS tree is an articulation point. ļ‚” A leaf node of DFS tree is not an articulation point ļ‚” If u is an internal node then it is not articulation point if and only if from every child w and u is possible to reach an ancestor of u using only a pathmade up of descendant of w and back edge
  • 22.
    ļ‚” www.hackerearth.com ļ‚” www.csie.ntu.edu.tw ļ‚”www.boost.org ļ‚” www.khanacademy.org