Q10
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT ( refers to the number of items in the queue)?
Show answer without attempting
Answer: A
GATE CS · 17 questions
17 Programming and Data Structures questions from GATE CS papers (2016), each with the official answer key. Answer any question right here and it is marked straight away, or practise them one at a time.
Answer: A
void f(int, short);
void main()
{
int i = 100;
short s = 12;
short *p = &s;
__________ ; // call to f()
}Answer: D
#include<stdio.h>
void mystery(int *ptra, int *ptrb) {
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%d\n", a);
}Answer: 2016.0
int max(int *p, int n) {
int a=0, b=n-1;
while (__________) {
if (p[a] <= p[b]) { a = a+1; }
else { b = b-1; }
}
return p[a];
}Answer: D
void count(int n){
static int d=1;
printf("%d ", n);
printf("%d ", d);
d++;
if(n>1) count(n-1);
printf("%d ", d);
}
void main(){
count(3);
}Answer: A
Answer: B
while Q is not Empty do
if S is Empty OR Top(S) <= Head(Q) then
x := Dequeue(Q);
Push(S,x);
else
x := Pop(S);
Enqueue(Q,x);
end
endAnswer: 256.0
| Operator | Precedence | Associativity | Arity |
|---|---|---|---|
| High | Left | Binary | |
| Medium | Right | Binary | |
| Low | Left | Binary |
Answer: 9.0
Answer: 31.0
void f(int* p, int m){
m = m + 5;
*p = *p + m;
return;
}
void main(){
int i=5, j=10;
f(&i, j);
printf("%d", i+j);
}Answer: 30.0
Answer: C
Answer: 8.0
int exp(int X, int Y) {
int res = 1, a = X, b = Y;
while ( b != 0 ){
if ( b%2 == 0) { a = a*a; b = b/2; }
else { res = res*a; b = b-1; }
}
return res;
}Answer: C
Answer: C
int f(int *p, int n)
{
if (n <= 1) return 0;
else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
int a[] = {3,5,2,6,4};
printf("%d", f(a,5));
}Answer: 3.0

Answer: 2.2 to 2.4
Answer: 64.0
0/170 correct0 marks