Computer Science and Information Technology
GATE CSE Programming and Data Structures PYQs
Build your understanding with focused practice from past exam papers.
Questions 41–50 of 106. Imported answers require independent review unless marked reviewed.
Question 48
Open questionCS1MSQ2 marksNeeds review
Consider the following C function definition.
int f(int x, int y) {
for (int i=0; i<y; i++) {
x=x+x+y;
}
return x;
}
Which of the following statements is/are TRUE about the above function?
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 48
Open questionCSMSQ2 marksNeeds review
Let S1 and S2 be two stacks. S1 has capacity of 4 elements. S2 has capacity of 2 elements. S1 already has 4 elements: 100, 200, 300, and 400, whereas S2 is empty, as shown below.

Only the following three operations are available:
PushToS2: Pop the top element from S1 and push it on S2.
PushToS1: Pop the top element from S2 and push it on S1.
GenerateOutput: Pop the top element from S1 and output it to the user.
Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.
Which of the following output sequences can be generated by using the above operations?
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 12
Open questionCSMCQ1 markNeeds review
Which one of the following sequences, when stored in an array at locations A[1], . . . , A[10] forms a max-heap?
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 13
Open questionCSMCQ1 markNeeds review
Let SLDel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLDel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list.
Let n denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLDel and DLDel?
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 35
Open questionCSNAT1 markNeeds review
The integer value printed by the ANSI-C program given below is ______.
#include<stdio.h>
int func(){
static int x = 1;
x++;
return x;
}
int main(){
int x,y;
x = func();
y = func()+x;
printf("%d\n", (x+y));
return 0;
}
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 36
Open questionCSMCQ2 marksNeeds review
Consider the following program:
int main() int f1() int f2(int x) int f3()
{ { { {
f1(); return(1); f3(); return(5);
f2(2); } if (x==1) }
f3(); return f1();
return(0); else
} return (x*f2(x-1);
}
Which one of the following options represents the activation tree corresponding to the main function?
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 46
Open questionCSMCQ2 marksNeeds review
Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation Extract-Max(A) extracts and deletes the maximum element from A. The operation Insert(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.
When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
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 47
Open questionCSMCQ2 marksNeeds review
Consider the C function foo and the binary tree shown.
typedef struct node {
int val;
struct node *left, *right;
} node;
int foo(node *p) {
int retval;
if (p == NULL)
return 0;
else {
retval = p->val + foo(p->left) + foo(p->right);
printf("%d ", retval);
return retval;
}
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?

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 59
Open questionCSNAT2 marksNeeds review
Consider a sequence
of elements
, and
. The following operations are performed on a stack
and a queue
, both of which are initially empty.I: push the elements of
from
to
in that order into
.II: enqueue the elements of
from
to
in that order into
.III: pop an element from
.IV: dequeue an element from
.V: pop an element from
.VI: dequeue an element from
.VII: dequeue an element from
and push the same element into
.VIII: Repeat operation VII three times.
IX: pop an element from
.X: pop an element from
.The top element of
after executing the above operations is __________.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 15
Open questionCSMCQ1 markNeeds review
Consider the problem of reversing a singly linked list. To take an example, given the linked list below,

the reversed linked list should look like

Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in
space?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 answer