Recent questions tagged algorithms

9 9 votes
2 2 answers
2.0k
2.0k views
Let $G$ be a weighted directed acyclic graph with $m$ edges and $n$ vertices. Given $G$ and a source vertex $s$ in $G$, which one of the following options gives the worst...
9 9 votes
6 6 answers
3.9k
3.9k views
Consider an array $A$ of integers of size $n$. The indices of $A$ run from $1$ to $n$. An algorithm is to be designed to check whether $A$ satisfies the condition given b...
9 9 votes
2 2 answers
1.1k
1.1k views
Consider a table $T$, where the elements $T[i][j], 0 \leq i, j \leq n$, represent the cost of the optimal solutions of different subproblems of a problem that is being so...
15 15 votes
5 5 answers
1.8k
1.8k views
Consider a binary search tree (BST) with $n$ leaf nodes $(n>0)$. Given any node $V$, the key present in the node is denoted as $\operatorname{Val}(V)$. All the keys prese...
13 13 votes
7 7 answers
2.3k
2.3k views
Consider the following recurrence relations:For all $n>1$,\[\begin{array}{c}T_{1}(n)=4 T_{1}\left(\frac{n}{2}\right)+T_{2}(n) \\T_{2}(n)=5 T_{2}\left(\frac{n}{4}\right)+\...
5 5 votes
3 3 answers
1.9k
1.9k views
Let $n$ be an odd number greater than $100$. Consider a binary minheap with $n$ elements stored in an array $P$ whose index starts from $1$.Which of the following indices...
10 10 votes
2 answers 2 answers
1.6k
1.6k views
Consider a hash table $P[0,1, \ldots, 10]$ that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is $h(x...
7 7 votes
5 5 answers
3.3k
3.3k views
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with $23$ no...
8 8 votes
4 4 answers
2.8k
2.8k views
Let $P$ be the set of all integers from $1$ to $15$. Consider any order of insertion of the elements of $P$ into a binary search tree that creates a complete binary tree....
11 11 votes
3 3 answers
1.9k
1.9k views
Let $G(V, E)$ be an undirected, edge-weighted graph with integer weights. The weight of a path is the sum of the weights of the edges in that path. The length of a path i...
8 8 votes
3 3 answers
1.5k
1.5k views
Let $G(V, E)$ be a simple, undirected, edge-weighted graph with unique edge weights.Which of the following statements about the minimum spanning trees (MST) of $G$ is/are...
8 8 votes
5 5 answers
1.8k
1.8k views
Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph $G(V, E)$ as input, where $d[v]$ and $f[v]$ are the discovery time a...
21 21 votes
2 2 answers
3.1k
3.1k views
Consider the recursive functions represented by the following code segment:int bar(int n) { if (n == 1) return 0; else return 1 + bar(n/2); } int foo(int n) { if (n == 1)...
4 4 votes
3 3 answers
1.7k
1.7k views
The following sequence corresponds to the preorder traversal of a binary search tree $T$ :\[50,25,13,40,30,47,75,60,70,80,77\]The position of the element $60$ in the post...
1 1 vote
0 0 answers
231
231 views
Let $G=(V,E)$ be a directed graph, and let $G^R$ denote the graph obtained by reversing all the edges of $G$.Which of the following statements is/are TRUE?If a vertex $v$...
0 0 votes
1 1 answer
252
252 views
Let $$A = [1, 2, 3, 5, 4]$$Let $N_1$ be the number of comparisons performed by Bubble Sort, and $N_2$ be the number of comparisons performed by Insertion SortWhich of th...
1 1 vote
1 1 answer
226
226 views
In Quick Sort, the first element is always chosen as the pivot.Which of the following recurrence relations correctly represent the expected running time?$T(n)=T(1)+T(n-1)...
0 0 votes
0 0 answers
190
190 views
There are $1000$ keys. Find the height (or the number of comparisons in the worst case) required in Binary Search.
0 0 votes
2 2 answers
284
284 views
A binary tree has the following traversals:Preorder traversal$: P, Q, S, E, R, F, G$ Inorder traversal$: S, Q, E, P, F, R, G$ Which of the following statement(s) is/are T...
1 1 vote
1 1 answer
464
464 views
Suppose the input directed graph $G(V,E)$ is a DAG. For an edge $(u,v)\in E$, which of the following will NEVER be correct in DFS discovery/finish times?$d[u] < d[v] < f[...
2 2 votes
1 1 answer
633
633 views
If there is no path from $\delta$ to a of length at most k , then $d_k(u)=\infty$Statement 1: For every $u \geq 0$ and $u \in V, d_{k+1}(u) \leq d_k(u)$.Statement 2: For ...
4 4 votes
2 2 answers
534
534 views
Consider the following:For all $n>1$$$\begin{aligned}& T_1(n)=4 T_1(n / 2)+T_2(n) \\\\& T_2(n)=5 T_2(n / 4)+\theta\left(\log _2 n\right)\end{aligned}$$Assume that for all...
0 0 votes
1 1 answer
462
462 views
Let $\mathrm{G}(\mathrm{V}, \mathrm{E})$ be a simple, undirected, edge-weighted graph with unique edge weights.Which of the following statements about MST (minimum spanni...
0 0 votes
1 1 answer
491
491 views
Let $G$ be a weighted directed acyclic graph (DAG) with $m$ vertices and $n$ edges. Given $G$ and a source vertex $S$, which of the following options gives the worst-case...
0 0 votes
0 0 answers
341
341 views
In dynamic programming,$\verb|A[i][j]|$ is a term, for $1 \leq \verb|i|, \verb|j| \leq n$$\verb|A[0][k] = A[k][0] = 0|$$\verb|A[i][j] = 2A[i-1][j] + 3A[i][j-1]|$Which of ...