• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE-CS-2007

Question 41

In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity by
  • Dijkstra’s algorithm starting from S.
  • Warshall’s algorithm
  • Performing a DFS starting from S.
  • Performing a BFS starting from S.

Question 42

Consider the following C function, what is the output? C
#include <stdio.h>
int f(int n)
{
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3)
    {
        r = n;
        return f(n-2)+2;
    }
    return f(n-1)+r;
}

int main()
{
    printf(\"%d\", f(5));
}
  • 5
  • 7
  • 9
  • 18

Question 43

A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
  • 3
  • 4
  • 5
  • 6

Question 44

In the following C function, let n >= m. c
int gcd(n,m)
{
  if (n%m ==0) return m;  
  n = n%m;
  return gcd(m,n);
}
How many recursive calls are made by this function? (A) [Tex]\\theta[/Tex](logn)? (B) [Tex]\\Omega[/Tex](n) (C) [Tex]\\theta[/Tex](loglogn) (D) [Tex]\\theta[/Tex](sqrt(n))
  • A
  • B
  • C
  • D

Question 45

What is the time complexity of the following recursive function: c
int DoSomething (int n) 
{
  if (n <= 2)
    return 1;
  else  
    return (DoSomething (floor(sqrt(n))) + n);
}
(A) [Tex]\\theta[/Tex](n) (B) [Tex]\\theta[/Tex](nlogn) (C) [Tex]\\theta[/Tex](logn) (D) [Tex]\\theta[/Tex](loglogn)
  • A
  • B
  • C
  • D

Question 46

Consider the following C program segment where CellNode represents a node in a binary tree: C
struct CellNode 
{
  struct CellNOde *leftChild;
  int element;
  struct CellNode *rightChild;
};

int GetValue(struct CellNode *ptr) 
{
  int value = 0;
  if (ptr != NULL) 
  {
   if ((ptr->leftChild == NULL) &&
        (ptr->rightChild == NULL))
      value = 1;
   else
      value = value + GetValue(ptr->leftChild)
                   + GetValue(ptr->rightChild);
  }
  return(value);
}
The value returned by GetValue() when a pointer to the root of a binary tree is passed as its argument is:
  • the number of nodes in the tree
  • the number of internal nodes in the tree
  • the number of leaf nodes in the tree
  • the height of the tree

Question 47

Consider the process of inserting an element into a Max Heap, where the Max Heap is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is: (A) [Tex]\\theta[/Tex](logn) (B) [Tex]\\theta[/Tex](LogLogn ) (C) [Tex]\\theta[/Tex](n) (D) [Tex]\\theta[/Tex](nLogn)
  • A
  • B
  • C
  • D

Question 48

Which of the following is TRUE about formulae in Conjunctive Normal Form?

  • For any formula, there is a truth assignment for which at least half the clauses evaluate to true.

  • For any formula, there is a truth assignment for which all the clauses evaluate to true

  • There is a formula such that for each truth assignment, at most one-fourth of the clauses evaluate to true.

  • None of the above

Question 49

Let w be the minimum weight among all edge weights in an undirected connected graph. Let e be a specific edge of weight w . Which of the following is FALSE?
  • There is a minimum spanning tree containing e.
  • If e is not in a minimum spanning tree T, then in the cycle formed by adding e to T, all edges have the same weight.
  • Every minimum spanning tree has an edge of weight w .
  • e is present in every minimum spanning tree.

Question 50

An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed?
  • At least 2n - c comparisons, for some constant c, are needed.
  • At most 1.5n - 2 comparisons are needed.
  • At least nLog2n comparisons are needed.
  • None of the above.

There are 85 questions to complete.

Last Updated :
Take a part in the ongoing discussion