analysis & design of algorithm
TRANSCRIPT
ANALYSIS & DESIGN OF ALGORITHM
Bhagwan Mahavir College Of Engineering & Technology
Class: S.Y.(5rd Sem)Department: Computer Science Subject: Analysis & Design of AlgorithmsSubmitted To: Twinkal mam
Name of the student BHAM RAHELA A
(150063131003) AGRAVAT DIVYA H
(150063131001) BODRA BHUMI A
(150063131004) CHODVADIYA JYOTSNA B
(150063131005)
Exploring Graphs
Traversing a Graph Breadth First search(BFS) Depth first search(DFS)
Topological sort Connected component
Traversing a Graph 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: Inorder Traversal Preorder Traversal Postorder Traversal
DFS
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
DFSDFS-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)
BFS 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(Breadth First search)
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.
BFS
BFSnode 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 node 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
node Level[ node ]
s(source node)
0
1 12 13 24 25 26 27 3
Topological sort
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
Topological sort
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
Topological sort
Topological sort
A topological sorting of this graph is:0-1-2-3-4-5
ARTICULATION POINT
Articulation point: An Articulation point in a connected graph is a vertex that, if delete, would break the graph into two or more pieces
ARTICULATION POINT
1
After removing articulation
point 1 two disjoint graph
BI-CONNECTED COMPONENTSBiconnected 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.
BI-CONNECTED COMPONENTSBiconnected 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.
BI-CONNECTED COMPONENTS
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
references
www.hackerearth.com www.csie.ntu.edu.tw www.boost.org www.khanacademy.org
THANK YOU
ANY QUESTION???