My Report (&Account)

Directed Acyclic Graph Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)

1. What is the maximum number of possible non zero values in an adjacency matrix of a simple graph with n vertices?

2. The time complexity to calculate the number of edges in a graph whose information in stored in form of an adjacency matrix is ____________

3. Given an adjacency matrix A = [ [0, 1, 1], [1, 0, 1], [1, 1, 0] ], The total no. of ways in which every vertex can walk to itself using 2 edges is ________

4. Adjacency matrix of all graphs are symmetric.

5. Two directed graphs(G and H) are isomorphic if and only if A=PBP-1, where P and A are adjacency matrices of G and H respectively.

6. Given the following program, what will be the 3rd number that'd get printed in the output sequence for the given input?

#include <bits/stdc++.h> 
using namespace std; 
int cur=0; 
int G[10][10]; 
bool visited[10]; 
deque <int> q; 

void fun(int n); 

int main()
{   
	int num=0; 
	int n; 
	cin>>n; 

	for(int i=0;i<n;i++) 
      	for(int j=0;j<n;j++) 
        	cin>>G[i][j]; 

	for(int i=0;i<n;i++) 
        visited[i]=false; 

        fun(n); 
	return 0; 
} 

void fun(int n)
{ 
	cout<<cur<<" "; 
	visited[cur]=true; 
	q.push_back(cur); 
	 
	do
        { 
		for(int j=0;j<n;j++)
                { 
		    if(G[cur][j]==1 && !visited[j])
                    { 
		        q.push_back(j); 
		        cout<<j<<" "; 
		        visited[j]=true; 
	            } 
			 
                 } 
		 
		q.pop_front(); 
		if(!q.empty()) 
		cur=q.front(); 
	 }while(!q.empty()); 
}

Input Sequence:-

9 
0 1 0 0 0 0 0 0 1    
1 0 0 0 0 0 0 0 0 
0 0 0 1 1 1 0 0 1 
0 0 1 0 0 0 0 0 0 
0 0 1 0 0 0 0 1 0 
0 0 1 0 0 0 1 0 0 
0 0 0 0 0 1 0 1 1 
0 0 0 0 1 0 1 0 0 
1 0 1 0 0 0 1 0 0 

7. In the given connected graph G, what is the value of rad(G) and diam(G)?

8. Which of these adjacency matrices represents a simple graph?

9. On which of the following statements does the time complexity of checking if an edge exists between two particular vertices is not, depends?

10. The number of elements in the adjacency matrix of a graph having 7 vertices is __________


 

Start practicing “1000 MCQs on Data Structure”, and once you are ready, you can take tests on all topics by attempting our “Data Structure Test Series”.

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.