Programming and Data Structures questions

Q10

GATE CS 2016 CS-1Linear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (nn refers to the number of items in the queue)?
Show answer without attempting

Answer: A

Q12

GATE CS 2016 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program.
void f(int, short);
void main()
{
    int i = 100;
    short s = 12;
    short *p = &s;
    __________ ;    // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
Show answer without attempting

Answer: D

Q15

GATE CS 2016 CS-1C ProgrammingNAT1 mark
Consider the following C program.
#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);
}
The output of the program is ________.
Show answer without attempting

Answer: 2016.0

Q34

GATE CS 2016 CS-1Linear Data StructuresMCQ2 marks−2/3 if wrong
The following function computes the maximum value contained in an integer array p[] of size n (n >= 1).
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];
}
The missing loop condition is
Show answer without attempting

Answer: D

Q35

GATE CS 2016 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
What will be the output of the following C program?
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);
}
Show answer without attempting

Answer: A

Q37

GATE CS 2016 CS-1Tree Data StructuresMCQ2 marks−2/3 if wrong
An operator delete(i) for a binary heap data structure is to be designed to delete the item in the i-th node. Assume that the heap is implemented in an array and i refers to the i-th index of the array. If the heap tree has depth d (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?
Show answer without attempting

Answer: B

Q41

GATE CS 2016 CS-1Linear Data StructuresNAT2 marks
Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.
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
end
The maximum possible number of iterations of the while loop in the algorithm is ________.
Show answer without attempting

Answer: 256.0

Q45

GATE CS 2016 CS-1C ProgrammingNAT2 marks
The attributes of three arithmetic operators in some programming language are given below.
OperatorPrecedenceAssociativityArity
++HighLeftBinary
−-MediumRightBinary
∗*LowLeftBinary
The value of the expression 2−5+1−7∗32-5+1-7*3 in this language is ________.
Show answer without attempting

Answer: 9.0

Q11

GATE CS 2016 CS-2Tree Data StructuresNAT1 mark
Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex tt at a distance four from the root. If tt is the nn-th vertex in this BFS traversal, then the maximum possible value of nn is _________.
Show answer without attempting

Answer: 31.0

Q12

GATE CS 2016 CS-2C ProgrammingNAT1 mark
The value printed by the following program is _________.
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);
}
Show answer without attempting

Answer: 30.0

Q15

GATE CS 2016 CS-2Linear Data StructuresMCQ1 mark−1/3 if wrong
NN items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed.

An algorithm performs the following operations on the list in this order: Θ(N)\Theta(N) delete, O(log⁡N)O(\log N) insert, O(log⁡N)O(\log N) find, and Θ(N)\Theta(N) decrease-key. What is the time complexity of all these operations put together?
Show answer without attempting

Answer: C

Q34

GATE CS 2016 CS-2Tree Data StructuresNAT2 marks
A complete binary min-heap is made by including each integer in [1,1023][1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 0. The maximum depth at which integer 9 can appear is _________.
Show answer without attempting

Answer: 8.0

Q35

GATE CS 2016 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
The following function computes XYX^Y for positive integers XX and YY.
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;
}
Which one of the following conditions is TRUE before every iteration of the loop?
Show answer without attempting

Answer: C

Q36

GATE CS 2016 CS-2Tree Data StructuresMCQ2 marks−2/3 if wrong
Consider the following New-order strategy for traversing a binary tree:
- Visit the root;
- Visit the right subtree using New-order;
- Visit the left subtree using New-order;

The New-order traversal of the expression tree corresponding to the reverse polish expression
3 4 * 5 - 2 ^ 6 7 * 1 + -
is given by:
Show answer without attempting

Answer: C

Q37

GATE CS 2016 CS-2RecursionNAT2 marks
Consider the following program:
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));
}
Note: max(x,y) returns the maximum of x and y.

The value printed by this program is _________.
Show answer without attempting

Answer: 3.0

Q39

GATE CS 2016 CS-2RecursionNAT2 marks
The given diagram shows the flowchart for a recursive function A(n)A(n). Assume that all statements, except for the recursive calls, have O(1)O(1) time complexity. If the worst case time complexity of this function is O(nα)O(n^\alpha), then the least possible value (accurate up to two decimal positions) of α\alpha is _________.
Question figure
Show answer without attempting

Answer: 2.2 to 2.4

Q40

GATE CS 2016 CS-2Tree Data StructuresNAT2 marks
The number of ways in which the numbers 1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 6, is _________.

Note: The height of a tree with a single node is 0.
Show answer without attempting

Answer: 64.0

0/170 correct0 marks

Related topics in GATE CS