edited by
1,343 views
3 votes
3 votes
The square of a directed graph G=(V,E) is the graph G2=(V,E2) such that
(u,v) ∈ E2 if and only G contains a path with at most two edges between u and v.
Describe efficient algorithms for computing G2 from G for both the adjacency-list
and adjacency-matrix representations of G. Analyze the running times of your
algorithms.
edited by

1 Answer

1 votes
1 votes

Adjacency list

If we are given the adjacency list representation of G then we compute the adjacency list representation of transpose of G. This would take O (V+E) time. Now to compute the adjacency list of G-square we first scan through the adjacency list of each vertex in G. Suppose we are scanning the adjacency list of vertex v of graph G. If u belongs to the adjacency list of v then u is also added in the adjacency list of v in G-square.Now we scan through the adjacency list of v in G-transpose. Suppose the list contains the vertices u1,u2,...un. Then u is added to the adjacency list of u1,u2,...,un in G-square. In this way we form the adjacency list of G-square. This would take O(|V||E|+|V|) time because we have to spend |V| time when we process through each edge.

Adjacency matrix 

The time complexity is written wrong it will be O(V3)

edited by

Related questions

2 votes
2 votes
1 answer
1
Manu Thakur asked Aug 18, 2017
1,450 views
Can you please solve this following question further?What will be the time complexity?
1 votes
1 votes
1 answer
2
Manu Thakur asked Aug 14, 2017
1,266 views
Suppose$A = log^{k}n$$B = n^{\epsilon} $ Assume that $ k\geq 1$ and $ \epsilon 0$What is the relation b/w the asymptotic time complexities of A and B?1. A = O(B)2. A =...
0 votes
0 votes
1 answer
3
1 votes
1 votes
2 answers
4
Vishal Upadhayay asked Apr 14, 2017
642 views
HI i am trying to understand what author is trying to explain in the below para. However i understood the meaning of Theta(n^2) but if anyone can explain me this para in ...