/*! 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} Q5E The reverse of a directed graph ... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

The reverse of a directed graph G = (V,E) is another directed graphGR=(V,ER) on the same vertex set, but with all edges reversed that is,ER={(v,u):(u,v)∈E} . Give a linear-time algorithm for computing the reverse of a graph in adjacency list format.

Short Answer

Expert verified

A linear-time algorithm is used for reversalGR=(V,ER) of a directed graph G=(V,E) by using an adjacency list is proved.

Step by step solution

01

Step 1: Adjacency List

The representation of the list contains an array known as an adjacency list.

An adjacency list consists of a linked list for each vertex.

The size of the array is the same as the number of vertices in it.

If the graph is an undirected graph, then each edge appears twice in the list.

Each list consists of the name of the vertex.

Reversing the adjacency lists of a Directed Graph can be done in linear time

Order of complexity will be O(V+E).

02

Reversal of graph takes linear time

Consider directed graph G =(V,E) which has vertices and edges. Firstly, perform the reversal of graph that is GR=(V,ER). Let’s perform the reverse of the graph by changing the directions of edges that are connected to the vertex. After the reversal of the graph all the edges reversed that is, E={(v,u):(u,v)∈E}is shown in the figure below.

The degree of a node in a directed graph is the number of edges connected to the node. For each node in a graph there is a list. It will take a linear time in adjacency list and it always assign a degree value to each node. And while iterating from the list the total number of the vertex is the degree of the vertex. After reversal of the graph take the adjacency list and put all the vertices in the adjacency list one by one.

Draw the Reversal of the directed graph:

Adjacency list for directed graph is shown below:

As in this directed graph it contains five vertices so the size of the adjacency list here is five. After that as known that the graph is the directed graph so, the vertex connected by edges to the other vertex writes only those vertices in front of the list that take a temp as a variable for storing the temporary variable while traversing the directed graph to the adjacency list. Like here vertex one is connected by vertex two and vertex two is connected to vertex three like that mark in the adjacency list. Here each vertex has one linked list. After performing this step now, the graph contained the adjacency list. Where the time complexity is O (V+E) . Hence it is proved that this is a linear-time algorithm that takes O (V+E) time.

03

Prove by using example

Now take another example where a graph G=(V,E)which have vertices and edges. Firstly, perform the reversal of graph that is GR=(V,ER). Draw a directed graph for 5 vertices.

Let’s perform reverse of graph by changing the directions of edges that are connected to the vertex. After reversal of graph all the edges reversed that isE={(v,u):(u,v)∈E},is shown in the figure below. Here five vertices and every edge are bidirectional so here in this example each vertex has a degree of two.

The indegree of each vertex is two and the outdegree of each vertex is also two. Now after performing the reversal of graph then put the vertices into the adjacency list. Where this list contain array named as adjacency list and it consists of a linked list for each vertex.

Here the reversing the adjacency lists of a Directed Graph can be done in linear time. And the order of complexity will be O (V+E).

Hence it is proved that a linear-time algorithm is used for computing the reversal of a graph by using adjacency list.

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

Give an efficient algorithm which takes as input a directed graph G(V,E)and determines whether or not there is a vertexs∈V from which all other vertices are reachable.

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?

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.

Rewrite the explore procedure (Figure 3.3) so that it is non-recursive (that is, explicitly use a stack). The calls to pre visit and post visit should be positioned so that they have the same effect as in the recursive procedure.

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.