The time complexity to test whether a graph is bipartite or not is said to be _______ using depth first search.

Nguyễn Trà

New member
The time complexity to test whether a graph is bipartite or not is said to be _______ using depth first search.
A. O(n$^{3}$)
B. linear time
C. O(1)
D. O(nlogn)
 
Answer: b
Explanation: It is possible to test whether a graph is bipartite, and to return either a two-coloring (if it is bipartite) or an odd cycle (if it is not) in linear time i.e, O(n) using depth first search. In case of the intersection of n line segments or other simple shapes in the Euclidean graph, it is possible to test whether the graph is bipartite and it will return either a two-coloring or an odd cycle in time O(nlogn), even though the graph itself has up to O(n$^{2}$) edges.
 

Tìm kiếm

Back
Top