Recent questions and answers in Algorithms

261
views
1 answers
3 votes
A $\text{stable sort}$ preserves the order of values that are equal with respect to the comparison function. We have a list of three-dimensional points$[(7, 1, 8),(3, 5, ...
99
views
1 answers
0 votes
How to approach this type of questions?
9.4k
views
3 answers
33 votes
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences $X[m]$ and $Y[n]$ of lengths ...
1.0k
views
1 answers
0 votes
Consider the following sorting algorithms:Bubble sortInsertion sortSelection sortWhich ONE among the following choices of sorting algorithms sorts the numbers in the arra...
13.5k
views
8 answers
35 votes
Consider the following program written in pseudo-code. Assume that $x$ and $y$ are integers.Count (x, y) { if (y !=1 ) { if (x !=1) { print("*"); Count (x/2, y); } else {...
904
views
2 answers
2 votes
The given array is $\text{arr={1, 2, 4, 3}}$. Bubble sort is used to sort the array elements. How many passes will be done to sort the array?$4$$2$$1$$3$
5.2k
views
5 answers
12 votes
Consider the following $\text{ANSI C}$ function:int SomeFunction (int x, int y) { if ((x==1) || (y==1)) return 1; if (x==y) return x; if (x y) return SomeFunction(x-y, y...
6.5k
views
5 answers
8 votes
Consider the following $\text{ANSI C}$ function:int SimpleFunction(int Y[], int n, int x) { int total = Y[0], loopIndex; for (loopIndex=1; loopIndex<=n-1; loopIndex++) to...
11.6k
views
5 answers
26 votes
Consider the program below:#include <stdio.h int fun(int n, int *f_p) { int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n-1, f_p); f = t + *f_p; *f_p = t; return f;...
13.4k
views
5 answers
27 votes
Consider the following C-program:void foo (int n, int sum) { int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n/10; sum = sum + k; foo (j, sum); printf ("%d,",k); } ...
511
views
2 answers
1 votes
#include<stdio.h>int main(){ int x,sum; sum=0; for(x=0;x<=500;x+=10){ sum=sum+x; } printf("%d",sum); return 0;} What is output of above C-program...
175
views
1 answers
0 votes
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....a)O(nlogn)b)O(...
9.5k
views
5 answers
16 votes
Consider the code fragment written in C below :void f (int n) { if (n <=1) { printf ("%d", n); } else { f (n/2); printf ("%d", n%2); } }What does f(173) print?$010110101$...
11.9k
views
5 answers
27 votes
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...
9.3k
views
2 answers
27 votes
Suppose you are given an array $s[1....n]$ and a procedure reverse $(s, i, j)$ which reverses the order of elements in $s$ between positions $i$ and $j$ (both inclusive)....
5.0k
views
2 answers
21 votes
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...
18.4k
views
6 answers
46 votes
Which of the given options provides the increasing order of asymptotic complexity of functions $f_1, f_2, f_3$ and $f_4$?$f_1(n) = 2^n$$f_2(n) = n^{3/2}$$f_3(n) = n \log_...
134
views
1 answers
2 votes
for (i = 1; i <= N; i++){ for (j= 1;j <= i^2;j=j+i){ //some code}} how is this O(n^2)? explain in detail and simple terms
18.9k
views
4 answers
57 votes
Arrange the following functions in increasing asymptotic order:$n^{1/3}$$e^n$$n^{7/4}$$n \log^9n$$1.0000001^n$a, d, c, e, bd, a, c, e, ba, c, d, e, ba, c, d, b, e
994
views
2 answers
2 votes
$\text{G}$ is a directed graph with negative weight edges but NO negative weight cycles. Which of the following hold for Dijkstra’s algorithm on $\text{G}:$Dijkstra’s...
725
views
1 answers
3 votes
Number of possible permutations that can be obtained using stack if the input sequence is 1, 2, 3, 4, 5 (in the order) is
313
views
1 answers
0 votes
Which of the following statements is/are correct?Consider 'n' as the number of nodes in graph.A.In an unweighted, undirected connected graph, Dijkstra’s algorithm can b...
606
views
1 answers
0 votes
Suppose we have a directed graph G = (V,E) with V= {1, 2, ..., n} and Eis presented as an adjacency list. For each vertex u in V, out(u) is a list such that (u, v) in {1,...
550
views
2 answers
1 votes
int i,j,k,s=0; for(i=1; i<=n; i++) { for(j=1 ; j<=i; j=j*2) { for(k=n; k>1;k=k/2) { s++; } } }What will be the time complexity of the above code?
2.2k
views
2 answers
1 votes
The number of edges present in the forest generated by the $\text{DFS}$ traversal of an undirected graph $G$ with $100$ vertices is $40$. The number of connected componen...
469
views
1 answers
2 votes
A linear-probing hash table of length $10$ uses the hash function $h(x)=x \bmod 10$. After inserting six integer keys into an initially empty hash table, the array of key...
28.6k
views
9 answers
113 votes
The number of elements that can be sorted in $\Theta(\log n)$ time using heap sort is$\Theta(1)$$\Theta(\sqrt{\log} n)$$\Theta(\frac{\log n}{\log \log n})$$\Theta(\log n)...
18.2k
views
12 answers
65 votes
In a depth-first traversal of a graph $G$ with $n$ vertices, $k$ edges are marked as tree edges. The number of connected components in $G$ is$k$$k+1$$n-k-1$$n-k$
2.0k
views
1 answers
6 votes
Consider the following four data structures: array, binary search tree, hash table, and a linked list. Which of the following options arranges them in non-decreasing orde...
791
views
2 answers
1 votes
How much extra space is used by heapsort ?$O (1)$$O (\log n)$$O (n)$$O (n^2)$
101
views
0 answers
0 votes
can anyone have the algorithm notes from go classes (PDF or material)
43.9k
views
8 answers
19 votes
The minimum number of comparisons required to sort 5 elements is -4567
197
views
1 answers
1 votes
What is the returned value by the given function below.Algo fun(n){ If(x<=2) return 1; Else { Return fun(n1/2) + n; }}Note : Assume that all...
11.7k
views
4 answers
34 votes
Consider a weighted, undirected graph with positive edge weights and let $uv$ be an edge in the graph. It is known that the shortest path from the source vertex $s$ to $u...
206
views
0 answers
0 votes
Calculate the minimum and maximum number of element comparisons involved in 2 way merge sort assuming n is power of 2.
287
views
1 answers
0 votes
For flag based approach in Bubble sort we can check first by a flag if the list is sorted or not in O(n), and if it is sorted, then no need to sort and the operation ends...
724
views
2 answers
1 votes
An international cellphone company provides service on 7 different frequencies. They wish to set up business in Tamil Nadu and have fixed the locations of 100 towers for ...
8.1k
views
7 answers
21 votes
Consider the DAG with $V = \{1,2,3,4,5,6\}$ shown below.Which of the following is not a topological ordering?$1$ $2$ $3$ $4$ $5$ $6$$1$ $3$ $2$ $4$ $5$ $6$$1$ $3$ $2$ $4$...
To see more, click for all the questions in this category.