Computer Science and Information Technology
GATE CSE Programming and Data Structures PYQs
Build your understanding with focused practice from past exam papers.
Questions 11–20 of 106. Imported answers require independent review unless marked reviewed.
Question 50
Open questionCS2MSQ2 marksNeeds review
Consider a stack
and a queue
. Both of them are initially empty and have the capacity to store ten elements each. The elements 1, 2, 3, 4, and 5 arrive one by one, in that order. When an element arrives, it is assigned either to
(pushed on
) or to
(enqueued to
). Once all the five elements are stored, the output is generated in two steps. First, stack
is emptied by popping all elements. Then queue
is emptied by dequeuing all elements. The output obtained by following this process is 4 3 1 2 5.Given the output, the objective is to predict whether an element was assigned to
or
.Which of the following options are possible valid assignment(s) of the elements?
Note: In the options, the notation
denotes that element
was assigned to
and
denotes that element
was assigned to
.Your answerSelect all correct options. You can choose more than one.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 60
Open questionCS2NAT2 marksNeeds review
Consider the following ANSI-C program.
#include<stdio.h>
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 61
Open questionCSNAT2 marksNeeds review
Consider the recursive functions represented by the following code segment:
int bar(int n){
if (n == 1) return 0;
else return 1 + bar(n/2);
}
int foo(int n){
if (n == 1) return 1;
else return 1 + foo(bar(n));
}
The smallest positive integer
for which foo(n) returns 5 is _____. (answer in integer)Note: Ignore syntax errors (if any) in the function.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 61
Open questionCS2NAT2 marksNeeds review
Consider the following ANSI-C function.
int func(int start, int end){
int length=end+1-start;
if((length<1)||(start<0)||(end<0)){ return(0); }
if(length%3==0){
return(func(start+1, end));
} else if(length%3==1){
return(1+func(start, end-1));
} else {
return(func(start+2, end));
}
}
The maximum possible value that can be returned from this function is __________. (answer in integer)
Note: Ignore syntax errors (if any) in the function.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 62
Open questionCSNAT2 marksNeeds review
The following sequence corresponds to the preorder traversal of a binary search tree
:50, 25, 13, 40, 30, 47, 75, 60, 70, 80, 77
The position of the element 60 in the postorder traversal of
is _____. (answer in integer)Note: The position begins with 1.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 13
Open questionCSMCQ1 markNeeds review
Consider a binary tree
in which every node has either zero or two children. Let
be the number of nodes in
. Which ONE of the following is the number of nodes in
that have exactly two children?Your answerChoose one option.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 19
Open questionCSMCQ1 markNeeds review
Consider the following C program:
#include <stdio.h>
void strcpy(char *, char *);
int main(){
char a[30] = "@#Hello World!";
strcpy(a, a + 2);
printf("%s\n", a);
return 0;
}
void strcpy(char *s, char *t) {
while(*t)
*s++ = *t++;
}
Which ONE of the following will be the output of the program?
Your answerChoose one option.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 26
Open questionCSMSQ1 markNeeds review
Which of the following statement(s) is/are TRUE for any binary search tree (BST) having
distinct integers?Your answerSelect all correct options. You can choose more than one.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 33
Open questionCSNAT1 markNeeds review
The pseudocode of a function fun() is given below:
fun(int A[0,...,n-1]) {
for i=0 to n-2
for j=0 to n-i-2
if (A[j]>A[j+1])
then swap A[j] and A[j+1]
}
Let
be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with
as argument, is __________. (Answer in integer)Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 33
Open questionCSNAT1 markNeeds review
The output of the given C code segment is ________. (Answer in integer)
int x=12,y=10;
do {
if(x>y) x=x-y;
else y=y-x;
} while(x!=y);
printf("%d",x);
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer