Recent questions tagged algorithms

27 27 votes
2 answers 2 answers
7.0k
7.0k views
Consider the following program that attempts to locate an element $x$ in an array $a[ ]$ using binary search. Assume $N 1$. The program is erroneous. Under what conditio...
39 39 votes
8 answers 8 answers
15.8k
15.8k views
Let $G$ be the directed, weighted graph shown in below figureWe are interested in the shortest paths from $A$.Output the sequence of vertices identified by the Dijkstra’s...
38 38 votes
1 answers 1 answer
8.1k
8.1k views
A complete, undirected, weighted graph $G$ is given on the vertex $\{0, 1,\dots, n -1\}$ for any fixed ‘n’. Draw the minimum spanning tree of $G$ ifthe weight of the edge...
42 42 votes
2 answers 2 answers
9.9k
9.9k views
A two dimensional array $A[1..n][1..n]$ of integers is partially sorted if $\forall i, j\in [1..n-1], A[i][j] < A[i][j+1] \text{ and } A[i][j] < A[i+1][j]$The smallest it...
44 44 votes
5 answers 5 answers
18.2k
18.2k views
Quick-sort is run on two inputs shown below to sort in ascending order taking first element as pivot$1, 2, 3, \dots n$$n, n-1, n-2, \dots, 2, 1$Let $C_1$ and $C_2$ be the...
78 78 votes
10 answers 10 answers
48.1k
48.1k views
The average number of key comparisons required for a successful search for sequential search on $n$ items is$\dfrac{n}{2}$$\dfrac{n-1}{2}$$\dfrac{n+1}{2}$None of the abov...
32 32 votes
5 answers 5 answers
13.8k
13.8k views
The recurrence relation$T(1) = 2$$T(n) = 3T (\frac{n}{4}) +n$has the solution $T(n)$ equal to$O(n)$$O (\log n)$$O\left(n^\frac{3}{4}\right)$ None of the above
63 63 votes
5 answers 5 answers
31.3k
31.3k views
Which of the following is false?$100n \log n=O(\frac{n\log n}{100})$$\sqrt{\log n} = O(\log\log n)$If $0 < x < y \text{ then } n^x = O\left(n^y\right)$$2^n \neq O\left(nk...
24 24 votes
1 answers 1 answer
8.4k
8.4k views
How many minimum spanning trees does the following graph have? Draw them. (Weights are assigned to edges).
24 24 votes
2 answers 2 answers
11.9k
11.9k views
Consider the following sequence of numbers:$$92, 37, 52, 12, 11, 25$$ Use Bubble sort to arrange the sequence in ascending order. Give the sequence at the end of each of ...
18 18 votes
3 answers 3 answers
5.8k
5.8k views
Consider the following Pascal function where $A$ and $B$ are non-zero positive integers. What is the value of $\text{GET}(3, 2)$?function GET(A,B:integer): integer; begin...
24 24 votes
1 answers 1 answer
6.2k
6.2k views
A language with string manipulation facilities uses the following operationshead(s): first character of a string tail(s): all but exclude the first character of a stringc...
15 15 votes
3 answers 3 answers
5.9k
5.9k views
Assume that $X$ and $Y$ are non-zero positive integers. What does the following Pascal program segment do?while X < Y do if X Y then X := X - Y else Y := Y - X; write(X)...
45 45 votes
6 answers 6 answers
56.9k
56.9k views
For merging two sorted lists of sizes $m$ and $n$ into a sorted list of size $m+n$, we require comparisons of$O(m)$$O(n)$$O(m+n)$$O(\log m + \log n)$
29 29 votes
2 answers 2 answers
7.6k
7.6k views
Merge sort uses:Divide and conquer strategyBacktracking approachHeuristic searchGreedy approach
25 25 votes
1 answers 1 answer
8.5k
8.5k views
In the following Pascal program segment, what is the value of X after the execution of the program segment?X := -10; Y := 20; If X Y then if X < 0 then X := abs(X) else ...
18 18 votes
2 answers 2 answers
8.1k
8.1k views
An array $A$ contains $n$ integers in locations $A[0], A , \dots A[n-1]$. It is required to shift the elements of the array cyclically to the left by $K$ places, where $1...
22 22 votes
4 answers 4 answers
5.7k
5.7k views
What function of $x$, $n$ is computed by this program?Function what(x, n:integer): integer: Var value : integer begin value := 1 if n 0 then begin if n mod 2 =1 then val...
74 74 votes
8 answers 8 answers
27.0k
27.0k views
Consider the following two functions:$g_1(n) = \begin{cases} n^3 \text{ for } 0 \leq n \leq 10,000 \\ n^2 \text{ for } n 10,000 \end{cases}$$g_2(n) = \begin{cases} n \te...
52 52 votes
7 answers 7 answers
16.5k
16.5k views
Which of the following statements is false?Optimal binary search tree construction can be performed efficiently using dynamic programmingBreadth-first search cannot be us...
28 28 votes
7 answers 7 answers
23.1k
23.1k views
Algorithm design technique used in quicksort algorithm is?Dynamic programmingBacktrackingDivide and conquerGreedy method
35 35 votes
8 answers 8 answers
25.6k
25.6k views
The recurrence relation that arises in relation with the complexity of binary search is:$T(n) = 2T\left(\frac{n}{2}\right)+k, \text{ k is a constant }$$T(n) = T\left(\fra...
64 64 votes
12 answers 12 answers
37.4k
37.4k views
Consider a complete undirected graph with vertex set $\{0, 1, 2, 3, 4\}$. Entry $W_{ij}$ in the matrix $W$ below is the weight of the edge $\{i, j\}$$$W=\begin{pmatrix} 0...
44 44 votes
5 answers 5 answers
17.5k
17.5k views
What is the value printed by the following C program?#include<stdio.h int f(int *a, int n) { if (n <= 0) return 0; else if (*a % 2 == 0) return *a+f(a+1, n-1); else retur...
20 20 votes
1 answers 1 answer
5.3k
5.3k views
Consider the recursive algorithm given below:procedure bubblesort (n); var i,j: index; temp : item; begin for i:=1 to n-1 do if A[i] A[i+1] then begin temp := A[i]; A[i]...
55 55 votes
6 answers 6 answers
20.6k
20.6k views
$\displaystyle \sum_{1\leq k\leq n} O(n)$, where $O(n)$ stands for order $n$ is:$O(n)$$O(n^2)$$O(n^3)$$O(3n^2)$$O(1.5n^2)$
23 23 votes
4 answers 4 answers
7.5k
7.5k views
What does the following code do?var a, b: integer; begin a:=a+b; b:=a-b; a:=a-b; end;exchanges $a$ and $b$doubles $a$ and stores in $b$doubles $b$ and stores in $a$leaves...
19 19 votes
6 answers 6 answers
9.1k
9.1k views
Consider the following function.Function F(n, m:integer):integer; begin if (n<=0) or (m<=0) then F:=1 else F:F(n-1, m) + F(n-1, m-1); end;Use the recurrence relation $\b...
51 51 votes
4 answers 4 answers
12.4k
12.4k views
Consider a graph whose vertices are points in the plane with integer co-ordinates $(x,y)$ such that $1 \leq x \leq n$ and $1 \leq y \leq n$, where $n \geq 2$ is an intege...
26 26 votes
2 answers 2 answers
10.7k
10.7k views
Let $T(n)$ be the function defined by $T(1) =1, \: T(n) = 2T (\lfloor \frac{n}{2} \rfloor ) + \sqrt{n}$ for $n \geq 2$.Which of the following statements is true?$T(n) = O...