edited by
11,969 views
36 36 votes

Match the algorithms with their time complexities:

$$\begin{array}{|l|l|}\hline \textbf{Algorithms}  &  \textbf{Time Complexity} \\\hline  \text{P. Tower of Hanoi with $n$ disks} & \text{i. $\Theta (n^2)$} \\\hline  \text{Q. Binary Search given $n$ sorted numbers} & \text{ii. $\Theta (n \log n)$} \\\hline \text{R. Heap sort given $n$ numbers at the worst case} & \text{iii. $\Theta (2^n)$} \\\hline \text{S. Addition of two $n\times n$ matrices} & \text{iv. $\Theta (\log n)$} \\\hline \end{array}$$

  1. $P\rightarrow (iii) \quad  Q \rightarrow(iv) \quad r \rightarrow(i)   \quad S \rightarrow(ii)$
  2. $P\rightarrow (iv) \quad  Q \rightarrow(iii) \quad  r \rightarrow(i) \quad  S\rightarrow(ii)$
  3. $P\rightarrow (iii) \quad  Q \rightarrow(iv) \quad r \rightarrow(ii) \quad S\rightarrow(i)$
  4. $P\rightarrow (iv) \quad  Q \rightarrow(iii)\quad  r \rightarrow(ii) \quad  S\rightarrow(i)$

8 Answers

0 0 votes
→ Tower of Hanoi with n disks takes θ(2n) time
It is a mathematical game or puzzle.
It consists of three rods and a number of disks of different sizes, which can slide onto any rod.
The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack.
3. No disk may be placed on top of a smaller disk.
With 3 disks, the puzzle can be solved in 7 moves.
The minimal number of moves required to solve a Tower of Hanoi puzzle is 2n-1, where n is the number of disks.
→ Binary Search given n sorted numbers takes Ɵ(log2 n)
→ Heap sort given n numbers of the worst case takes Ɵ(n log n)
→ Addition of two n×n matrices takes Ɵ(n2)
0 0 votes

P. Towers of Hanoi → Recurrence: T(n) = 2T(n-1) + 1 → Θ(2ⁿ)(iii)

Q. Binary Search → Halving each time → Θ(log n)(iv)

R. Heap Sort worst case → Build heap O(n) + n extractions each O(log n) → Θ(n log n)(ii)

S. Addition of two n×n matrices → Must visit all n² elements → Θ(n²)(i)

Answer:
Position:
Show:

Related questions

50 50 votes
5 answers 5 answers
16.2k
16.2k views
Madhav asked Feb 14, 2017
16,162 views
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:$$\begin{array}{|l|l|}\hline \text{P. Syntax t...
45 45 votes
4 answers 4 answers
9.6k
9.6k views
khushtak asked Feb 14, 2017
9,613 views
Match the following:$$\begin{array}{|ll|ll|}\hline P. & \text{static char var ;} & \text{i.} & \text{Sequence of memory locations to store addresses} \\\hline Q. & \text...
71 71 votes
10 answers 10 answers
41.1k
41.1k views
Madhav asked Feb 14, 2017
41,070 views
Consider the following C functionint fun(int n) { int i, j; for(i=1; i<=n; i++) { for (j=1; j<n; j+=i) { printf("%d %d", i, j); } } }Time complexity of $fun$ in terms of ...
35 35 votes
7 answers 7 answers
11.5k
11.5k views
khushtak asked Feb 14, 2017
11,475 views
Consider the following table:$$\begin{array}{|ll|ll|}\hline & \textbf{Algorithms} & & \textbf{Design Paradigms} \\\hline \text{(P)} & \text{Kruskal} & \text{(i)}& \text...