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

Run the DFS-based topological ordering algorithm on the following graph. Whenever you have a choice of vertices to explore, always pick the one that is alphabetically first.

(a) Indicate the pre and post numbers of the nodes.

(b) What are the sources and sinks of the graph?

(c) What topological ordering is found by the algorithm?

(d) How many topological orderings does this graph have?

Short Answer

Expert verified

(a). The pre and post numbers of the nodes is:A(1,14),B(15,16),C(2,13),D(3,10),E(5,6),F(4,9),G(5,6),H(7,8)

(b) Sources of the graph:AandB

Sink of the graph:GandH

(c) The topological ordering isB,A,C,E,D,F,H,G

(d) The number of topological orderings of the graph is 8.

Step by step solution

01

 Explain Depth First Search based topological ordering algorithm.

Depth First Search (DFS) is an application of graph traversal. It traverses downwards and uses the stack as a data structure, through this it traverses all vertices in downward direction one by one. And the topological orderings is basically a linear ordering of graph if and are the vertices of graph there u must be comes before. And the graph must be directed acyclic graph.

The edge obtained by traversing while using depth first search is called its tree edge. The edge(u,v) where u is descendant and it is not part of depth first search is called forward edge. The edge(u,v)where u is ancestor and it is not part of depth first search is called forward edge.

02

Find pre and post number.

(a)

The pre and post numbers of each vertex A while traversing is A1,14where 1 is pre vertex and 14 is post vertex. All the pre order number is obtained before obtaining post order number. The pre and post number of each vertex of the graph is ,A(1,14),B(15,16),C(2,13),D(3,10),E(5,6),F(4,9),G(5,6),H(7,8)

Hence, A(1,14),B(15,16),C(2,13),D(3,10),E(5,6),F(4,9),G(5,6),H(7,8)is the pre and post order of all vertices in the given graph.

03

Find the source and sink of the graph.

(b)

The source of the graph is a starting vertex and the source contain in degree of at least 1 .The sink of the graph is also called terminal. Sink is a vertex from which no other node or edge is attached or it is a ending point.Sink contains out-degree of 0.Sometimes if in a graph only one vertex is present so, it act as both source and sink.

The source vertices areAandBand

The sinks are GandH.

The final solution is:

Source =A,B

Sink =G,H

04

Find the topological order in the graph.

(c)

The topological ordering is found by the algorithm is the output in decreasing order of post number that is B,A,C,E,D,F,H,G. Here while traversing the directed acyclic graph in order to get a topological order in a way that the output is the decreasing order of post number and preference is given to alphabetical order.

Select source vertex as B with in order degree zero. Then select A and then take C as the next node while traversing in depth first search. From C another option with in-degree zero are D and E . Consider E as the next vertex because it follows depth first search and decreasing order of post number. Then after E, select F as our next node again search for degree here now the degree of G and H is 1 . Select H and then select G.

Thus, the final sequence isB,A,C,E,D,F,H,G .

05

Find the number of topological ordering in the given graph

(d)

1) The topological ordering 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 (directed acyclic graph)

3) The given graph should be DAG (directed acyclic graph)

4) The graph must not contain any cycle.

5) Every DAG (directed acyclic graph) have at least (directed acyclic graph) onetopological ordering.

The given graph is:

In this graph topological orders are possible.

In first step check whether the graph has cycle or not. If not then proceed for topological ordering and find out the node with indegree zero and consider it as source vertex. Starting with the source there are two nodes with in degreethat are A and B .

Select A then B after that it seems that C has degree zero D and 1 has degree up to here the sequence of graph is ABC .Then eliminate C . Now the degree of D and E are 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 .

Now the sequence is,ABCDEFGH

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

ABCDEFGHABCEDFGHABCEDFHGABCDEFHG

Now the next possibility is when the source node asB and after that selectAas 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 b C is zero. So, select C Again D and E are the two options 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

So, 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

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?

Perform a depth-first search on the following graph; whenever there’s a choice of vertices, pick the one that is alphabetically first. Classify each edge as a tree edge or back edge, and give the pre and post number of each vertex.

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.)

You are given a directed graph in which each nodeuV, has an associated pricepu which is a positive integer. Define the array cost as follows: for each uV,

cost[u] = price of the cheapest node reachable fromu (includingu itself).

For instance, in the graph below (with prices shown for each vertex), the cost values of the nodes A,B,C,D,E,Fare2,1,4,1,4,5,respectively.

Your goal is to design an algorithm that fills in the entire cost array (i.e., for all vertices).

(a) Give a linear-time algorithm that works for directed acyclic graphs.

(b) Extend this to a linear-time algorithm that works for all directed graphs.

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.

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