Given The Following Program What Will Be The 3rd Number #1211
Given the following program, what will be the 3rd number that’d get printed in the output sequence for the given input?</p> <pre><code class="language-cpp"> #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()); } </code></pre> <p>Input Sequence:- </p> <pre><code class="language-text"> 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 </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Graph - Adjacency Matrix - Quiz No.2.
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes