Question: We again consider directed graphs, with nodes 1..n and with a edges (this time without weights). Our aim is now to reverse the graph; that

 We again consider directed graphs, with nodes 1..n and with a

We again consider directed graphs, with nodes 1..n and with a edges (this time without weights). Our aim is now to reverse the graph; that is, from a given graph (V, E) we want to construct a graph (V, E) such that for all i and k in V, E contains an edge fro to k iff E contains an edge from k toi 1. (10p) First assume the graph is represented as an adjacency matrix A, with the boolean A(i, k) true iff the graph has an edge fromi to k. Write an algorithm to implement this specification, and analyze its running time, as a function of n and of a 2. (5p) Next assume the graph is represented as adjacency lists L (that is, for cachi e 1..n, the list L[i] contains the targets of edges with source i). Then the specification can be implemented by the algorithm below (where CONs adds an edge to a list of edges) whose running time, as a function of n and of a, you must analyze. for k 1 to n ,[A] EMPTY or i 1 to n foreach k E Li

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!