Test 4 - Algorithms | Computer Science(CS)

GATE Previous year paper Topic Wise Questions and Answers| | Algorithms

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Randomized quick sort is an extension of quick sort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quick sort?

  1. 0(n)
  2. 0(nlog n)
  3. 0(n2)
  4. 0(n!)
Question 2 Multiple Choice (Single Answer)

Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array $(i \leq n)$, the index of the parent is

  1. $i-1$
  2. $\lfloor \frac{i}{2} \rfloor$
  3. $\lceil \frac{i}{2} \rceil$
  4. $\frac{(i+1)}{2}$
Question 3 Multiple Choice (Single Answer)

Let f (n) = n2 logn and g(n) = n(logn)10 be two positive functions of n. Which of the following statements is correct?

  1. f (n) = 0(g(n)) and g(n) $\ne$Y 0(f (n))
  2. g (n) = 0(f (n)) and f (n) $\ne$Y 0(g(n))
  3. f (n) $\ne$Y 0(g(n)) and g(n) $\ne$Y 0(f (n))
  4. f (n) = 0(g(n)) and g(n) = 0(f (n))
Question 4 Multiple Choice (Single Answer)

The solution to the recurrence equation $T(2^k) = 3T(2^{k-1})+1, T(1) =1$ is

  1. $2^k$
  2. $\frac{(3^{k+1}-1)}{2}$
  3. $3^{\log_2 k}$
  4. $2^{\log_3 k}$
Question 5 Multiple Choice (Single Answer)

What is the minimum number of stacks of size n required to implement a queue to size n?

  1. One
  2. Two
  3. Three
  4. Four
Question 6 Multiple Choice (Single Answer)

How many undirected graphs (not necessarily connected) can be constructed out of a given set $V={v_1, v_2, \dots v_n}$ of $n$ vertices?

  1. $\frac{n(n-1)} {2}$
  2. $2^n$
  3. $n!$
  4. $2^\frac{n(n-1)} {2} $
Question 7 Multiple Choice (Single Answer)

The minimum number of colours required to colour the vertices of a cycle with n nodes in such a way that no two adjacent nodes have same colour is.

  1. 2
  2. 3
  3. 4
  4. $n − 2 \left[ \dfrac{n}{2} \right] + 2$
Question 8 Multiple Choice (Single Answer)

In the worst case, the number of comparisons needed to search a single linked list of length n for a given element is

  1. $\log n$
  2. $\dfrac{n}{2}$
  3. $\log_2 n -1$
  4. $n$
Question 9 Multiple Choice (Single Answer)

Maximum number of edges in a n-node undirected graph without self loops is

  1. n2
  2. $\dfrac{n(n-1)}{2}$
  3. (n-1)
  4. $\dfrac{(n-1)(2)}{2}$
Question 10 Multiple Choice (Single Answer)

The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:

  1. $\frac{n}{2}$
  2. $\frac{(n-1)}{3}$
  3. $\frac{(n-1)}{2}$
  4. $\frac{(2n+1)}{3}$
Question 11 Multiple Choice (Single Answer)

To evaluate an expression without any embedded function calls

  1. One stack is enough
  2. Two stack are needed
  3. As many stacks as the height of the expression tree are needed
  4. A Turning machine is needed in the general case
Question 12 Multiple Choice (Single Answer)

Consider the undirected unweighted graph G. Let a breadth-first traversal of G be done starting from a node r . Let d(r,u) and d(r,v) be the lengths of the shortest paths form r to u and v respectively in G. If u is visited before v during the breadth-first traversal, which of the following statements is correct?

  1. d(r,u) < d(r,v)
  2. d(r,u) > d(r,v)
  3. d(r,u) $\le$ d(r,v)
  4. None of the above
Question 13 Multiple Choice (Single Answer)

The running time of the following algorithm Procedure A(n)
If n <= 2 return (1) else return (A($|\sqrt n|$)); Is best described by

  1. 0(n)
  2. 0(log n)
  3. 0(loglog n)
  4. 0(1)
Question 14 Multiple Choice (Single Answer)

Level order traversal of a rooted tree can be done by stating from the root and performing

  1. preorder traversal
  2. inorder traversal
  3. depth first search
  4. breadth first search
Question 15 Multiple Choice (Single Answer)

A weight-balanced tree is a binary tree in which for each node, the number of nodes in the let sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the furthest leaf) of such a tree on n nodes is best described by which of the following?

  1. $\log_2 n$
  2. $\log_{\frac{4}{3}} n$
  3. $\log_3 n$
  4. $\log_{\frac{3}{2}} n$
Question 16 Multiple Choice (Single Answer)

Consider the following algorithm for searching for a given number x in an unsorted array A[1.....n] having n distinct values :
(1) Choose an i uniformly at random from [1....n]
(2) If A[i] = x then stop else Goto 1;

Assuming that x is present A, What is the expected number of comparisons made by the algorithm before it terminates?

  1. n
  2. n -1
  3. 2n
  4. $\dfrac{n}{2}$
Question 17 Multiple Choice (Single Answer)

Given the following input(4322,1334,1471,9679,1989,6171,6173,4199) and the hash function x mod 10, which of the following statements are true?

  1. 9679,1989,4199 hash to the same value
  2. 1471,6171 hash to the same value
  3. All element hashes to a different value
  1. 1 only
  2. 2 only
  3. 1 and 2 only
  4. 3 and 4 only
Question 18 Multiple Choice (Single Answer)

The tightest lower bound on the number of comparisons, in the worst case, for comparision-based sorting is of the order of

  1. n
  2. n2
  3. nlog n
  4. nlog2n
Question 19 Multiple Choice (Single Answer)

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely?

  1. preorder and postorder
  2. inorder and postorder
  3. preorder and inorder
  4. level order and postorder
  1. 1 only
  2. 2 and 3
  3. 3 only
  4. 4 only
Question 20 Multiple Choice (Single Answer)

Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or column major order in contiguous memory locations. The time complexity of an algorithm to compute M1x M2 x will be

  1. best if A is in row-major, and B is in column-major order
  2. best if both are in row-major order
  3. best if both are in column-major order
  4. independent of the storage scheme