The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+1 vote

An undirected graph can be converted into a directed graph by choosing a direction for every edge. Here is an example:

Show that for every undirected graph, there is a way of choosing directions for its edges so that the resulting directed graph has no directed cycles.

in Graph Theory by Veteran (98.3k points)
edited by | 151 views

1 Answer

+2 votes
Best answer
Select any random vertex and start BFS algorithm such that if you are at vertex $u$ and going to vertex $v$ direction of the edge will be from $u$ to $v, u\rightarrow v.$ Maintain a data structure $\text{visited[i]}$ which keeps track of unvisited edge -- if the edge $e_k$ is visited we do not perform BFS. This will create a directed graph with no back edge. Complexity -- $O(V+E)$
by Boss (18k points)
selected by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,807 questions
54,727 answers
79,845 users