analysis & design of algorithm
TRANSCRIPT
![Page 1: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/1.jpg)
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
![Page 2: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/2.jpg)
Name of the student BHAM RAHELA A
(150063131003) AGRAVAT DIVYA H
(150063131001) BODRA BHUMI A
(150063131004) CHODVADIYA JYOTSNA B
(150063131005)
![Page 3: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/3.jpg)
Exploring Graphs
Traversing a Graph Breadth First search(BFS) Depth first search(DFS)
Topological sort Connected component
![Page 4: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/4.jpg)
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
![Page 5: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/5.jpg)
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
![Page 6: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/6.jpg)
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)
![Page 7: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/7.jpg)
![Page 8: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/8.jpg)
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.
![Page 9: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/9.jpg)
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.
![Page 10: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/10.jpg)
BFS
![Page 11: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/11.jpg)
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
![Page 12: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/12.jpg)
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
![Page 13: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/13.jpg)
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
![Page 14: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/14.jpg)
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
![Page 15: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/15.jpg)
Topological sort
![Page 16: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/16.jpg)
Topological sort
A topological sorting of this graph is:0-1-2-3-4-5
![Page 17: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/17.jpg)
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
![Page 18: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/18.jpg)
ARTICULATION POINT
1
After removing articulation
point 1 two disjoint graph
![Page 19: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/19.jpg)
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.
![Page 20: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/20.jpg)
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.
![Page 21: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/21.jpg)
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
![Page 22: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/22.jpg)
references
www.hackerearth.com www.csie.ntu.edu.tw www.boost.org www.khanacademy.org
![Page 23: Analysis & design of algorithm](https://reader036.vdocuments.site/reader036/viewer/2022062412/58acc1231a28abd3048b5573/html5/thumbnails/23.jpg)
THANK YOU
ANY QUESTION???