category
stringclasses
107 values
title
stringlengths
15
179
question_link
stringlengths
59
147
question_body
stringlengths
53
33.8k
answer_html
stringlengths
0
28.8k
__index_level_0__
int64
0
1.58k
algorithm complexity
Complexity of recursive algorithm
https://cs.stackexchange.com/questions/121142/complexity-of-recursive-algorithm
<p>I'm having hard time understanding time complexity of my solution for <a href="https://leetcode.com/problems/combination-sum/" rel="nofollow noreferrer">combination sum problem</a>. The problem is as follows:</p> <blockquote> <p>Given a set of candidate numbers (<code>candidates</code>) (without duplicates) and a...
<p>The obvious algorithm tries all subsets, i.e., is <span class="math-container">$O(2^n)$</span> if you have <span class="math-container">$n$</span> elements to select. And your algorithm does that (try with first element, try without first element).</p> <p>Complexity is given by the recurrence:</p> <p><span class="...
200
algorithm complexity
Time complexity of Prim&#39;s algorithm
https://cs.stackexchange.com/questions/85870/time-complexity-of-prims-algorithm
<p>There is this Prim's algorithm I am studying, the time complexity of which is $O(n^2)$ (in the adjacency matrix).</p> <p>As far as I have understood,that is because we have to ckeck all the nodes per every node, that is, when checking the first node's best edge, we have to check edges from the current node to all o...
<p>The time complexity is $O(n^2)$ because $O(n\cdot(n-1)) = O(n^2)$</p> <p>The big-O notation is showing the worst-case performance of one algorithm, it is not showing the exact number of steps the algorithm will make, but only its overall complexity</p> <p>For example $$O(2n) = O(n)\\O(3n) = O(n)\\O(\frac{n}{2}) = ...
201
algorithm complexity
Is the DPLL algorithm complexity in terms of # of clauses or # of variables?
https://cs.stackexchange.com/questions/14004/is-the-dpll-algorithm-complexity-in-terms-of-of-clauses-or-of-variables
<p>I'm a bit confused how worst case complexity is estimated for the <a href="http://en.wikipedia.org/wiki/DPLL_algorithm" rel="nofollow">DPLL algorithm</a>. Is it in terms of number of clauses, number of variables, or something else?</p>
<p>In the papers I've read the time complexity of DPLL is expressed in terms of the number of variables in the CNF formula. Using the number of clauses is inappropriate in general because it is known that random k-SAT instances go through an easy-hard-easy transition if you fix the number of variables and increase the...
202
algorithm complexity
Level Ancestor Query long-paths algorithm complexity of sqrt n
https://cs.stackexchange.com/questions/130826/level-ancestor-query-long-paths-algorithm-complexity-of-sqrt-n
<p>Can someone explain why the complexity of a query for LA is √n when we only decompose the tree into long-paths? How can we show/prove that?</p> <p>How can we prove that the <strong>number of paths can be as high as O(√n)</strong> ??? Please help, I've been struggling for a couple of days now.</p> <p>Stage 1: <a href...
203
algorithm complexity
Definition of complexity of an algorithm
https://cs.stackexchange.com/questions/157219/definition-of-complexity-of-an-algorithm
<p>In a sorting algorithm, While computing the complexity of an algorithm why do we only account for the number of comparisons done but not the number of swappings done? And what's the formal definition of complexity?</p>
<p>The formal definition of complexity of an algorithm is the runtime in terms of the length of the input. Meaning, suppose you have a number with size n, to represent the number n you need <span class="math-container">$log_2(n)$</span>. Thus, the actual time complexity is the runtime relative to <span class="math-cont...
204
algorithm complexity
Complexity of recursive Fibonacci algorithm
https://cs.stackexchange.com/questions/14733/complexity-of-recursive-fibonacci-algorithm
<p>Using the following recursive Fibonacci algorithm:</p> <pre><code>def fib(n): if n==0: return 0 elif n==1 return 1 return (fib(n-1)+fib(n-2)) </code></pre> <p>If I input the number 5 to find fib(5), I know this will output 5 but how do I examine the complexity of this algorithm? How do I calcu...
<p>Most of the times, you can represent the recursive algorithms using recursive equations. In this case the recursive equation for this algorithm is $T(n) = T(n-1) + T(n-2) + \Theta(1)$. Then you can find the closed form of the equation using the substitution method or the expansion method (or any other method used to...
205
algorithm complexity
Euclid&#39;s Algorithm Time Complexity
https://cs.stackexchange.com/questions/72200/euclids-algorithm-time-complexity
<p>I have a question about the Euclid's Algorithm for finding greatest common divisors.</p> <p>gcd(p,q) where p > q and q is a n-bit integer.</p> <p>I'm trying to follow a time complexity analysis on the algorithm (input is n-bits as above)</p> <pre><code>gcd(p,q) if (p == q) return q if (p &lt; q) ...
<p>Here is the idea of the proof. Throughout, we assume that $p \geq q$.</p> <p>Let $p^{(t)},q^{(t)}$ be the values of $p,q$ after $t$ iterations, so that $p^{(0)}=p$ and $q^{(0)}=q$.</p> <p>Let $F_m$ be the $m$th Fibonacci number, which satisfies $F_m = \Theta(\varphi^m)$, where $\varphi = \frac{1+\sqrt{5}}{2} &gt; ...
206
algorithm complexity
Simplex algorithm experimental complexity
https://cs.stackexchange.com/questions/76347/simplex-algorithm-experimental-complexity
<p>For a school project I am doing on linear programming, I've implemented the simplex algorithm in Python. </p> <p>I was hoping to check the complexity on a number of matrices. </p> <p>Preferably, they would have to be in standard form ($Ax=b$ and $x\geq0$) (or easily put into standard form) and would have to have a...
207
algorithm complexity
Complexity of Longest Palindromic Subsequence Algorithm
https://cs.stackexchange.com/questions/93104/complexity-of-longest-palindromic-subsequence-algorithm
<p>I'm trying to find the longest palindromic subsequence for any string and I've tried two approaches: </p> <ol> <li>Recursive Algoritm</li> <li>Dynamic Programming</li> </ol> <p>Dynamic programming should be the better option in this case because of the time complexity but the time complexity of both algorithms is ...
<p>The dynamic programming approach is indeed <code>O(n^2)</code>. However, the recursive solution is exponential in <code>n</code>: any time two characters don't match, a subproblem of size <code>k</code> is converted into <code>2</code> subproblems of size <code>k-1</code> each. It's easy to see that, with all letter...
208
algorithm complexity
Complexity of the Dijkstra algorithm
https://cs.stackexchange.com/questions/57226/complexity-of-the-dijkstra-algorithm
<p>I'm little confused by computing a time complexity for <code>Dijkstra</code> algorithm. It is said that the complexity is in $O(|V|^2)$ - <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow" title="Wikipedia - Dijkstra">Wikipedia - Dijkstra</a>, which I understand. It's because for each node...
<blockquote> <p>For each v from V, we relax only those edges e, which werent computed yet. If vertex v is already computed (red on gif above), we don't need to work with it anymore.</p> </blockquote> <p>Your are assuming that each edge is visited only once, but this assumption is not quite right. Let's say we ha...
209
algorithm complexity
Compare Complexity of Graph Algorithm
https://cs.stackexchange.com/questions/52796/compare-complexity-of-graph-algorithm
<p>Assume I know that there is an algorithm of complexity<br> $ \mathcal{O}( log ( \vert V \vert^2 \vert E \vert ) ) $ for a Graph $G(E,V)$.</p> <p>How do I compare this for example to the complexity of<br> $ \mathcal{O}( \vert V \vert^2 + \vert E \vert ) $ or other complexity algorithms on $G$. </p> <p>There has to...
<p>First of all $\min (|E|) = 0$ since the graph can be disconnected. $\min(|E|) = |V| - 1$, is true only for connected graphs. Whether a vertex is needed to be connected to the graph depends on the problem being considered. In general, a vertex can be isolated. So, in general, $0 \leq |E| \leq {{|V|}\choose{2}}$, if t...
210
algorithm complexity
Time Complexity of Algorithm
https://cs.stackexchange.com/questions/14298/time-complexity-of-algorithm
<p>I need help with finding out the time complexity of the following algorithm:</p> <pre><code>procedure VeryOdd(integer n): for i from 1 to n do if i is odd then for j from i to n do x = x + 1 for j from 1 to i do y = y + 1 </code></pre> <p>This is my attempt:</p> <p>$$ Loop1 = \Theta(n)$$ $$ ...
<p>$$ Loop 1 = \theta(n) $$ Since both loop in total will run n times so, $$ Loop 2 + Loop3 = \theta(n) $$ $$ T(n) = \theta(n) * 1/2 ( \theta(n)) = \theta(n^2) $$</p>
211
algorithm complexity
Counterexample to an Algorithm Complexity Statement
https://cs.stackexchange.com/questions/100944/counterexample-to-an-algorithm-complexity-statement
<p>Say I have the following statement:</p> <blockquote> <p>If <span class="math-container">$f(n) = O(s(n))$</span> and <span class="math-container">$g(n) = O(r(n))$</span>, then <span class="math-container">$f(n) - g(n) = \Theta(s(n) - r(n))$</span>.</p> </blockquote> <p>What would be a counterexample to this?</p>
<p>A lot of counterexamples! <span class="math-container">$f(n) = n, s(n) = n, g(n) = n, r(n) = n^2$</span>. <span class="math-container">$f(n) - g(n) = 0 = \Theta(n^2 - n) = \Theta(n^2)$</span>.</p>
212
algorithm complexity
What time complexity is a reachability algorithm?
https://cs.stackexchange.com/questions/124959/what-time-complexity-is-a-reachability-algorithm
<p>I've read there are ways you can determine all reachable pairs using Strongly Connected Components. But, I want to calculate all reachable nodes on the fly - so I don't have to store a massive reachability matrix in RAM. What sort of time complexity would be possible for an algorithm to calculate all reachable nodes...
<p>You can calculate all reachable nodes in <span class="math-container">$O(V+E)$</span> time and <span class="math-container">$O(V)$</span> space, using DFS on the fly.</p> <p>If you want to use less than <span class="math-container">$O(V)$</span> space, then the problem becomes much more challenging. I recommend lo...
213
algorithm complexity
Finding time complexity of an algorithm
https://cs.stackexchange.com/questions/68745/finding-time-complexity-of-an-algorithm
<p>I am to find the time complexity of my algorithm and I found one method <a href="https://en.wikipedia.org/wiki/Time_complexity" rel="nofollow noreferrer">here</a>.<br> However I am really not sure about it correctness thus I would like to check it.<br> There is my algorithm (N is a set (len(N) is constant) and C is ...
214
algorithm complexity
Complexity of dynamic programming algorithm for Knapsack
https://cs.stackexchange.com/questions/43175/complexity-of-dynamic-programming-algorithm-for-knapsack
<p>Dynamic programming algorithm for Knapsack is stated to have complexity $\mathcal O (nW)$.</p> <p>However, I've also seen the complexity stated as $\mathcal O (n^2V)$, where $V=\max v_i$.</p> <p>(Here $n$ is the number of items and $W$ the weight limit).</p> <p>I see from the algorithm that the first complexity m...
<p>The first complexity measure is in terms of the target weight, the second in terms of the heaviest element. Since $W \leq nV$ (or rather, we can assume that $W \leq nV$), the first estimate $O(nW)$ implies the second $O(n^2V)$. So $O(nW)$ is a stronger estimate than $O(n^2V)$.</p>
215
algorithm complexity
Recursive euclid algorithm for gcd complexity
https://cs.stackexchange.com/questions/90573/recursive-euclid-algorithm-for-gcd-complexity
<p>I am trying to calculate the complexity of the euclidean algorithm for finding the greatest common divisor (gcd) (recursive version). </p> <p>Here's the pseudo code:</p> <pre><code>algorithm euclid(a,b) if b = 0 then return a else return euclid(b, a mod b) end if </code></pre> <p>My initial thought is tha...
216
algorithm complexity
Complexity of an algorithm with multiple inputs
https://cs.stackexchange.com/questions/53650/complexity-of-an-algorithm-with-multiple-inputs
<p>I've just started reading about the complexity of algorithms, but everywhere I look, it is only defined for one input $n$. For example an algorithm is cubic if its complexity is $O(n^3)$.</p> <p>But what about when the complexity depends on several inputs? For example if an algorithm has complexity $O(n^2k)$, is it...
<p>[If I have time, I'll answer the rest of the question later.]</p> <blockquote> <p>I've also seen phrases such as 'cubic in $k$ and $n$'; what does this mean exactly?</p> </blockquote> <p>It's vague, unfortunately, and you should avoid writing anything like this, ever. It means at the very least, that the comple...
217
algorithm complexity
Time complexity of algorithms
https://cs.stackexchange.com/questions/139140/time-complexity-of-algorithms
<p>I have some questions that I don't understand about time complexity.</p> <ol> <li>Given that the worst case complexity of the algorithm <span class="math-container">$A$</span> is <span class="math-container">$O(f(n))$</span> and the best case complexity of <span class="math-container">$A$</span> is <span class="math...
<p>The first and the last statements are correct, while the second one is <em>incorrect</em>.</p> <h2>Statement 1</h2> <p>Denote by <span class="math-container">$T_{min}$</span> the actual running time of the algorithm <span class="math-container">$A$</span>, in the best case, and <span class="math-container">$T_{max}$...
218
algorithm complexity
Calculating the complexity of an algorithm exercises
https://cs.stackexchange.com/questions/97402/calculating-the-complexity-of-an-algorithm-exercises
<p>I am really bad at calculating correctly the complexity of a given algorithm. I would like to know if there is some book or online resources where I can find many exercises that ask to calculate the complexity of a given algorithm. </p> <p>Thank you! </p>
219
algorithm complexity
Complexity time needed for any algorithm
https://cs.stackexchange.com/questions/62727/complexity-time-needed-for-any-algorithm
<p>How to understand at least a small introduction to the complexity time for algorithm , how i can know that algorithm need O(log^2 N ) and so on is there any basic reference for this topic , needed in my project </p>
220
algorithm complexity
Optimal algorithmic complexity of &quot;a nonrepetitive stack&quot;?
https://cs.stackexchange.com/questions/154426/optimal-algorithmic-complexity-of-a-nonrepetitive-stack
<p>I'm wondering about the optimal complexity - or at the very least, some way of achieving non-terrible complexity - of a particular stack variant, that I'm calling a 'nonrepetitive stack'.</p> <p>A nonrepetitive stack is like an ordinary stack, except that a push that would result in a repeated subsequence fails, not...
<p>Kosolobov [1] solved this exact problem. The first algorithm in the paper supports stack operations on a string while detecting a repeated substring, and each operation takes amortized <span class="math-container">$O(\log m)$</span> time where <span class="math-container">$m$</span> is the maximum string length so f...
221
algorithm complexity
Computation Complexity of stream algorithm
https://cs.stackexchange.com/questions/87316/computation-complexity-of-stream-algorithm
<p>I want to analyze a clustering algorithm that clusters data stream. Since the stream can be unbounded, I cannot write O(N^2), or explicitly denote the size of the stream. How can I use the arrival rate of the data for the computation complexity? Do you have any other idea for correct analysis of stream computation (...
<p>One standard way to measure the running time of streaming algorithms is to count the amount of time taken <em>per item</em> that the algorithm processes. For instance, one algorithm might take $O(1)$ time per item.</p> <p>Also it is common to analyze the memory usage (space complexity) of these algorithms, as in m...
222
algorithm complexity
Time complexity of Rabin-Karp algorithm
https://cs.stackexchange.com/questions/93009/time-complexity-of-rabin-karp-algorithm
<blockquote> <p><strong>$n$ : length of text T</strong> </p> <p><strong>$m$ : length of pattern P</strong></p> </blockquote> <p>When I study Rabin-Karp algorithm, I learned the best case of this algorithm is $\theta(n-m+1)$. Because if a hashed number is too small to modulo by some other number.</p> <p>But whe...
<p>The running time you quote isn't correct. If $n = m$ then it takes $\Omega(n)$ to verify that $T = P$. The best case running time of <em>any</em> string matching algorithm is $\Omega(m)$, since this is how long it takes to verify a match. Perhaps you are disregarding the time it takes to compute the hashes.</p> <p>...
223
algorithm complexity
Complexity of an algorithm with nested loops
https://cs.stackexchange.com/questions/163411/complexity-of-an-algorithm-with-nested-loops
<p>How do I calculate the complexity of this Algorithm below? I would like to know how I calculate the sums that form to obtain a formula as a function of n? I know that in general this algorithm has O(n^3) complexity, but how can I do that?</p> <pre><code>int i,j,k,s; for(i=0; i &lt; N-1; i++) for(j=i+1; j &lt; ...
224
algorithm complexity
The complexity of the algorithm with loops
https://cs.stackexchange.com/questions/63216/the-complexity-of-the-algorithm-with-loops
<p>I have algorithm that contains next loops:</p> <pre><code>for (int i = 0; i &lt; size; ++i) { for (int j = i + 1; j &lt; size; ++j) { //Do stuff } } </code></pre> <p>I found that this algorithm has $O(n^2)$ complexity but I can't understand why? I.e. if $N = 4$ then $n^2 = 16$ but my loop has 6 it...
<p>Your "stuff" will get executed $N(N - 1)/2 = 0.5N^2 - 0.5N$ times. When analyzing the asymptotic complexity, only the highest order term is kept, and multiplicative constants are removed, leaving you with $O(N^2)$. </p> <p>It works this way because we're interested in what happens when $N$ goes to infinity (scalabi...
225
algorithm complexity
calculate the complexity of binary search algorithm
https://cs.stackexchange.com/questions/92416/calculate-the-complexity-of-binary-search-algorithm
<p>How do i calculate the complexity of this algorithm at the best case and its complexity at the worst case and the average complexity by assuming that the probability that the element is in the list is 0≤p≤1 and that all sites are equal probability</p>
226
algorithm complexity
Complexity of set oprations in algorithm
https://cs.stackexchange.com/questions/67053/complexity-of-set-oprations-in-algorithm
<p>I am designing a graph algorithm. Some steps of the algorithm, are set operations (union, difference, intersection, set-membership).</p> <p>Can I assume them as $~ \mathcal{O}(1)$ operations? Have someone used them as $~\mathcal{O}(1)$ in his paper?</p> <p>What minimum complexity should I assume for these operatio...
227
algorithm complexity
computational complexity of a tree pruning algorithm
https://cs.stackexchange.com/questions/86698/computational-complexity-of-a-tree-pruning-algorithm
<p>I've just designed an algorithm to prune a tree related to a particular fluid dynamics problem, and I need to determine its computational complexity; however, since I'm just a newcomer (from mechanical engineering) to the computational complexity theory, I'm not sure about the following reasoning:</p> <p><a href="h...
228
algorithm complexity
Time Complexity: Intuition for Recursive Algorithm
https://cs.stackexchange.com/questions/92859/time-complexity-intuition-for-recursive-algorithm
<p>I decide to learn more about dynamic programming, so I started reading the Dynamic Programming chapter from the CLSR book.</p> <p>The first example problem presented there is Rod Cutting (15.1). Given a rod of length n and a list of prices for rods of any sizes figure out how to cut the rod so that the price of the...
<p>Based on the code you show there, your intuition is right.</p> <p>However, it looks like there is a typo in the code and the next-to-last line should have been</p> <pre><code> q = max(q, p[i] + CutRod(p, n-i)) </code></pre> <p>i.e., <code>n-i</code> rather than <code>n-1</code>. Try to work through a proof of c...
229
algorithm complexity
Can a time-optimal algorithm have a time complexity better than its space complexity?
https://cs.stackexchange.com/questions/165152/can-a-time-optimal-algorithm-have-a-time-complexity-better-than-its-space-comple
<p>That's what I'm formally asking:</p> <p>Let the algorithm <span class="math-container">$A$</span> have the worst-case time complexity <span class="math-container">$\Theta(f(n))$</span>, such that for any algorithm <span class="math-container">$B$</span> with the worst-case time complexity <span class="math-container...
230
algorithm complexity
Check Welzl&#39;s algorithm time complexity
https://cs.stackexchange.com/questions/147944/check-welzls-algorithm-time-complexity
<p>From the <a href="https://en.wikipedia.org/wiki/Smallest-circle_problem#Welzl%27s_algorithm" rel="nofollow noreferrer">wiki</a> this is the algorithm and we know that final complexity is O(n) but how we reached to this , is my problem :</p> <pre><code>algorithm welzl is input: Finite sets P and R of points in th...
<p>Note that the expected running time analysis is <span class="math-container">$O(n)$</span>. It is given in the <a href="https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.46.1450&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">original</a> paper itself (Section 2).</p> <p>Here, I am simply analyzing the ...
231
algorithm complexity
I do not know if my algorithm complexity is $P$, $NP$ or $NP-hard$?
https://cs.stackexchange.com/questions/77021/i-do-not-know-if-my-algorithm-complexity-is-p-np-or-np-hard
<p>I developed an algorithm but just not sure what is the complexity of the algorithm. I provide a brief description of it below:</p> <p>"For $N$ user case, there are $B(N)$ Decision Variables. $B(N)$ is Bell Number, for those of you who are not familiar with Bell Numbers please be noted that $B(N)$ grows exponentiall...
<p>Your question is somewhat malformed because <strong>P</strong> and <strong>NP</strong> are classes of problems, not algorithms. For example, as you state, the <em>problem</em> of sorting is in <strong>P</strong>. However, that doesn't mean that <em>every</em> sorting algorithm runs in polynomial time. For example, ...
232
algorithm complexity
Time complexity of a backtrack algorithm
https://cs.stackexchange.com/questions/13181/time-complexity-of-a-backtrack-algorithm
<p>I've developed the following backtrack algorithm, and I'm trying to find out it time complexity.</p> <p>A set of $K$ integers defines a set of modular distances between all pairs of them. In this algorithm, I considered the inverse problem of reconstructing all integer sets which realize a given distance multiset. ...
<p>The running time of your algorithm is at most $N (N-1) (N-2) \cdots (N-K+1)$, i.e., $N!/(N-K)!$. This is $O(N^K)$, i.e., exponential in $K$.</p> <p>Justification: There are $N$ possible choices for what you put into the first blank, and in the worst case you might have to explore each. There are $N-1$ choices for...
233
algorithm complexity
Complexity of a recursive bignum multiplication algorithm
https://cs.stackexchange.com/questions/14685/complexity-of-a-recursive-bignum-multiplication-algorithm
<p>We have started learning about analysis of recursive algorithms and I got the gist of it. However there are some questions, like the one I'm going to post, that confuse me a little.</p> <h3>The exercise</h3> <blockquote> <p>Consider the problem of multiplying two big integers, i.e. integers represented by a large nu...
<p>The idea is to divide each $n$-bit integer into two halves of $n/2$ bits. For example, $10100010$ would be divided into $1010$ and $0010$. Naively, we would need to multiply four such halves, but in fact there is a way to do with only three. (This is similar to matrix multiplication algorithms such as Strassen's.) T...
234
algorithm complexity
Definition of space complexity when algorithm cycles.
https://cs.stackexchange.com/questions/79946/definition-of-space-complexity-when-algorithm-cycles
<p>I'm reading side by side my class notes and Papadimitrious' Computational Complexity book. At this point they are talking about space complexity. They give rules for computing space employed in an algorithm that runs on a multi-tape Turing machine:</p> <ol> <li>We count the cells used.</li> <li>If we don't write in...
<blockquote> <p>So how does one measure the space complexity of an algorithm that may cycle forever?</p> </blockquote> <p>When we say that some language $L$ belongs to some complexity class it is assumed that a TM (algorithm) <strong>decides</strong> $x \in L$ in finite space and time amount. In other words, the TM/...
235
algorithm complexity
Algorithm complexity of this program is O(n) or O(n^3)?
https://cs.stackexchange.com/questions/86238/algorithm-complexity-of-this-program-is-on-or-on3
<p>I am very much confuse that why complexity of this program is O(n)?</p> <pre><code> int j = 0; int i; For (i = 0; i &lt; n, i++) // O(n) { For (i = 0; i &lt; n, i++)//O(n) { While (j &lt; n)// O(n) { Statement; j++; } } } </code></pre> <p>I am totally new to Alg...
236
algorithm complexity
Complexity inversely propotional to $n$
https://cs.stackexchange.com/questions/3495/complexity-inversely-propotional-to-n
<p>Is it possible an algorithm complexity decreases by input size? Simply $O(1/n)$ possible?</p>
<p>Consider an algorithm with some running time bounded by $f(n)$ and suppose that $f(n) \in O(1/n)$. That means that there is some constant $c$ such that for sufficiently large values of $n$, it holds that $$f(n) \leq c\frac{1}{n}.$$ Clearly, for any fixed $c$ and sufficiently large $n$, the right side will be strictl...
237
algorithm complexity
Termination proof and complexity of a algorithm
https://cs.stackexchange.com/questions/106224/termination-proof-and-complexity-of-a-algorithm
<p>I have written the following algorithm </p> <ul> <li><span class="math-container">$select(\Pi)$</span> select the first elements from <span class="math-container">$\Pi$</span>. When there are no element in <span class="math-container">$\Pi$</span>, it return <span class="math-container">$\emptyset$</span>. Always t...
238
algorithm complexity
Design an algorithm with linear complexity
https://cs.stackexchange.com/questions/157540/design-an-algorithm-with-linear-complexity
<p>Let A[1 : n] be a vector of n integers such that all elements except O(n^2/3) elements are between 1 and 10n. Design an algorithm with linear complexity that sorts A.</p> <p>Beyond the algorithm, what I can't fully understand is why we are provided with the information &quot;all elements except O(n^2/3)&quot; It is ...
<p>The reason you are provided that information is that, without this extra promise, it is not possible to sort in linear time. With this extra promise, it <em>is</em> possible to sort in linear time.</p> <p>It's your exercise, so I will leave it to you to come up with the strategy to sort such an array in linear time...
239
algorithm complexity
Algorithm with amortized time complexity
https://cs.stackexchange.com/questions/153341/algorithm-with-amortized-time-complexity
<p>While I understand the process of considering/observing an algorithm and finding an average time, necessary to perform an operation that happens in this algorithm, I still cannot quite gasp the idea, or rather the expression:</p> <p><strong>&quot;The Algorithm has an amortized time complexity which is cost./linear e...
<p>The amortized time is indeed the average time over a larger number of repetition of an operation (large enough that the variations are smoothed away).</p> <p>A typical example is a growable array supporting <code>push_back</code> operations. When there is room at the end of the allocated space, a <code>push_back</co...
240
algorithm complexity
Is there any relationship between time complexity and space complexity of an algorithm?
https://cs.stackexchange.com/questions/110934/is-there-any-relationship-between-time-complexity-and-space-complexity-of-an-alg
<p>For example:</p> <p>If algorithm A takes an input of size n, and has a time complexity of O(a^n) and a space complexity of O(1)</p> <p>Is there a way to increase the space complexity to something like O(n^2) that would guarantee that the time complexity would decrease?</p>
<blockquote> <p>If algorithm A takes an input of size n, and has a time complexity of O(a^n) and a space complexity of O(1)</p> </blockquote> <p>First of all we do not know any <em>exponential</em> or <em>sub-exponential time</em> algorithm that requires only <span class="math-container">$O(1)$</span> space, having ...
241
algorithm complexity
How to find an algorithm&#39;s complexity from actual running times
https://cs.stackexchange.com/questions/112083/how-to-find-an-algorithms-complexity-from-actual-running-times
<p>I have a certain algorithm which I can run, but I do not have access to its code. Thus, it works as a black box. I would like to now the order of complexity of this algorithm on a certain set of instances, which grow in size as a function of <span class="math-container">$n$</span>.</p> <p>Now, I have collected runn...
<p>You can do regression on the whole data to get a better fit.</p>
242
algorithm complexity
Can an algorithm complexity be lower than its tight low bound / higher than its tight high bound?
https://cs.stackexchange.com/questions/128174/can-an-algorithm-complexity-be-lower-than-its-tight-low-bound-higher-than-its
<p>The worst case time complexity of a given algorithm is <span class="math-container">$\theta(n^3logn)$</span>.<br /> Is it possible that the worst time complexity is <span class="math-container">$\Omega(n^2)$</span>?<br /> Is it possible that the worst time complexity is <span class="math-container">$O(n^4)$</span>?<...
<p>Let <span class="math-container">$t(x)$</span> be the time taken for input <span class="math-container">$x\in \{0,1\}^*$</span>, and <span class="math-container">$T(n)=\max_{x\in\{0,1\}^*,|x|=n}t(x)$</span> is the worst case.</p> <p>If <span class="math-container">$T\in\theta(n^3\log(n))$</span>, this means that the...
243
algorithm complexity
Definition of efficiency versus complexity of algorithm
https://cs.stackexchange.com/questions/71858/definition-of-efficiency-versus-complexity-of-algorithm
<p>When I read introductory textbooks I get contradictory answers. In some cases efficiency and complexity are treated the same and the big-O notation is used to indicate that (for example) for an O(n) algorithm the time to execute is linearly proportional to the input dataset size.</p> <p>From other sources I have re...
<p>An algorithm is often called "efficient" if its runtime is short, compared to the inherent difficulty of the problem. </p> <p>For example, you cannot sort arbitrary arrays by comparing keys in less than O (n log n). Once sorted you can lookup values in O (log n). Looking up a value in the sorted array by doing a li...
244
algorithm complexity
Algorithm with no closed-form exact complexity
https://cs.stackexchange.com/questions/60622/algorithm-with-no-closed-form-exact-complexity
<p>Does there exist an algorithm for which an exact complexity <em>provably</em> cannot be expressed in <a href="https://en.wikipedia.org/wiki/Closed-form_expression" rel="nofollow">closed-form</a>? </p> <p>Here closed-form means a <em>finite</em> composition of addition, subtraction, product, division, factorial, pow...
<p>The runtime of an algorithm that computes the Ackermann function can't be expressed using primitive recursive functions. All commonly known named functions (well, besides the Ackermann function) are primitive recursive as far as I know.</p>
245
algorithm complexity
Bentley–Ottmann algorithm time complexity issue
https://cs.stackexchange.com/questions/52979/bentley-ottmann-algorithm-time-complexity-issue
<p>In the <a href="https://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm" rel="nofollow">Bentley–Ottmann algorithm</a>, Regarding :</p> <blockquote> <p>Find the segments r and t that are immediately below and above s in T (if they exist) and if their crossing forms a potential future event in the event...
246
algorithm complexity
Binary search algorithm - worst-case complexity
https://cs.stackexchange.com/questions/67387/binary-search-algorithm-worst-case-complexity
<p>I tried to calculate the worst case of binary search (not binary search tree). My calculations: <span class="math-container">$$T(n) = T\left(\frac{n}{2}\right) + 1$$</span> <span class="math-container">$$T(n) = T\left(\frac{n}{4}\right) + (1+1) = T\left(\frac{n}{8}\right) + (1+1+1) = {\dots} = T\left(\frac{n}{2^{k}}...
<p>A much better way is to use the master method :), check that out!</p>
247
algorithm complexity
Need help verifying the complexity of an algorithm
https://cs.stackexchange.com/questions/159948/need-help-verifying-the-complexity-of-an-algorithm
<p>I have the following algorithm which takes as an input a non negative integer n : <br/> i = n <br/> while i &gt; 0 do : <br/> <span class="math-container">$\,$</span> <span class="math-container">$\,$</span> <span class="math-container">$\,$</span> <span class="math-container">$\,$</span>i = i - 1 <br/> <span class...
248
algorithm complexity
Shell algorithm knuth sequence time complexity analysis
https://cs.stackexchange.com/questions/160442/shell-algorithm-knuth-sequence-time-complexity-analysis
<p>Given this shell sort algorithm implementation:</p> <pre><code>void shell(float ∗a ,int l ,int r) { int i, j, h; for ( h = 1 ; 3∗h +1 &lt;= r−l; h = 3∗h + 1 ); for (; h &gt; 0; h / = 3) { for (i = l+h; i &lt;= r; ++ i) { for (j = i; j &gt;= l +h &amp;&amp; a[j] &lt; a[j−h]; j −= h) { swap (a+...
249
algorithm complexity
Is there an algorithm for algorithms time/space complexity optimisation?
https://cs.stackexchange.com/questions/51516/is-there-an-algorithm-for-algorithms-time-space-complexity-optimisation
<p>In 1950s a number of methods for <a href="https://en.wikipedia.org/wiki/Circuit_minimization_for_Boolean_functions" rel="nofollow">circuit minimization for Boolean functions</a> have been invented. Is there an extension of those methods or anything similar for optimising time or space complexity of algorithms?</p> ...
<p>Look up <a href="https://en.wikipedia.org/wiki/Blum&#39;s_speedup_theorem">Blum's speedup theorem</a> (yes, this article is less than informative; look at a book on complexity theory). It essentially says that there are programs for which there is a program doing the same job that is faster by any specified margin f...
250
algorithm complexity
Time complexity of tree algorithm
https://cs.stackexchange.com/questions/165081/time-complexity-of-tree-algorithm
<p>I'm new to recurrence relations and master theorem so trying to learn. Say there's an algorithm <span class="math-container">$A$</span> whose input is the root of a binary tree <span class="math-container">$T$</span>. <span class="math-container">$A$</span> recurses so that it's called on each and every node in <spa...
<p>Note that the complexity of the algorithm depends on the tree <span class="math-container">$T$</span>. For the maximally imbalanced tree, as you computed the complexity is <span class="math-container">$O(n^2)$</span>. Another important observation is that the complexity on this particular type of tree is <span class...
251
algorithm complexity
Time Complexity and Optimization for the Algorithm?
https://cs.stackexchange.com/questions/50072/time-complexity-and-optimization-for-the-algorithm
<p>I have found a algorithm to check whether a Hamiltonian Cycle Exists in the graph or not, but not able to compute/analyse it's time complexity.</p> <p>The algorithm is as follows :</p> <ol> <li>Label all the vertices with distinct prime numbers.</li> <li>Label all edges with weight equal to 1.</li> <li>Now remove ...
<p>Unfortunately, whenever you start thinking about algorithms that use the nice prime factorization property things start breaking down. Why? You never said <em>how</em> you could generate $n$ prime numbers. That is not $\in P$, in fact that is still an open problem in mathematics, how many prime numbers are there? So...
252
algorithm complexity
Complexity of peak finding algorithm for N dimensions
https://cs.stackexchange.com/questions/170041/complexity-of-peak-finding-algorithm-for-n-dimensions
<p>I am totally new in this area.</p> <p>Lets say we have a list of random numbers and we have to find one peak value (only one is fine), and a peak is if <span class="math-container">$a \geq$</span> than its both neighbours (or one if it is in on the edge). For example:</p> <p><a href="https://i.sstatic.net/3KNtaoJl.p...
<p>First of all, I recommend against using the term &quot;binary search&quot; in this context, since it's usually reserved for the specific problem of finding an element in a sorted list. I'd recommend calling it &quot;divide and conquer&quot;.</p> <p>Second, big-O notation looks like <span class="math-container">$O(f(...
253
algorithm complexity
Constant in Complexity of SQRT algorithm
https://cs.stackexchange.com/questions/30558/constant-in-complexity-of-sqrt-algorithm
<p>this is my first question in CS so I apologize if this question is off-topic.</p> <p>If we use Newton`s Method for finding square root then complexity is $O(M(n))$ (using Wikipedia Notation: $M(n)$ is the algorithm to multiply two $n$-digit numbers). </p> <p>I am interested to know whats the constant hidden in Lan...
254
algorithm complexity
Using software to calculate the complexity of an algorithm
https://cs.stackexchange.com/questions/12475/using-software-to-calculate-the-complexity-of-an-algorithm
<p>I am somewhat a beginner, and I have often seen complexity being calculated for various algorithms but they never actually gave me a very clear idea about how it is done. Can someone please point some resources where I can learn to calculate the complexity of an algorithm?</p> <p>Secondly, is there some software th...
<p>Depending on your background, the <a href="http://en.wikipedia.org/wiki/Introduction_to_Algorithms">CLRS book</a> is a solid introduction. I think in the very first chapter, they walk you through of how to analyze a simple algorithm in terms of both correctness (showing the algorithm really solves the problem) and c...
255
algorithm complexity
Calculate the complexity of an algorithm
https://cs.stackexchange.com/questions/76465/calculate-the-complexity-of-an-algorithm
<p>I have an algorithm here and it wants me to calculate the complexity:</p> <pre><code>for (i=1;i&lt;n;i++) for (j=1;j&lt;i*i;j++) if (j%i==0) for (k=0;k&lt;j;k++) sum++; </code></pre> <p>First of all, I think that i have different complexities for best, average and worst case but I don't know...
<p>The number of times that the <em>if</em> is executed is $$ \sum_{i=1}^{n-1} (i^2-1) = \Theta(n^3). $$ The number of times that <em>sum</em> is incremented is $$ \sum_{i=1}^{n-1} \sum_{\substack{1 \leq j &lt; i^2 \\ i \mid j}} j = \sum_{i=1}^{n-1} \sum_{k=1}^{i-1} ki = \sum_{i=1}^{n-1} i \binom{i}{2} = \Theta(n^4). $...
256
algorithm complexity
What is the algorithmic complexity of DFS under the cache oblivious model?
https://cs.stackexchange.com/questions/65409/what-is-the-algorithmic-complexity-of-dfs-under-the-cache-oblivious-model
<p>Consider the basic non-recursive DFS algorithm on a graph G=(V,E) (python-like pseudocode below) that uses array-based adjacency lists, a couple of arrays of size V, and a dynamic array stack of size &lt;= V. If I understand correctly, this is a cache oblivious algorithm since no information about the memory configu...
257
algorithm complexity
Notation for average case complexity of an algorithm
https://cs.stackexchange.com/questions/14960/notation-for-average-case-complexity-of-an-algorithm
<p>I'm just wondering what the correct notation is when referring to an average case complexity of an algorithm that was calculated by doing empirical analysis.</p> <p>For example, I have tested my algorithm and fitted the results to the curve $f(n)=2.65\times 10^{-15}\cdot(2.17^{n})$ and in my report right now I'm sa...
<p>The notation $\Theta(f(n))$ isn't reserved for worst-case complexity, it's asymptotic notation applicable to functions in general. So you can state that the average case complexity is $\Theta(2.17^n)$, and it means exactly what you think it does. (Regardless of whether this has been proved or not.)</p>
258
algorithm complexity
What&#39;s better for an algorithm complexity, O(log n) or amortized O(log n)?
https://cs.stackexchange.com/questions/12714/whats-better-for-an-algorithm-complexity-olog-n-or-amortized-olog-n
<p><strong>Some context:</strong> I'm to write a program that sorts the lines of a file in C for Linux. Since I have to read all lines of the file (<code>fgets()</code> for example) I'm thinking about inserting them in a tree like structure in a sorted manner using the so called tree sort algorithm.</p> <p>Looking for...
<p>$O(\log n)$ in the worst case implies $O(\lg n)$ amortized.</p> <p>Basically, given two data structures supporting the same operator, one in $O(\lg n)$ time in the worst case and the other one in $O(\lg n)$ amortized time, the first one is considered to be superior asymptotically: being $O(\lg n)$ time in the worst...
259
algorithm complexity
Complexity of dynamic card game algorithm
https://cs.stackexchange.com/questions/52668/complexity-of-dynamic-card-game-algorithm
<p>Consider the following dynamic card game with a regular deck of 26 red cards and 26 black cards. A dealer draws the unturned cards one by one, and we can ask him to stop at any time. For every red card drawn, we get 1 dollar and lose 1 dollar for every black card drawn. The problem consists in finding an algorithm w...
<p>As pointed out in the comments, your recurrence is wrong (though equivalent for $b=r$; it's a recurrence for $E(b,r)+b-r$). Also, you can solve this efficiently using memoization or its more principled cousin, dynamic programming. The dynamic programming solution calculates iteratively $E(i,j)$ for $i+j=0,1,\ldots,5...
260
algorithm complexity
Complexity of algorithm waiting $e^{n}$ seconds
https://cs.stackexchange.com/questions/167613/complexity-of-algorithm-waiting-en-seconds
<p>A dumb question in complexity theory.</p> <p>Let's consider an algorithm that solves the following problem:</p> <p>is <span class="math-container">$e^{n}$</span> time passed?</p> <pre><code>f(n): 1. let t = get_current_time() 2. wait(e^n) 3. return get_current_time()-t </code></pre> <p>Naively, I'd say this...
<p>There are some problems in your question:</p> <ol> <li>What is the computation model, and what is the operation &quot;wait&quot; in your model?</li> <li>&quot;Is <span class="math-container">$e^n$</span> time passed?&quot; is a very unclear statement. What is the input, and what is the question asked?</li> <li>&quot...
261
algorithm complexity
Suffix array construction algorithm linear complexity constant
https://cs.stackexchange.com/questions/92336/suffix-array-construction-algorithm-linear-complexity-constant
<p>A non-recursive linear Suffix Array construction algorithm is presented in this thesis: <a href="https://www.uni-ulm.de/fileadmin/website_uni_ulm/iui.inst.190/Mitarbeiter/baier/gsaca.pdf" rel="nofollow noreferrer">Linear-time Suffix Sorting</a>. The author claims that, overall, the algorithm runs at $O(n)$. While it...
<p>Constants like this are generally not calculated for the run time of algorithms, because it's not clear what they would count - would they count the number of some sort of primitive C operation executed, or the number of x86-64 operations, or the number of arm64 operations, or the microcode operations, or ...?</p> ...
262
algorithm complexity
Kosaraju&#39;s algorithm&#39;s time complexity
https://cs.stackexchange.com/questions/39955/kosarajus-algorithms-time-complexity
<p>I've reading up on Kosaraju's algorithm to compute the strongly connected components of a directed graph and I found that</p> <ol> <li>using an adjacency list representation gives a time complexity of $\Theta(V+E)$.</li> <li>using an adjacency matrix representation gives a time complexity of $O(V^{2})$.</li> </ol> ...
<p>Any algorithm for computing strongly connected components must examine at least $\binom{|V|}{2}$ entries in the worst case (proof below). In particular, since Kosaraju's algorithm is correct, its (worst-case) complexity is $\Omega(|V|^2)$, and so also $\Theta(|V|^2)$. There is no particular reason why Wikipedia used...
263
algorithm complexity
Calculating Time Complexity of Algorithm Using Incrementor Variable
https://cs.stackexchange.com/questions/112130/calculating-time-complexity-of-algorithm-using-incrementor-variable
<p>I am trying to calculate the time complexity of an algorithm using <code>n</code> in the code below.</p> <p>I have a working solution to a coding challenge to sort a stack using only another stack, and I've added a counter variable <code>n</code> that is incremented anywhere an element in the stack is pushed, poppe...
264
algorithm complexity
Time complexity of a tree-based algorithm
https://cs.stackexchange.com/questions/106350/time-complexity-of-a-tree-based-algorithm
<p>I solved a practice interview problem that was sent me by Daily Coding Problem mailing list. I am now curious about the exact time complexity of my solution.</p> <h2>Problem Statement</h2> <blockquote> <p>Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decod...
<p>You can show a simple exponential lower bound for you algorithm as follows.</p> <ol> <li>Assume we have a <span class="math-container">$d$</span> digit encoding (2 in your initial example).</li> <li>For any cipher text of length <span class="math-container">$n$</span> we can create a worst-case encoding of <span cl...
265
algorithm complexity
Problems with proven complexity but no algorithm yet found
https://cs.stackexchange.com/questions/63005/problems-with-proven-complexity-but-no-algorithm-yet-found
<p>Does there exists a computable problem P such that:</p> <ul> <li>Is proven that P can be solved with an algorithm that has a certain complexity.</li> <li>The best algorithm know unluckily is still slower (greater complexity) than the proven bound.</li> </ul> <p><strong>Example:</strong></p> <ul> <li>A problem tha...
266
algorithm complexity
Complexity of exponential algorithm, optimised with memoization?
https://cs.stackexchange.com/questions/68491/complexity-of-exponential-algorithm-optimised-with-memoization
<p>I was solving a problem, where one part of it was the following:</p> <p>"Given a m-sided dice ([1,m] values) that will be rolled n times, calculate the possibility that the total sum of rolls will be higher than b"</p> <p>Initially, I implemented a naive exponential solution, discovering the whole state space (DFS...
267
transformer architecture
What is prefix monotonicity?
https://cs.stackexchange.com/questions/7685/what-is-prefix-monotonicity
<p>I have a background in computer architecture and only cursory understanding of process networks. For a paper I am writing I need to understand prefix monotonicity properly. </p> <p>For now I have "a stream transformer is prefix monotonic if its output for a given input record r is dependent only on the input stream...
<p>This publication provides a definition of prefix monotonicity: <a href="http://www4.informatik.tu-muenchen.de/publ/papers/broy_acm93.pdf" rel="nofollow">link</a></p> <p>Definition:</p> <p><em>"Prefix monotonicity reflects a basic property of communicating systems: assume we have observed a finite sequence of outpu...
268
transformer architecture
How can we improve the capture of hierarchical structures in Graph Neural Networks (GNNs)?
https://cs.stackexchange.com/questions/171414/how-can-we-improve-the-capture-of-hierarchical-structures-in-graph-neural-networ
<p>Graph Neural Networks (GNNs) have proven to be powerful tools for modeling relationships in structured data, but one of their main limitations is their difficulty in capturing hierarchical structures within a graph. Message-passing methods primarily focus on local relationships, which can limit their ability to repr...
269
attention mechanism
Are there any neural NLG systems which don&#39;t generate in left-to-right order?
https://cs.stackexchange.com/questions/99987/are-there-any-neural-nlg-systems-which-dont-generate-in-left-to-right-order
<p>For a while, all classification tasks in natural language processing were based on simple RNN's, which operate in a very word-by-word order. Adding gating mechanisms increased ability to "look back", and the newer addition of context vectors which can train attention to different words during the task have made cla...
270
GPT model
Why GPT model is a higher order hidden markov model
https://cs.stackexchange.com/questions/160891/why-gpt-model-is-a-higher-order-hidden-markov-model
<p>I have read the GPT-1 paper, and my understanding is that it works as follows: <span class="math-container">$U$</span> is input tokens, <span class="math-container">$h_0=UW_e+W_p$</span>, <span class="math-container">$h_i=\text{transformer_block}(h_{i-1})$</span> and the output is a probability vector <span class="m...
<p>The statement that GPT is a higher order hidden Markov model should not be taken too seriously. It is intended as a slogan or intuition, not something that is intended to be be rigorously proven.</p> <p>Let <span class="math-container">$x_1,x_2,\dots,x_k$</span> denote the words of the text, in order (<span class="...
271
GPT model
Question about word embeddings in a specific language model - GPT-2
https://cs.stackexchange.com/questions/116184/question-about-word-embeddings-in-a-specific-language-model-gpt-2
<p>How were the <a href="https://openai.com/blog/better-language-models/" rel="nofollow noreferrer">GPT-2</a> token embeddings constructed? </p> <p>The authors mention that they used Byte Pair Encoding to construct their vocabulary. But BPE is a compression algorithm that returns a list of subword tokens that would be...
272
GPT model
What are the 175 billion parameters used in the GPT-3 language model?
https://cs.stackexchange.com/questions/156130/what-are-the-175-billion-parameters-used-in-the-gpt-3-language-model
<p>I am currently working my way through <em><a href="https://arxiv.org/abs/2005.14165" rel="nofollow noreferrer">Language Models are Few-Shot Learners </a></em>, the initial 75-page paper about <a href="https://en.wikipedia.org/wiki/GPT-3" rel="nofollow noreferrer">GPT-3</a>, the language learning model spawning off i...
<p>The 175 billion parameters in the GPT-3 language model are values that are used by the model to make predictions about the next word or words in a sentence or piece of text. These parameters are essentially the weights that are applied to the input data in order to make the model's predictions. In a neural network, ...
273
GPT model
Is there a way to connect a deep language model output to input?
https://cs.stackexchange.com/questions/115948/is-there-a-way-to-connect-a-deep-language-model-output-to-input
<p>In models like GPT-2, TXL and Grover, is there a good way to know which input weights (tokens) resulted in each token of the output? </p>
274
GPT model
Difference between Byte Pair Encoding (BPE), Sequitur, and Re-Pair
https://cs.stackexchange.com/questions/171396/difference-between-byte-pair-encoding-bpe-sequitur-and-re-pair
<p>I looked at the Wikipedia pages for <a href="https://en.wikipedia.org/wiki/Byte_pair_encoding" rel="nofollow noreferrer">Byte Pair Encoding (BPE)</a>, <a href="https://en.wikipedia.org/wiki/Sequitur_algorithm" rel="nofollow noreferrer">Sequitur</a>, and <a href="https://en.wikipedia.org/wiki/Re-Pair" rel="nofollow n...
275
GPT model
Generate product description from product specifications
https://cs.stackexchange.com/questions/167540/generate-product-description-from-product-specifications
<p>I am looking for a python NLP library that can generate a proper product description based on product features provided to it.</p> <p>Till now, i have tried <strong>transformers</strong> library and this is the code:</p> <pre><code>from transformers import pipeline def generate_description(specs): # Construct i...
<p>Shopping questions (requests for us to recommend a library or software package) are off-topic on Stack Exchange.</p> <p>One possible way to achieve your goals is to use a large language model, like GPT4, to generate a description. GPT2 is likely to be terrible at this. Try GPT4.</p>
276
LSTM
What are the inputs to an LSTM for Slot Filling Task
https://cs.stackexchange.com/questions/71032/what-are-the-inputs-to-an-lstm-for-slot-filling-task
<p>I am confused on the inputs of a Long-Short Term Memory (LSTM) for the slot filling task in Spoken Language Understanding. </p> <p>Before I worked on this, I implemented a language model with a Recurrent Neural Network (RNN) and then with a LSTM. The input to the RNN and LSTM language models was a one hot vector, w...
277
LSTM
What is Temperature in LSTM (and neural networks generally)?
https://cs.stackexchange.com/questions/79241/what-is-temperature-in-lstm-and-neural-networks-generally
<p>One of the hyperparameters for LSTM networks is temperature. What is it?</p>
<p><strong>Temperature</strong> is a hyperparameter of LSTMs (and neural networks generally) used to control the randomness of predictions by scaling the logits before applying softmax. For example, in TensorFlow’s Magenta <a href="https://github.com/tensorflow/magenta/blob/5cbbfb94ff4f506f1dd1f711e4704a1b3279a385/mage...
278
LSTM
Time Series Prediction with an LSTM
https://cs.stackexchange.com/questions/60138/time-series-prediction-with-an-lstm
<p>I have a time series that I want to predict with an LSTM. I am able to get very good results using 50 datapoints predicting 51, but I struggle to get any accuracy using something like 200 datapoints to predict 220. After an epoch, my network outputs 0 for all inputs. Is there a technique for predicting multiple t...
<p>Yes, you could try applying the LSTM iteratively 20 times. In other words: use the first 200 datapoints to predict the 201th; then use datapoints 2..201 to predict the 202th; and so on, until you predict the 220th. You'll have to evaluate how well this works on a test set; it might work, or it might not.</p> <p>T...
279
LSTM
Hessian-Free instead of LSTM for Recurrent Net Machine Translation
https://cs.stackexchange.com/questions/38144/hessian-free-instead-of-lstm-for-recurrent-net-machine-translation
<p>Last year, Ilya Sutskever and collaborators came out with a <a href="http://papers.nips.cc/paper/5346-sequence-to-sequence-learning-with-neural-networks.pdf" rel="nofollow">paper</a> about a recurrent LSTM net that learns sequence to sequence mappings for machine translation. It's somewhat surprising that the author...
280
LSTM
What Happens if I swap the forget gate and update gate in LSTM model?
https://cs.stackexchange.com/questions/129526/what-happens-if-i-swap-the-forget-gate-and-update-gate-in-lstm-model
<p>Consider the following eqautions used in LSTM ( taken from Andrew ng's course on Sequential model)</p> <p>In an LSTM model, LSTM Cell has three inputs at any time step t</p> <ul> <li>Input(<span class="math-container">$X_t , a^{(t-1)}, C^{(t-1)})$</span>, <br><br> Here <span class="math-container">$X_t$</span> is th...
<p>The two formulas are mathematically equivalent; the only change is that you have swapped the names of the variables (changes them to names that are less intuitive, compared to what effect they have), but that doesn't affect the behavior of the system.</p>
281
LSTM
How does the forget layer of an LSTM work?
https://cs.stackexchange.com/questions/118865/how-does-the-forget-layer-of-an-lstm-work
<p>Can someone explain the mathematical intuition behind the forget layer of an LSTM?</p> <p>So as far as I understand it, the cell state is essentially long term memory embedding (correct me if I'm wrong), but I'm also assuming it's a matrix. Then the forget vector is calculated by concatenating the previous hidden s...
<p>Think of it like this: The cell state <span class="math-container">$h_t$</span> is a vector. The forget vector <span class="math-container">$f_t$</span> is used to choose which parts of the cell state to "forget". We update the hidden state with something like <span class="math-container">$c_t = f_t \circ c_{t-1}$...
282
LSTM
Intuitive description for training of LSTM (with forget gate/peephole)?
https://cs.stackexchange.com/questions/12871/intuitive-description-for-training-of-lstm-with-forget-gate-peephole
<p>I am a CS undergraduate (but I don't know much about AI though, did not take any courses on it, and definitely nothing about NN until recently) who is about to do a school project in AI, so I pick a topics regarding grammar induction (of context-free language and perhaps some subset of context-sensitive language) us...
<p>LSTM is designed to process a stream of data chunks (each chunk being the set of inputs for the network at this point in time) that arrive over time and observe features occurring in the data and yield output accordingly. The time lag (delay) between the occurrence of features to recognize may vary and may be prolo...
283
LSTM
LSTM : What should I do if I am always getting an output too close to one value?
https://cs.stackexchange.com/questions/134959/lstm-what-should-i-do-if-i-am-always-getting-an-output-too-close-to-one-value
<p>I am training a model for ham and spam classification using LSTM. I am indicating the spams as 0, and the hams as 1. However, the dataset has much more hams than spams, so I tend to get an output very close to 1. That means the output is almost always above 0.5. So I have two questions about this :</p> <p>Q1. Should...
<p>The usual starting point is that if the score is above 0.5, classify it as ham, otherwise as spam. If most emails are ham, then it makes sense that most emails give you a score above 0.5, so you have not said anything that indicates there is a problem.</p> <p>This approach assumes that the proportion of ham vs spam...
284
LSTM
Is there something as good as a GRU or LSTM but simpler?
https://cs.stackexchange.com/questions/83939/is-there-something-as-good-as-a-gru-or-lstm-but-simpler
<p>I was just reading this paper: <a href="https://arxiv.org/pdf/1701.05923.pdf" rel="nofollow noreferrer">Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks Rahul Dey and Fathi M. Salem</a></p> <p>It seems to me that perhaps the architecture of LSTMs and GRUs are overly complicated. And that the same problem...
285
LSTM
How long can the short memory last in the RNN?
https://cs.stackexchange.com/questions/142325/how-long-can-the-short-memory-last-in-the-rnn
<p>For a recurrent neural network, the LSTM was a model of how the network worked. However, consider the case where an input was a long paragraph or even an article. <span class="math-container">$$c_1c_2...c_n$$</span> where <span class="math-container">$c_i$</span> were some characters. The LSTM would work as expected...
286
LSTM
Why does a RNN network output different based on the training sequence
https://cs.stackexchange.com/questions/113158/why-does-a-rnn-network-output-different-based-on-the-training-sequence
<p>I've set up an RNN LSTM network in Java using DL4J as the library.</p> <p>I currently have 500 examples of positive text, and 500 examples of negative text.</p> <p>When I fitness the training data by first training all the negatives and then all the positives, my predictions only favor high positive responses even...
<p>RNNs are pattern recognition tools. It is't entirely clear to me what it is exactly that you are trying to do, but if you simply intend for it to classify positive and negative messages a regular Neural Network might be better suited.</p> <p>What your RNN does (if implemented correctly) is learn classifications in ...
287
LSTM
How can I modify this detail in the article &quot;&quot;Extending Multi-Sense Word Embedding to Phrases and Sentences for Unsupervised Semantic Applications&quot;?&quot;
https://cs.stackexchange.com/questions/144325/how-can-i-modify-this-detail-in-the-article-extending-multi-sense-word-embeddi
<p>This question is about de paper <a href="https://arxiv.org/pdf/2103.15330.pdf" rel="nofollow noreferrer">Extending Multi-Sense Word Embedding to Phrases and Sentences for Unsupervised Semantic Applications</a>.</p> <p>I am interested in the transformer part of the paper and the main structures of the algorithm is re...
<p>Thanks for being interested in our work.</p> <p>The role of the decoder is to model the dependency between the codebook embeddings. For example, in this case, outputting an embedding close to sings might be correlated to outputting an embedding close to microphone.</p> <p>There are several reasons that we choose to ...
288
LSTM
which neural network is good for predecting the value of strings
https://cs.stackexchange.com/questions/131318/which-neural-network-is-good-for-predecting-the-value-of-strings
<p>I have a dataset that contains some strings. A numeric value is assigned to each string. I want to develop a machine learning (deep learning) model to get a string and predict its value. What neural network do you suggest for this model? Should I use RNN (LSTM)?</p>
<p>Assuming the strings are variable-length, a recurrent neural network would be a reasonable choice: either a LSTM or a convolutional network.</p>
289
LSTM
Signal translation with Seq2Seq model
https://cs.stackexchange.com/questions/130020/signal-translation-with-seq2seq-model
<p>I'm currently doing some research on signal processing and I got a dataset which includes the signal in itself and its &quot;translation&quot;.</p> <p><a href="https://i.sstatic.net/Bnp2P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Bnp2P.png" alt="A signal and its translation" /></a></p> <p>So I w...
<p>I am skeptical that machine learning is the right tool for this problem. I would look for a more direct solution, perhaps using peak detection or changepoint detection, or some other form of classical method for time-series analysis.</p> <p>If you do use machine learning, cross-entropy loss is not the right loss fo...
290
LSTM
Can an artificial neural network convert from cartesian coordinates to polar coordinates?
https://cs.stackexchange.com/questions/51090/can-an-artificial-neural-network-convert-from-cartesian-coordinates-to-polar-coo
<p>Given cartesian coordinates $x$ and $y$ as input, can a neural network output $r$ and $\theta$, the equivalent polar coordinates?</p> <p>This would seem to require an approximation of the pythagorean theorem (which requires approximations of $x^2$ and $\sqrt{x}$) and $\sin$, $\cos$, or $\tan$ approximations. Is thi...
<p>i dont know if this answers your question (or at least part of it)</p> <p>According to the <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem" rel="nofollow noreferrer">Universal approximation theorem for ANNs</a>, it is possible (at least within a region of interest).</p> <p>The question about...
291
LSTM
RNN input shape for sequence generation on Tensorflow
https://cs.stackexchange.com/questions/68612/rnn-input-shape-for-sequence-generation-on-tensorflow
<p>I would like to train a RNN with LSTM cells in Tensorflow to predict the next word of a sequence. Words are N-length vectors of 0s and 1s. By looking at different tutorials, I saw that the input tensor has a shape like this</p> <pre><code>seq_input = tf.placeholder(tf.float32, [n_steps, batch_size, seq_width]) </co...
292
LSTM
Do all the cells in a recurrent neural network share learned parameters?
https://cs.stackexchange.com/questions/88891/do-all-the-cells-in-a-recurrent-neural-network-share-learned-parameters
<p>Most descriptions of modern RNNs present a "folded" characterisation, that is to say, a single cell with a loop back to itself transmitting the hidden state from one step to the next. However, in implementations the RNN is computed "unfolded", so a new cell is created for every step of the sequence up to some maximu...
<p>Indeed, the copies of a cell in an unfolded version share their learning parameters.</p> <p>Why is it done this way? If the sequence processed by the LSTM is always the same lenght, we could conceivably get a better result with different parameters, but there are two key caveats:</p> <ol> <li>Shared parameters are...
293
LSTM
How would you go about creating a algorithm that should generate a shakespearean sonnet on any given theme
https://cs.stackexchange.com/questions/92523/how-would-you-go-about-creating-a-algorithm-that-should-generate-a-shakespearean
<p>I need to create an algorithm that is going to create a shakespearean sonnet for a specific theme. This theme should be generated out of twitter tweets that have some hashtag.</p> <p>My current idea goes like </p> <p><strong>While training:</strong></p> <ul> <li>break up sonnets and other kinds of poems into word...
294
LSTM
What&#39;s the input to the decoder in a sequence to sequence autoencoder?
https://cs.stackexchange.com/questions/69432/whats-the-input-to-the-decoder-in-a-sequence-to-sequence-autoencoder
<p>What's the input to the decoder part of a sequence to sequence autoencoder? I've seen certain examples of such an autoencoder (using LSTM's more often than not) but am still unclear.</p> <ul> <li><p>For example, here in this often-cited <a href="https://pdfs.semanticscholar.org/6506/d13a84f90f8620fd028cfe5b8b9d0444...
<p>I was wondering the same and just stumbled across a nice <a href="http://cs.stanford.edu/~quocle/tutorial2.pdf" rel="noreferrer">tutorial</a> by Quoc V. Le. The following explanation deals with the conditional case since this seems to be the common case. My explanation is based on and the image is taken from chapter...
295
LSTM
Clarification about RNN encoder-decoder equation
https://cs.stackexchange.com/questions/148739/clarification-about-rnn-encoder-decoder-equation
<p>In the paper by <a href="https://arxiv.org/pdf/1406.1078.pdf" rel="nofollow noreferrer">Cho et.al.</a>, section 2.3 details the equations for the modified LSTM cell in RNN used in the paper's implementation. The equation in question is :</p> <p><a href="https://i.sstatic.net/nRRBI.png" rel="nofollow noreferrer"><img...
<p><span class="math-container">$\mathbf{r}$</span> is a vector; <span class="math-container">$r'_j$</span> is a scalar; so this is multiplying a scalar (<span class="math-container">$r'_j$</span>) by a vector (the part in <span class="math-container">$[...]$</span>). There is only one way to multiply a scalar by a ve...
296
LSTM
Is deepfake detection viable?
https://cs.stackexchange.com/questions/131326/is-deepfake-detection-viable
<p>I'm thinking of doing a project on deepfake detection, but I'm not entirely sure if it is viable. Based on my understanding, how it works is that deepfake generation programs have a generative and discriminative network, and eventually after training, the systems reaches an equilibrium where the discriminative netwo...
297
LSTM
Can we supervise on the hidden states of RNN?
https://cs.stackexchange.com/questions/141532/can-we-supervise-on-the-hidden-states-of-rnn
<p>I'm trying to generate some history-dependent model with machine learning, whose underline physical model has a clear definition of its &quot;internal state variable&quot; (a state derived from historical inputs) and how this variable interacts with the inputs to get the outputs. Mathematically this reads: <span cla...
<p>There are several examples of performing supervision on hidden states for history dependent models.</p> <p><strong>Latent variables</strong></p> <p>Loss functions are commonly applied to internal states such as latent variables in <em>variational autoencoders</em> (VAEs).</p> <p><strong>Hidden states</strong></p> <p...
298
LSTM
How can one measure the time dependency of an RNN?
https://cs.stackexchange.com/questions/129437/how-can-one-measure-the-time-dependency-of-an-rnn
<p>Most of the discussion about RNN and LSTM alludes to the varying ability of different RNNs to capture &quot;long term dependency&quot;. However, most demonstrations use generated text to show the absence of long term dependency for vanilla RNN.</p> <p>Is there any way to explicitly measure the time dependency of a g...
<p>I am not aware of any standard or widely-used metric for this. I think what metric would be appropriate would depend on what you want to use it for.</p> <p>The issues with RNN is &quot;forgetting&quot;. If you feed a long sequence of inputs <span class="math-container">$x=(x_1,\dots,x_n)$</span> into a RNN, where <...
299