analysis & design of algorithm

23
ANALYSIS & DESIGN OF ALGORITHM Bhagwan Mahavir College Of Engineering & Technology Class: S.Y.(5 rd Sem) Department: Computer Science Subject: Analysis & Design of Algorithms Submitted To: Twinkal mam

Upload: rahela-bham

Post on 22-Feb-2017

49 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Analysis & design of algorithm

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

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

Exploring Graphs

Traversing a Graph Breadth First search(BFS) Depth first search(DFS)

Topological sort Connected component

Page 4: Analysis & design of algorithm

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

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

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
Page 8: Analysis & design of algorithm

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

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

BFS

Page 11: Analysis & design of algorithm

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

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

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

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

Topological sort

Page 16: Analysis & design of algorithm

Topological sort

A topological sorting of this graph is:0-1-2-3-4-5

Page 17: Analysis & design of algorithm

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

ARTICULATION POINT

1

After removing articulation

point 1 two disjoint graph

Page 19: Analysis & design of algorithm

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

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

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

references

www.hackerearth.com www.csie.ntu.edu.tw www.boost.org www.khanacademy.org

Page 23: Analysis & design of algorithm

THANK YOU

ANY QUESTION???