adplus-dvertising
frame-decoration

Question

What would be the output of the following C++ program if the given input is

0 0 0 1 1

0 0 0 0 1

0 0 0 1 0

1 0 1 0 0

1 1 0 0 0
#include <bits/stdc++.h>
using namespace std;
bool visited[5];
int G[5][5];
 
void fun(int i)
{
	cout<<i<<" ";
	visited[i]=true;
	for(int j=0;j<5;j++)
		if(!visited[j]&&G[i][j]==1)
			fun(j);
}
 
int main()
{   
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			cin>>G[i][j];
 
	for(int i=0;i<5;i++)
		visited[i]=0;
 
	fun(0);
		return 0;
}

a.

0 2 3 1 4

b.

0 3 2 4 1

c.

0 2 3 4 1

d.

0 3 2 1 4

Answer: (b).0 3 2 4 1

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What would be the output of the following C++ program if the given input is 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0

Similar Questions

Discover Related MCQs

Q. Which of the given statement is true?

Q. For any two different vertices u and v of an Acyclic Directed Graph if v is reachable from u, u is also reachable from v?

Q. What is the value of the sum of the minimum in-degree and maximum out-degree of an Directed Acyclic Graph?

Q. In which of the following does a Directed Acyclic Word Graph finds its application in?

Q. What is time complexity to check if a string(length S1) is a substring of another string(length S2) stored in a Directed Acyclic Word Graph, given S2 is greater than S1?

Q. In which of the following case does a Propositional Directed Acyclic Graph is used for?

Q. Every Binary Decision Diagram is also a Propositional Directed Acyclic Graph.

Q. In a Propositional Directed Acyclic Graph Leaves maybe labelled with a boolean variable.

Q. Given Adjacency matrices determine which of them are PseudoGraphs?

i) {{1,0} {0,1}}

ii) {{0,1}{1,0}}

iii) {{0,0,1}{0,1,0}{1,0,0}}

Q. All undirected Multigraphs contain eulerian cycles.

Q. Determine the number of vertices for the given Graph or Multigraph?
G is a 4-regular Graph having 12 edges.

Q. Which of the following statement is true.

Q. Given Adjacency matrices determine which of them are PseudoGraphs?
i) {{1,0} {0,1}}

ii) {{0,1}{1,0}}

iii) {{0,0,1}{0,1,0}{1,0,0}}

Q. Possible number of labelled simple Directed, Pseudo and Multigarphs exist having 2 vertices?

Q. Which of the following is a HyperGraph, where V is the set of vertices, E is the set of edges?

Q. What would be the Incidence Matrix of the given HyperGraph?
V = {x,y,z} E = {{x,y}{y}{x,z}{z,y}}

Q. What is the degree sequence of the given HyperGraph, in non-increasing order.
V = {v1,v2,v3,v4,v5,v6} E = {{v1,v4,v5} {v2,v3,v4,v5} {v2} {v1} {v1,v6}}

Q. MultiGraphs having self-loops are called PseudoGraphs?

Q. Binary Decision Diagram is a type of __________

Q. In which of the following case does a Binary Decision Diagram is used for?