Bound the graph

Let G G be a graph of n n vertices and m m edges. If a depth first search is performed on G G what is the tightest upper bound of the running time?

Details and Assumptions

The graph is represented in adjacency matrix.

O ( n ) O(n) O ( n + m ) O(n+m) O ( n 2 ) O(n^{2}) O ( n m ) O(nm)

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Tom Engelsman
Oct 17, 2020

A Depth-First Search of a graph takes O ( m + n ) O(m+n) time when the graph is represented using adjacency list.

In adjacency matrix representation, graph is represented as an n × n n \times n matrix. To do DFS, for every vertex, we traverse the row corresponding to that vertex to find all adjacent vertices (in adjacency list representation we traverse only the adjacent vertices of the vertex). Therefore time complexity becomes O ( n 2 ) . \boxed{O(n^2)}.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...