• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE-CS-2005

Question 31

Consider the following C-program: C
void foo(int n, int sum)
{
  int k = 0, j = 0;
  if (n == 0) return;
    k = n % 10; 
  j = n / 10;
  sum = sum + k;
  foo (j, sum);
  printf (\"%d,\", k);
}
 
int main ()
{
  int a = 2048, sum = 0;
  foo (a, sum);
  printf (\"%d\\n\", sum);
   
  getchar();
}
What does the above program print?
  • 8, 4, 0, 2, 14
  • 8, 4, 0, 2, 0
  • 2, 0, 4, 8, 14
  • 2, 0, 4, 8, 0

Question 32

Consider the following C-program: C
double foo (double); /* Line 1 */

int main()
{

    double da, db;

    // input da

    db = foo(da);

}

double foo(double a)
{
    return a;
}
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:
  • no compile warning or error
  • some compiler-warnings not leading to unintended results
  • some compiler-warnings due to type-mismatch eventually leading to unintended results
  • compiler errors

Question 33

Postorder traversal of a given binary search tree T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an inorder traversal of the tree T?
  • 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
  • 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
  • 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
  • 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

Question 34

A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is given below: 10, 8, 5, 3, 2 Two new elements ”1‘ and ”7‘ are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is:

  • 10, 8, 7, 5, 3, 2, 1

  • 10, 8, 7, 2, 3, 1, 5

  • 10, 8, 7, 1, 2, 3, 5

  • 10, 8, 7, 3, 2, 1, 5

Question 35

How many distinct binary search trees can be created out of 4 distinct keys?
  • 5
  • 14
  • 24
  • 42

Question 36

In a complete k-ary tree, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is
  • nk
  • (n - 1)k + 1
  • n(k - 1) + 1
  • n(k - 1)

Question 37

Suppose T(n) = 2T (n/2) + n, T(0) = T(1) = 1 Which one of the following is FALSE?
  • T(n) = O(n2)
  • T(n) = θ(n log n)
  • T(n) = Ω(n2)
  • T(n) = O(n log n)

Question 38

Let G(V, E) an undirected graph with positive edge weights. Dijkstra\'s single-source shortest path algorithm can be implemented using the binary heap data structure with time complexity:
  • O(| V |2)
  • O (| E | + | V | log | V |)
  • O (| V | log | V |)
  • O ((| E | + | V |) log | V |)

Question 39

Suppose there are ⌈ log n ⌉ sorted lists of ⌊ n/log n ⌋ elements each. The time complexity of producing a sorted list of all these elements is : (Hint : Use a heap data structure)
  • O(n log log n)
  • θ(n log n)
  • Ω(n log n)
  • Ω(n3/2)

Question 40

Let P, Q and R be three atomic prepositional assertions. Let X denote (P v Q) → R and Y denote (P → R) v (Q → R). Which one of the following is a tautology?
  • X ≡ Y
  • X → Y
  • Y → X
  • ¬ Y → X

There are 90 questions to complete.

Last Updated :
Take a part in the ongoing discussion