Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Give a linear-time algorithm for the following task.
Input: A directed acyclic graph G

Does G contain a directed path that touches every vertex exactly once?

Short Answer

Expert verified

Yes, a directed acyclic graph contains a directed path that touches every vertex exactly once in linear-time.

Step by step solution

01

Step 1:

DAG (directed acyclic graph) is a graph which contain directed edges between all the vertices and they are not contain any cycle in graph. This type of graph are called directed acyclic graph.

And G contain a directed path that touches every vertex exactly once, Where G is the graph with no of vertex and edges in it.

The path that touches every vertex exactly once is known as Hamiltonion path.

This algorithm is also shown by topologically ordering the vertices in which traversing the directed acyclic graph in order to get a topological order in a way that the output in decreasing order of post number.

It is also called as backtracking approach.

This is the NP hard problem.

And the theorem is proved by topological sorting

The topological sorting is the traversing of directed acyclic graph in order to get a topological order in a way that the output in decreasing order of post number.

Some properties ofTopological sorting are as follows:

1). The topological orderings is basically a linear ordering of graph if u and v are the vertices of graph there u must be comes before v.

2). It must be a DAG (directed acyclic graph).

3). The given graph should be directed acyclic graph with no cycle.4). Every directed acyclic graph must contain at least one topological ordering.

02

Explanation of algorithm.

As given in the question a directed acyclic graph G contain a directed path that touches every vertex exactly once. In first step check whether the graph has cycle or not. If not then proceed for topological ordering.in the above graph it does not contain any cycle in it then proceed it to the next step.

Now find out the node with indegree zero and consider it as source vertex.

Indegree of any node is the number of edges which directs towards it.

So, here has indegree zero and also contain zero as its indegree. Now select anyone from these vertices.

Fig: Directed acyclic graph

Let as its source vertex.After selection ofselect as its next node because its indegree is. Andremoves source nodes from the graph.

So, after removing both of the vertices, it seems thathas degree and has indegree. Than select, up to here the sequence of graph is .

Than eliminate . now the degree of D and E again. Select any one from them. Select D and after that select E. Now the degree of is zero and the degree of G and H is . After selecting eliminate and again look for degree and the degree of both G and H is 0because no other edge is coming on these nodes let select G and after that select H. Similarly apply this method on each and every vertex.

By this it is clear that it traverses all the vertices exactly once and the sequence is ABCDEFGH.

Hence, A linear-time algorithm for which a directed acyclic graph and that graph contain a directed path that touches every vertex exactly once is proved.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question:Undirected vs. directed connectivity.

(a) Prove that in any connected undirected graph G =(V , E)there is a vertexvโˆˆV whose removal leaves G connected. (Hint: Consider the DFS search tree for G.)

(b) Give an example of a strongly connected directed graph G(V ,E)such that, for everyvโˆˆV, removing v from G leaves a directed graph that is not strongly connected.

(c) In an undirected graph with two connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components 0 such that no addition of one edge can make the graph strongly connected.

The police department in the city of Computopia has made all streets one-way. The mayor contends that there is still a way to drive legally from any intersection in the city to any other intersection, but the opposition is not convinced. A computer program is needed to determine whether the mayor is right. However, the city elections are coming up soon, and there is just enough time to run a linear-time algorithm.

a) Formulate this problem graph-theoretically, and explain why it can indeed be solved in linear time.

(b) Suppose it now turns out that the mayorโ€™s original claim is false. She next claims something weaker: if you start driving from town hall, navigating one-way streets, then no matter where you reach, there is always a way to drive legally back to the town hall. Formulate this weaker property as a graph-theoretic problem, and carefully show how it too can be checked in linear time.

A bipartite graph is a graph G=(V,E)whose vertices can be partitioned into two sets (V=V1V2andV1V2=ฯ•) such that there are no edges between vertices in the same set (for instance, if , then there is no edge between and ).

(a) Give a linear-time algorithm to determine whether an undirected graph is bipartite.

(b) There are many other ways to formulate this property. For instance, an undirected graph is bipartite if and only if it can be colored with just two colors. Prove the following formulation:

an undirected graph is bipartite if and only if it contains no cycles of odd length.

(c) At most how many colors are needed to color in an undirected graph with exactly one odd length?

Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve this problem under the assumption that the graph is strongly connected.)

Two paths in a graph are called edge-disjointif they have no edges in common. Show that in any undirected graph, it is possible to pair up the vertices of odd degree and find paths between each such pair so that all these paths are edge-disjoint.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free