# Recent questions and answers in Algorithms

is bubble sort an online algorithm? cause whenever new element is fed, it can be take to its place by swapping the adjacent numbers. is my thinking right?
Consider the following three functions. $f_1=10^n\quad f_2=n^{\log n}\quad f_3=n^{\sqrt {n}}$ Which one of the following options arranges the functions in the increasing order of asymptotic growth rate? $f_3, f_2, f_1$ $f_2, f_1, f_3$ $f_1, f_2,f_3$ $f_2, f_3, f_1$
for an almost sorted array, which algorithm is better, shell sort or insertion sort? and also for a fully sorted array?
I am currently studying dynamic programming for GATE 2022. I am kinda stuck with which problems to prioritize. Can someone help? #dynamic-programming
if we require a large(more than size of array or 1000000mb) but constant( irrespective of size of input array) extra space for an algorithm, will the algorithm be in place or not? the extra space is not required to manipulate the elements of array but may be required for some other purpose.
We can reduce the space complexity of heapsort to o(1) by using heapify using loops, then why we dont reduce the space complexity of heapify from o(logn) to o(1) by using loops here also.?
This is in regards to Binary tree. The question is The image given below is full binary tree or not?
Hi Experts, I have been practicing Master Theorem since Yesterday as I am recently involved in algorithm course. I have found a hard the following problem whether the Master Theorem is applicable or it violates rules. if yes then kindly elaborate for better understanding…. Apology for English grammar T(n) = 2^1.534T( n 2 ) + 2^ 2n
1 vote
Every graph having minimum one spanning tree 1. True 2.False Which is correct? My doubt is spanning tree is possible for any type of graph??
Hi, I do not succeed in this question: Need to construct a right-linear grammar Would appreciate help :)
T(n)=T(n-1)-1 what is complexity of this
Considering the Huffman coding algorithm, the Huffman (encoding) tree requires more number of nodes than the distinct number of characters from the input file (say ‘n’). Then how is the space complexity for the algorithm = O(n), assuming the min-heap is operated on recursively?
Find a longest common subsequence between following strings: String1= {1, 2, 3, 4, 5, 6, 7, 8} String2={1,1,9,1,9,7,3,9} (Neatly show all the steps and also write the algorithm)(Analyze the running time of the given problem).
n^3 + n^2logn = bigoh(n^3) For satisfying above equation what should be the value of c??
If a graph contains n vertices then in minimum spanning tree(MST) will contain Minimum(n-1) edges Exact (n-1) edges. What will be the answer for this?? Plz explain with example for better understanding.
what is the time complexity in f( int n) { if(n <=2) return 1 else return f(floor(sqrt(n))) + n; }
Is binary search possible in sorted array where some elements repeat in array??
Sir, can ypu help me to find vedio solutions for all pyq questions that are asked in gate exam goup by subjects Thanks in advance
In quick sort the time complexity equation is T(n)=T(k)+T(n-k-1)+⊝(n) in average case how does the equation comes out to be T(n)=T(n/9)+T(9n/10)+⊝(n) in Average case.
in this question since they are asking function time so it depends on n and so that’s y time is O(1)?
How to Implement a stack with a priority queue ?
What is the correct answer for this question.Please give the detailed solution…..
Q.9 Determine the asymptotic running time of f(n) for the following C program. Int f(int n) int x; if (n == 0) x = 1: else x = f(n-1) 2; g(x): return x; void g(int m) { int y: for (y = m, y > 0; y/ = 2):}
Here, Chapter 9 is missing. This makes me loose 2 marks. Because I blindly believed that the content described in this material is accurate. So plz update the latest content in this material.
True/False 1) Multiplying all edge weight by a positive number might change the graph MST. 2) If all edge in a graph have distinct weight than the shortest path between two vertices is unique. Please answer with reason. Thanks
1 vote
1) Time complexity to construct a Binary tree when inorder and preorder/postorder traversal of the tree is given. a) if inorder sorted b) if inorder is not sorted. 2) If construct Binary tree when pre-order and postorder to the tree is given. .....… My answer: 1 a) O( nlogn) 1 b) O(nlogn) 2) O(2^n) Please check and correct Thanks
Let $G$ be a connected undirected weighted graph. Consider the following two statements. $S_1$: There exists a minimum weight edge in $G$ which is present in every minimum spanning tree of $G$. $S_2$: If every edge in $G$ has distinct weight, then $G$ has a unique minimum spanning ... $S_1$ is true and $S_2$ is false $S_1$ is false and $S_2$ is true Both $S_1$ and $S_2$ are false
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size $n$? $\Theta ( \sqrt{n})$ $\Theta (\log _2(n))$ $\Theta(n^2)$ $\Theta(n)$
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); if (y > x) return SomeFunction (x, y-x); } The value returned by $\textrm{SomeFunction(15, 255)}$ is __________
Consider the string $\textrm{abbccddeee}$. Each letter in the string must be assigned a binary code satisfying the following properties: For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. For any two letters ... assignments which satisfy the above two properties, what is the minimum length of the encoded string? $21$ $23$ $25$ $30$
For constants $a \geq 1$ and $b>1$, consider the following recurrence defined on the non-negative integers: $T(n) = a \cdot T \left(\dfrac{n}{b} \right) + f(n)$ Which one of the following options is correct about the recurrence $T(n)$? If $f(n)$ is $n \log_2(n)$, then $T(n)$ ... $\Theta(n^{\log_b(a)})$ If $f(n)$ is $\Theta(n^{\log_b(a)})$, then $T(n)$ is $\Theta(n^{\log_b(a)})$
Consider the following directed graph: Which of the following is/are correct about the graph? The graph does not have a topological order A depth-first traversal starting at vertex $S$ classifies three directed edges as back edges The graph does not have a strongly connected component For each pair of vertices $u$ and $v$, there is a directed path from $u$ to $v$
Consider the following $\text{ANSI C}$ program #include <stdio.h> int foo(int x, int y, int q) { if ((x<=0) && (y<=0)) return q; if (x<=0) return foo(x, y-q, q); if (y<=0) return foo(x-q, y, q); return foo(x, y-q, q) + foo(x-q, y, q); } int main( ) { int r = foo(15, 15, 10); printf(“%d”, r); return 0; } The output of the program upon execution is _________
In a directed acyclic graph with a source vertex $\textsf{s}$, the $\textit{quality-score}$ of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex $v$ other than $\textsf{s}$, the quality-score of $v$ is ... quality-score of $\textsf{s}$ is assumed to be $1$. The sum of the quality-scores of all vertices on the graph shown above is _______
Consider the following array.$\begin{array}{|l|l|l|l|l|l|} \hline 23&32&45&69&72&73&89&97 \\ \hline\end{array}$ Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order? Selection sort Mergesort Insertion sort Quicksort using the last element as pivot
Consider the following undirected graph with edge weights as shown: The number of minimum-weight spanning trees of the graph is ___________.
Consider the following recurrence relation. $T\left ( n \right )=\left\{\begin{array} {lcl} T(n ∕ 2)+T(2n∕5)+7n & \text{if} \; n>0\\1 & \text{if}\; n=0 \end{array}\right.$ Which one of the following options is correct? $T(n)=\Theta (n^{5/2})$ $T(n)=\Theta (n\log n)$ $T(n)=\Theta (n)$ $T(n)=\Theta ((\log n)^{5/2})$
Define $R_n$ to be the maximum amount earned by cutting a rod of length $n$ meters into one or more pieces of integer length and selling them. For $i>0$, let $p[i]$ denote the selling price of a rod whose length is $i$ meters. Consider the array of prices: ... $R_7$? $R_7=18$ $R_7=19$ $R_7$ is achieved by three different solutions $R_7$ cannot be achieved by a solution consisting of three pieces
Consider a $\textit{dynamic}$ hashing approach for $4$-bit integer keys: There is a main hash table of size $4$. The $2$ least significant bits of a key is used to index into the main hash table. Initially, the main hash table entries are empty. Thereafter, when more keys are hashed into it, to resolve ... in decimal notation)? $5,9,4,13,10,7$ $9,5,10,6,7,1$ $10,9,6,7,5,13$ $9,5,13,6,10,14$
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++) total=x*total +Y[loopIndex]; return total; } Let $\textsf{Z}$ be an array of $10$ elements with $\textsf{Z}[i]=1$, for all $i$ such that $0 \leq i \leq 9$. The value returned by $\textsf{SimpleFunction(Z},10,2)$ is __________