Logo

Algorithms Questions Set 6:

Quiz Mode

What is the time complexity of searching an element from a set of n elements using a Binary Search algorithm?

1
2
3
4

Solution:

Solve the following recurrence using Master's theorem:

T(k) = 4T(k/2) + k!

1
2
3
4

Solution:

If a simple graph G contains n vertices and m edges, the number of edges in the graph G' (the complement of G) is:

1
2
3
4

Solution:

A binary search tree in which the difference in height between the left and right subtrees of any node is at most 1 is called?

1
2
3
4

Solution:

In a linked list implementation of a queue, where is a new element inserted?

1
2
3
4

Solution:

What is the Big O analysis of the running time (in terms of m) for the following program?

For (x=0; x< m; x++)

   For (y=x; y< m; y++)

        For (z=y; z< m; z++)

              p++;

1
2
3
4

Solution:

The fastest time in which the kth root of a number N (up to a given precision p) can be computed is approximately:

(The nth root of a number a refers to a1/n )

1
2
3
4

Solution:

Consider the following definition in C programming language:

struct node
{
   int data;
   struct node * next;
}
typedef struct node NODE;
NODE *ptr;

Which of the following C code is used to create a new node?

1
2
3
4

Solution:

Given the program of naïve method for matrix multiplication:

for a=1 to m do
  for b=1 to m do
      Z[a][b]=0;
      for c=1 to m do
           Z[a][b] = Z[a][b] + X[a][c] * Y[c][b]

Fill in the blanks with the appropriate formula.

1
2
3
4

Solution:

Define Rn to be the maximum amount earned by cutting a rod of length n meters into one or more pieces of integer length and selling them. For i>0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:

p[1]=1, p[2]=5, p[3]=8, p[4]=9, p[5]=10, p[6]=17, p[7]=18

Which of the following statements is/are correct about R7?

  1. R7=18
  2. R7=19
  3. R7 is achieved by three different solutions
  4. R7 cannot be achieved by a solution consisting of three pieces

1
2
3
4

Solution: