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.

Design a linear-time algorithm which, given an undirected graph G and a particular edge ein it, determines whetherGhas a cycle containing.

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.

Let S be a finite set. A binary relation on S is simply a collection R of ordered pairs(x,y)S×S. . 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 “has the same birthday as” is an equivalence relation, whereas “is 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.)

As in the previous problem, you are given a binary tree T=(V,E) with designated root node. In addition, there is an array x[.]with a value for each node in V Define a new array z[.]as follows: for each uV,

z[u]=the maximum of the x-values associated with u’s descendants.

Give a linear-time algorithm that calculates the entire z-array.

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