/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q24E Give a linear-time algorithm for... [FREE SOLUTION] | 91影视

91影视

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 91影视!

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

In an undirected graph, the degreed(u) of a vertex u is the number of neighbours u is the number of neighbors u has, or equivalently, the number of edges incident upon it. In a directed graph, we distinguish between the indegreedin(u), which is the number of edges into u, and the outdegreedout(u), the number of the edges leaving u.

(a) Show that in an undirected graph, role="math" localid="1658908755010" uevd(u)=2|E|

(b) Use part (a) to show that in an undirected graph, there must be an even number of vertices whose degree is odd.

(c) Does a similar statement hold for the number of vertices with odd indegree in a directed graph?

Let S be a finite set. A binary relation on S is simply a collection R of ordered pairs(x,y)SS. . For instance, S might be a set of people, and each such pair (x,y)R might mean 鈥 x knows y 鈥.

An equivalence relationis a binary relation which satisfies three properties:

  • Reflexivity: localid="1659006645990" (x,y)R for all XS
  • Symmetry: If (x,y)R then (y,x)R
  • Transitivity: if (x,y)R and (y,z)R then localid="1659006784500" (x,Z)R

For instance, the binary relation 鈥渉as the same birthday as鈥 is an equivalence relation, whereas 鈥渋s the father of鈥 is not, since it violates all three properties.

Show that an equivalence relation partition set S into disjoint groups S1,S2,,Sk (in other words, S=S1S2SkandSiSj=forallij ) such that:

  • Any two members of a group are related, that is, (x,y)R for any localid="1659006702579" (x,y)Si, for any i .
  • Members of different groups are not related, that is, for all ij, for all localid="1659006762355" xSi andySi, we have (x,Z)R.

(Hint: Represent an equivalence relation by an undirected graph.)

Infinite paths.Let G=(V,E) be a directed graph with a designated 鈥渟tart vertex鈥 sV,asetVGV, a set of 鈥済ood鈥 vertices, and a set VBV of 鈥渂ad鈥 vertices. An infinite trace of is an infinite sequence of vertices viV such that (1)v0=s, and (2) for all i0, (vi,vi+1)E. That is, p is an infinite path in G starting at vertex s. Since the setV of vertices is finite, every infinite trace of Gmust visit some vertices infinitely often.

  1. If p is an infinite trace, let Inf(p)V be the set of vertices that occur infinitely often in p. Show that Inf(p) is a subset of a strongly connected component of G.
  2. Describe an algorithm that determines if role="math" G has an infinite trace.
  3. Describe an algorithm that determines if G has an infinite trace that visits some good vertex in VG infinitely often.
  4. Describe an algorithm that determines if role="math" localid="1659627728759" G has an infinite trace that visits some good vertex in VG infinitely often, but visits no bad vertex in VB infinitely often.

For each node in an undirected graph, let twodegreeube the sum of the degrees of鈥檚 neighbors. Show how to compute the entire array of two degree. values in linear time, given a graph in adjacency list format

Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear.

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.