The chapter suggests an alternative algorithm for linearization (topological sorting), which repeatedly removes source nodes from the graph (page 101). Show that this algorithm can be implemented in linear time.

Short Answer

Expert verified

Answer is not given by the question.

Step by step solution

01

Linearization topology sorting.

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 ordering is basically a linear ordering of graph if u and v are the vertices of graph their 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 onetopological ordering.

5). It takes linear time for processing.

02

Proving the algorithm.

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.

03

Find the degree of the vertices.

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

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

So, here A has in degree zero and B also contain zero as its in degree. Now select anyone from these vertices.

Let A as its source vertex.

04

Find the cycle and degree.

After selection of A select as its next node because its in degree is zero. And removes source nodes from the graph.

So, after removing both of the vertices, it seems that C has degree 0 and D has 1 in degree. Than select C , up to here the sequence of graph is ABC .

Than eliminate C .now the degree of D and E again zero. Select any one from them. Select D and after that select E. Now the degree of F is zero and the degree of G and H is 1 . After selecting F eliminate F and again look for degree and the degree of both G and H is zero because 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.

Then the sequence is, ABCDEFGH

05

Evaluate all possible cases.

Similarly, by selectingas first edge other three case is possible through this they are as follows,

ABCDEFGHABCEDFGHABCEDFHGABCDEFHG

Now the next possibility is when the source node as B and after that select A as the next vertex now again find the degree of the each and every node in the graph after eliminating both vertex A and B then it is clear the new degree of C is zero. So, select C . Again D and E are the two option select each of them one by one for showing various possibility.

Then select in one case EFGH .

The other four cases are as follows:

BACEDFHGBACDEFHGBACDEFGHBACEDFGH

It takes linear time for processing.And, there are 8 topological orders are possible in the graph.

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

Biconnected componentsLet G=(V,E) be an undirected graph. For any two edgese,e'E,, we’ll saye:e'if eithere=e'or there is a (simple) cycle containing both e and e'.

a. Show that : is an equivalence relation (recall Exercise 3.29) on the edges.

The equivalence classes into which this relation partitions the edges are called the biconnected components of G . A bridge is an edge which is in a biconnected component all by itself.

A separating vertexis a vertex whose removal disconnects the graph.

b. Partition the edges of the graph below into biconnected components, and identify the bridges and separating vertices.

Not only do biconnected components partition the edges of the graph, they almost partition the vertices in the following sense.

c. Associate with each biconnected component all the vertices that are endpoints of its edges. Show that the vertices corresponding to two different biconnected components are either disjoint or intersect in a single separating vertex.

d. Collapse each biconnected component into a single meta-node, and retain individual nodes for each separating vertex. (So there are edges between each component node and its separating vertices.) Show that the resulting graph is a tree.

DFS can be used to identify the biconnected components, bridges, and separating vertices of a graph in linear time.

e. Show that the root of the DFS tree is a separating vertex if and only if it has more than one child in the tree.

f. Show that a non-root vertex v of the DFS tree is a separating vertex if and only if it has a child v' none of whose descendants (including itself) has a back edge to a proper ancestor of v .

g. For each vertex u define:

Iowu=minpreuprew

Where (v,w) is a back edge for some descendant v of u.

(h) Show how to compute all separating vertices, bridges, and biconnected components of a graph in linear time.

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?

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.

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.

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?

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