Welcome to Data Structure Quiz, Intermediate Level !!

Question 1. How many distinct binary search trees can be created out of 4 distinct keys?

5

14

24

42

Question 2. A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

An array of 50 numbers

An array of 100 numbers

An array of 500 numbers

A dynamically allocated array of 550 numbers

Question 3. The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is

O(n)

O(nlogn)

O(log*n)

O(n^2)

Question 4. How many undirected graphs (not necessarily connected) can be constructed out of a given set V= {V 1, V 2, ... V n} of n vertices

n(n-l)/2

2^n

n!

2^(n(n-1)/2)

Question 5. Suppose T(n) = 2T(n/2) + n, T(0) = T(1) = 1
Which of the following is true ?

T(n) = O(n^2)

T(n) = Theta(n^2)

T(n) = Omega(n^2)

T(n) = O(nLogn)

Question 6. The following C function takes a simply-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.
typedef struct node
{
  int value;
  struct node *next;
}Node;

Node *move_to_front(Node *head)
{
  Node *p, *q;
  if ((head == NULL: || (head->next == NULL))
    return head;
  q = NULL; p = head;
  while (p-> next !=NULL)
  {
    q = p;
    p = p->next;
  }
  _______________________________
  return head;
}

Choose the correct alternative to replace the blank line.

q = NULL; p->next = head; head = p;

q->next = NULL; head = p; p->next = head;

head = p; p->next = q; q->next = NULL;

q->next = NULL; p->next = head; head = p;

Question 7. 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 8. An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array

Solves it in linear time using a left to right pass of the array

Solves it in linear time using a right to left pass of the array

Solves it using divide and conquer in time O(nlogn)

Solves it in time O(n^2)

Question 9. What is the maximum height of any AVL tree with 7 nodes? Assume that the height of a tree with a single node is 0.

2

3

4

5

Question 10. What is the best definition of a collision in a hash table?

Two entries are identical except for their keys.

Two entries with different data have the exact same key.

Two entries with different keys have the same exact hash value.

Two entries with the exact same key have different hash values.