Let G (V, E) be a directed graph with n vertices. A path from vi to vj in G is…

2003

Let G (V, E) be a directed graph with n vertices. A path from vi to vj in G is sequence of vertices (vi, vi+1, ......., vj) such that (vk, vk+1) ∈ E for all k in i through j - 1. A simple path is a path in which no vertex appears more than once. Let A be an n x n array initialized as follow

image.png

Consider the following algorithm.

for i = 1 to n
   for j = 1 to n
      for k = 1 to n
         A [j , k] = max (A[j, k] (A[j, i] + A [i, k]); 

Which of the following statements is necessarily true for all j and k after terminal of the above algorithm ?

  1. A.

    A[j, k] ≤ n

  2. B.

    If A[j, k] ≥ n - 1, then G has a Hamiltonian cycle

  3. C.

    If there exists a path from j to k, A[j, k] contains the longest path lens from j to k

  4. D.

    If there exists a path from j to k, every simple path from j to k contain most A[j, k] edges

Attempted by 34 students.

Show answer & explanation

Correct answer: D

The algorithm is a variant of the Floyd-Warshall algorithm that computes the maximum number of edges in any simple path from vertex j to vertex k. Initially, A[j,k] is 1 if there is a direct edge from j to k, and 0 otherwise. The update rule A[j,k] = max(A[j,k], A[j,i] + A[i,k]) effectively computes the longest simple path (in terms of edge count) between any two vertices. After termination, A[j,k] represents the maximum number of edges in a simple path from j to k. Therefore, if A[j,k] = m, then every simple path from j to k has at most m edges. This makes statement D necessarily true.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir