Recent questions tagged algorithms

17.0k
views
4 answers
46 votes
Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let ... \leq 2T(4n/5) + n$T(n) \leq 2T(n/2) + n$
37.9k
views
7 answers
79 votes
The minimum number of comparisons required to determine if an integer appears more than $\frac{n}{2}$ times in a sorted array of $n$ integers is$\Theta(n)$\Theta(\log n)$\Theta(\log^*n)$\Theta(1)$
17.0k
views
5 answers
40 votes
Consider the following functions:$f(n) = 2^n$g(n) = n!$h(n) = n^{\log n}$Which of the following statements about the asymptotic behavior of $f(n)$, $g(n)$ and ...
36.4k
views
6 answers
31 votes
The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is:$\text{MNOPQR}$\text{NQMPOR}$\text{QMNPRO}$\text{QMNPOR}$
14.0k
views
6 answers
28 votes
The most efficient algorithm for finding the number of connected components in an undirected graph on $n$ vertices and $m$ edges has time complexity$\Theta(n)$\Theta(m)$\Theta(m+n)$\Theta(mn)$
22.2k
views
5 answers
48 votes
Consider the following C program that attempts to locate an element $x$ in an array $Y[ \ ]$ using binary search. The program is erroneous. f (int Y[10] , int x) { int i, j, k; ... $ 2 < x < 20$ and $x$ is even
25.0k
views
8 answers
107 votes
The cube root of a natural number $n$ is defined as the largest natural number $m$ such that $(m^3 \leq n)$ . The complexity of computing the cube root of $n$ ($n$ is ... some constant $k > 0.5$, but not $O( (\log \log n)^{0.5} )$
904
views
1 answers
1 votes
What is the time complexity?main() { n=2^2^k, k>0 for(i = 1 to n) { j=2 while(j ≤ n) { j=j^2 } } }
2.6k
views
2 answers
5 votes
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } }The time complexity of the above code is?
1.3k
views
1 answers
5 votes
Simple linear search to find max min algomaxmin(a,n,max,min) { max=min=a[1]; for i=2 to n do { if a[i]>max then max:=a[i]; else if ... n/2 elements2.Average case complexity of the above algo if the first condition fails 1/2 timesplz xplain
32.4k
views
9 answers
81 votes
Consider the following operation along with Enqueue and Dequeue operations on queues, where $k$ is a global parameter.MultiDequeue(Q){ m = k while (Q is not empty) and (m > 0) ... $Θ(n + k)$Θ(nk)$Θ(n^2)$
14.7k
views
4 answers
43 votes
Let $W(n) $ and $A(n)$ denote respectively, the worst case and average case running time of an algorithm executed on an input of size $n$ ... $A(n) = \text{o} (W(n))$
16.0k
views
3 answers
35 votes
The recurrence relation capturing the optimal execution time of the $Towers \ of \ Hanoi$ problem with $n$ discs is$T(n) = 2T(n − 2) + 2$T (n) = 2T(n − 1) + n$T (n) = 2T(n/2) + 1$T (n) = 2T(n − 1) + 1$