# Recent questions tagged algorithms

Big O is fn=c.gn for some values of constant 'c>0' and for little o it is fn=c.gn for all values of constant 'c>0', now my question is what is the difference between this some c>0 and all values of c>0 mentioned here
Which of the following is/are true? [MSQ] If f(n) = Ο(g(n)) and g(n) = Ο(h(n)), then h(n) = Ω( f(n)) If f(n) = Ο(g(n)) and g(n) = Ο( f(n)) then f(n) = θ(g(n)) The sequence < 20, 15, 18, 7, 9, 5, 12, 3, 6, 2 ... heap. After each insertion, the heap still has the max-heap property, so after n Insert operations, it is a max-heap on the n elements. Then this heap construction runs in Ο(n logn) time.
Help me solve these three questions on Master’s Theorem: T(n) = T(n/2) + 2^n T(n) = 2T (n/2) + n/logn T(n) = 16T (n/4) + n!
I am making a list of different types of numericals that can possibly come in GATE from different subjects .. This list is not comprehensive, so please ... ?fbclid=IwAR0ezzTYvJdobF2hXtr3xVNZpZOFtw96yHAywR2_j9BOKGe1mBNSgVUcsvw#9xiori58gq22i 7. https://www.mediafire.com/folder/gp6z7khjzyl8d/gate_materials?fbclid=IwAR0ezzTYvJdobF2hXtr3xVNZpZOFtw96yHAywR2_j9BOKGe1mBNSgVUcsvw#mp3qyi2prh3fb
Assume a scenario in which min-max heap has the following property: An almost complete binary tree where each node at an even level in the tree is less than all of its descendants and each of the node at an odd level in the tree is greater than all of its descendants. The worst-case ... log n) respectively (d) Ο(n) for max and Ο(log n) for min or Ο(n) for min and Ο(log n) for max respectively
There is an algorithm that took array of strings, sorted each string and then sorted the entire array.What would be the runtime?
Did not understand answer of this question plz help me to resolve problem.
// C++ implementation to find the character in first // string that is present at minimum index in second // string #include <bits/stdc++.h> using namespace std; // function to find the minimum index character void printMinIndexChar(string str, string patt) { // ... is present in unordered map or not because it only returns true or false but how can we assign the character inside the if condition.
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?
for an almost sorted array, which algorithm is better, shell sort or insertion sort? and also for a fully sorted array?
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
In avl tree can we take base case for minimum height as n(1)=2 rather than n(0)=1 in the recurrence relation : n(h)=2n(h-1)+1 where h is height of the tree.
T(n)=T(n-1)-1 what is complexity of this
"In Binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2." How is this statement valid in case of Left or Right Skewed Binary tree?
what is the time complexity in f( int n) { if(n <=2) return 1 else return f(floor(sqrt(n))) + n; }
How to Implement a stack with a priority queue ?
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.
1 vote
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 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$
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})$
1 vote
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, 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 __________