DFS on undirected graph complexity -


let's have undirected graph v nodes , e edges.if represent graph adjacency lists,if have representation of edge between x , y,i must have representation of edge between y , x in adjacency list.

i know dfs directed graphs has v+e complexity.for undirected graphs doesn't have v+2*e complexity ,because visit each edge 2 times ?sorry if it's noobish question..i want understand think.thank you,

the complexity expressed o(|v| + |e|) , isn't affected factor of 2.

but factor of 2 there. 1 undirected edge behaves line 2 directed edges. e.g. algorithm (for connected undirected graph) is

visit(v) {   mark(v)   each unmarked w adjacent v, visit(w) } 

the loop consider each edge incident each vertex once. since each undirected edge incident 2 vertices, considered twice!

note undirected dfs doesn't have worry restarting sources. can pick vertex.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -