instruction
stringlengths
0
29.8k
⌀
null
No, the input does not count in the space complexity. The data has to be supplied anyway and if we counted it, no $o(n)$ complexity (in particular $O(1)$) would be possible.
I’ll suggest to do some work yourself. When you look up, or add, or remove a value from the hash table, what operations would be performed with different load factors, with which probability, what the cost of these operations is, and what the memory usage would be on average. That should give you some idea, whi...
A hash table is an implementation of a more general principle: A key/value table. In a key/value table you can insert values according to a key, you cannot add two values under the same key. You can lookup a value based on the key, or delete it based on the key. Very often the key can be anything that is "equatable"...
I can’t understand How can dfa have more than one sink state? Isn’t it the same state? Maybe there is some examples
How can dfa have more than one sink state? Isn’t it the same state?
|formal-languages|formal-grammars|
Consider the following automaton. [![enter image description here][1]][1] There are two sink states: $q_3$ and $q_4$. Of course, any automaton with multiple sink states is equivalent to an automaton with at most one sink state, and even to an automaton without any sink state if the automaton is not complete. ...
> Auxiliary Space: The extra space that is taken by an algorithm > temporarily to finish its work > > Space Complexity: Space complexity is the total space taken by the > algorithm with respect to the input size plus the auxiliary space that > the algorithm uses. i.e., space complexity of a program on the whol...
A set is an abstract data type that stores "elements" such as integers, strings, points, or whatever. The elements must be unique and are stored in an unspecified order. Those elements are called the "keys". A dictionary is like a set, but a value is associated to each key. A set or a dictionary can be implemente...
null
I have an array (of hundreds of numbers) and I need to sort them. In this case, I used Bubble Sort because of the better time complexity compared to other algorithms, Θ(n²). ``` procedure bubbleSort(arr)         for i=0 to n-i-1             for j=0 to n-i-2                 if arr[j]>arr[j+1]                   ...
Modified Bubble Sort's time complexity
|algorithms|time-complexity|sorting|arrays|
I have an array (of hundreds of numbers) and I need to sort them. In this case, I used Bubble Sort because of the better time complexity compared to other algorithms, $\Theta(n^2)$. ``` procedure bubbleSort(arr)         for i=0 to n-i-1             for j=0 to n-i-2                 if arr[j] > arr[j+1]            ...
My book([link][1]) says that if the computer tries to access a virtual memory page that is on the hard-disc it loads that page into physical memory. But how does the computer keep track of which physical memory it should use? Does it look through the page table to find free physical memory? [1]: https://www.amaz...
How does the computer keep track of which physical pages are used?
|memory-management|virtual-memory|
By definition, a parametrized reduction from a parametrized problem $A$ to $B$ needs to satisfy the following properties: 1. The reduction maps each instance $(x,k)$ of $A$ is mapped to some instance $(x',k')$ of $B$ such that $(x,k)$ is true if and only if $(x',k')$ is true. 2. The parameter $k'$ obtained after t...
I'm learning about (complexity-theoretic) pseudorandom number generators, and I have a pretty basic question about them that I couldn't find an answer to. Let's say we have a PRG for $P$ with seed length $O(\log^{10}(n))$. This would already be a breakthrough, as it would imply $BPP$ can be decided in deterministic ...
Why can't we just compose PRGs to get better PRGs?
|randomized-algorithms|pseudo-random-generators|
Given a set S of numbers, min and max. Find all sebsets of numbers from S with a subset sum larger or equal to min and smaller or equal to max. The following article says that there's an algorithm called ESS that solves this but I haven't been able to find the algorithm anywhere: "Cached Iterative Weakening for Optim...
I'm looking for an algorithm to find all subsets of a set S with subset sums between a given min and max
|algorithms|subset-sum|
null
## General description ## I have an optimization problem in which I need to schedule events and each of the events needs to be scheduled exactly once. The "cost" of scheduling one event depends on all of the events that have been scheduled before. So given a list of events $[e_1, e_2, ... e_n]$, the goal is to find ...
For arbitrary min and max the problem is weakly NP-complete. Let min=max=W and the answer is "at least one" if and only if the original instance is a yes instance. In any case, solve the problem using dynamic programming and count the number of solutions for each number in [min, max]. While actually outputting al...
Short answer: you can enumerate all possible seeds of length $O(\log^{10}(\log^{10}(n)))$ in $\text{poly}(\log n)$ time, so such a PRG cannot possible be secure against algorithms whose running time is polynomial in $\log n$, so such a PRG tells us nothing about BPP. Slightly longer answer: Each PRG comes with a sec...
Given n points on the plane, it is a standard interview problem to find the line with the maximum points, which can be done in O(n^2) with pivoting + hashmaps or other method. **Question: Are there more efficient algorithms that runs in o(n^2) e.g. O(nlogn), solving:** **(1) Find the line containing maximum numbe...
Optimal time complexity to solve "maximum points on line"
|algorithms|time-complexity|
I'm learning about (complexity-theoretic) pseudorandom number generators, and I have a pretty basic question about them that I couldn't find an answer to. Let's say we have a PRG for $P$ that can fool any algorithm running over $n$ bits in time $poly(n)$ with seed length $O(\log^{10}(n))$. This would already be a br...
The upper bound of n! is O(n^n). But I am not getting a way to compute the lower bound of n!. We can write n! = n*(n-1)*(n-2)*...*1. I can easily put all the terms as 1. The lower bound will be big omega of 1. But I am not convinced with this answer.
What is the lower bound of n factorial
|algorithms|complexity-theory|asymptotics|big-o-notation|
The upper bound of $n!$ is $O(n^n)$. But I am not getting a way to compute the lower bound of n!. We can write $n! = n\times(n-1)\times(n-2)\times\dots\times 1$. I can easily put all the terms as 1. The lower bound will be $\Omega(1)$. But I am not convinced with this answer.
It is well known that $log(n!) =\Theta(n\log(n))$. Therefore, $\exists c\in \mathbb{R}^+, 0<c\le 1$ such that: $$log(n!)\ge cn\log(n)$$ For large enough values of $n$. Because $e^x$ is monotonically increasing, we can order this a bit around, and get: $$n!\ge e^{cn\log(n)}=\left(e^{\log(n)}\right)^{cn}=n^{cn}...
## General description ## I have an optimization problem in which I need to schedule events and each of the events needs to be scheduled exactly once. The "cost" of scheduling one event depends on all of the events that have been scheduled before. So given a list of events $[e_1, e_2, ... e_n]$, the goal is to find ...
I need to divide numbers represented as digits in byte arrays with non standard amount of bytes. It maybe 5 bytes or 1 GB or more. Division should be done with numbers represented as byte arrays, without any conversions to numbers.
What is the fastest algorithm for division of crazy large integers?
|algorithms|mathematical-programming|
[Stirling's approximation](https://en.wikipedia.org/wiki/Stirling%27s_approximation) says that $$n! \sim \left(\frac{n}{e}\right)^n\sqrt{2\pi n}$$ That means that $n!\in \Theta\left(\left(\frac{n}{e}\right)^n\sqrt{n}\right)$ (this is a lower and upper bound).
null
null
null
null
null
I am trying to understand "On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo. One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuck at the sentence "Given recognizers for these languages, we c...
Generating parse trees when only a recognizer is given
|context-free|parsers|
I am trying to understand "On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo. One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuck at the sentence "Given recognizers for these languages, we c...
I am trying to understand "On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo. One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuck at the sentence "Given recognizers for these languages, we c...
Let's say we have the following context free grammar: $S \rightarrow a \\ S \rightarrow SS$ And we do the following two "derivations" for the same string: aaa: $S \rightarrow SS \rightarrow SSS \rightarrow aaa$ aaa: $S \rightarrow SS \rightarrow SSS \rightarrow aSS \rightarrow aaS \rightarrow aaa$ The d...
In Context free languages, is it okay to substitute multiple same variables at the same time?
|context-free|formal-grammars|
I am trying to learn how to prove the runtime of a recurrence relation, particularly through induction. I was looking at [this](https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture3.pdf) lecture PDF, and on the first page, the author writes this: > **Recurrence:** $T(1)=1$ and $T(n)=2 T(\lfloor n / 2\r...
Dropping terms in proving the runtime for a recurrence?
|runtime-analysis|recurrence-relation|induction|
It is possible, though it is often denoted with a $^*$ to indicate that there is a sequence of replacement instead of just one replacement: $$S\Rightarrow SS \Rightarrow SSS \Rightarrow^* aaa$$ Note that I am using a $\Rightarrow$ symbol instead of a $\to$ one to distinguish derivations of strings from production...
I am trying to learn how to prove the runtime of a recurrence relation, particularly through induction. I was looking at [this](https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture3.pdf) lecture PDF, and on the first page, the author writes this: > **Recurrence:** $T(1)=1$ and $T(n)=2 T(\lfloor n / 2\r...
1. In the last step, there is an inequality. Since it is assumed that $c\geqslant 1$, then $-cn + n = (1 - c) n \leqslant 0$, so the inequality is correct, it is not a matter of irrelevance or not. 2. For $\Theta$, it would be better to prove two different inequalities by induction, with different coefficients (howe...
I am trying to understand ["On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo](https://link.springer.com/chapter/10.1007/3-540-09510-1_39). One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuc...
I am trying to understand ["On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo](https://link.springer.com/chapter/10.1007/3-540-09510-1_39). One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuc...
I am a researcher starting to work on the field of parsing and recognition of languages. As part of my background research, I am reading up on CYK. I understand that it requires the grammar to be in CNF. This however, is restrictive, as it forces the grammar to be restructured to remove $\epsilon$ rules from arbitra...
I am trying to understand ["On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo](https://link.springer.com/chapter/10.1007/3-540-09510-1_39). One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuc...
A recognizer is any algorithm that, given a context-free grammar $G$ and a word $x \in \Sigma^*$, tests whether $x \in L(G)$. There are standard algorithms to do that, e.g., [Earley parsers](https://en.wikipedia.org/wiki/Earley_parser) or [CYK parser](https://en.wikipedia.org/wiki/CYK_algorithm).
For 1. (though Nathaniel answered for the case in question) generally, in $f(n)+g(n)$ where $g(n)=o(f(n))$, you can drop the term $g(x)$ because it becomes negligible. $$f(n)+g(n)=f(n)\left(1+\frac{g(n)}{f(n)}\right)=f(n)(1+\epsilon(n))$$ where the function $\epsilon$ tends to zero and the factor on the right can be...
There is a well-known Curry-Howard-Lambek correspondence between certain type systems, proof calculi and categories. Some variants of Barendregt's pure type systems have the property of strong normalization, i.e. any term can be reduced to a normal form after a finite number of reduction steps, the other of them don...
On the logical and categorical interpretation of lambda calculi and type systems
|lambda-calculus|type-theory|category-theory|curry-howard|
I am trying to understand ["On the complexity of general context-free language parsing and recognition" by Walter L. Ruzzo](https://link.springer.com/chapter/10.1007/3-540-09510-1_39). One of the results from the paper is about generating a parse tree when only a (blackbox) recognizer is given. Unfortunately, I am stuc...
There is no "the" upper/lower bound. There are as many upper/lower bounds as you want. For instance, $n!=\Omega(1), n!=\Omega(n), n!=\Omega(n^{27})$ are all true. What you are probably after is a tight bound. As said by Nathaniel, $\Omega(n^{n+1/2}e^{-n})$ is tight, because the ratio tends to a constant. But $\Omega...
There is no "the" upper/lower bound. There are as many upper/lower bounds as you want. For instance, $n!=\Omega(1), n!=\Omega(n), n!=\Omega(n^{27})$ are all true. What you are probably after is a tight bound. As said by Nathaniel, $\Omega(n^{n+1/2}e^{-n})$ is tight, because the ratio tends to a constant. But $\Omega...
For 1. (though Nathaniel answered for the case in question) generally, in $f(n)+g(n)$ where $g(n)=o(f(n))$, you can drop the term $g(x)$ because it becomes negligible. $$f(n)+g(n)=f(n)\left(1+\frac{g(n)}{f(n)}\right)=f(n)(1+\epsilon(n))$$ where the function $\epsilon$ tends to zero and the factor on the right can be...
There is no "the" upper/lower bound. There are as many upper/lower bounds as you want. For instance, $n!=\Omega(1), n!=\Omega(n), n!=\Omega(n^{27}), n!=\Omega(10^n)$ are all true. What you are probably after is a tight bound. As said by Nathaniel, $\Omega(n^{n+1/2}e^{-n})$ is tight, because the ratio tends to a cons...
There is no "the" upper/lower bound. There are as many upper/lower bounds as you want. For instance, $n!=\Omega(1), n!=\Omega(n), n!=\Omega(n^{27}), n!=\Omega(10^n)$ are all true. What you are probably after is a tight bound. As said by Nathaniel, $\Omega(n^{n+1/2}e^{-n})$ is tight, because the ratio tends to a cons...
You can look up Stirling's formula. If you want lower bounds that are much less good but mathematically very easy: 1. n! is the product of n numbers. All but $\sqrt n$ of them are greater than $\sqrt n$, so n! > $(\sqrt n)^{n - \sqrt n}$ which is $n^{n/2 - \sqrt n/2}$. 2. n! is the product of n numbers. Half are ...
I am reading "Introduction to the Theory of Computation" 3rd edition ~ by Michael Sipser, page 113-114 - topic: "Context free languages, push down automata" He states that the transition from one state to another would look as follows: "$a,b\rightarrow c$". But the way he states the usage confuses me > We write "...
Implementation details of "transitions" of Non deterministic finite automata
|pushdown-automata|
I am reading "Introduction to the Theory of Computation" 3rd edition ~ by Michael Sipser, page 113-114 - topic: "Context free languages, push down automata" He states that the transition from one state to another would look as follows: "$a,b\rightarrow c$". But the way he states the usage confuses me > We write "...
Kindly read again the description you have quoted from the book. It states there that $b$ is the stack element to be read and popped and $c$ would be the symbol to be pushed on top of the stack. So to answer your questions: 1. Nothing will be popped and pushed 2. Nothing will be popped but $c$ will be pushed 3. Po...
null
I am reading "Introduction to the Theory of Computation" 3rd edition ~ by Michael Sipser, page 113-114 - topic: "Context free languages, push down automata" He states that the transition from one state to another would look as follows: "$a,b\rightarrow c$". But the way he states the usage confuses me > We write "...
Implementation details of "transitions" of Non-deterministic push-down automata
null
null
I ended up with the following. First, it's necessary to define what is "false positive" (FP) and "false negative" (FN) of the algorithm. Let's say, a static method that is not eliminated is a "false negative" result ("negative" because the algorithm said "There is NO static method to eliminate"). Then, if a non-static ...
Suppose I would like to generate n clauses, in 3-CNF form, that would give a unique solution for m variables (m<n). Example: for m=6, I've got **{a,b,c,d,e,f} = 111010** How to generate these n 3-CNF clauses while minimizing this number of clauses (to avoid redundancies)? What would be the minimum number of clau...
null
Would you accept punched cards as carrying digital digits ? [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/UWxz9.png
Complexity analysis is usually done to compare algorithms that process the same input. In this case, it makes little sense to include the space of the input data, because it's the same for all algorithms being compared and doesn't affect the comparison. However, we might want to compare algorithms that process diffe...
Since the question has been clarified (by my comment) and its content is quite different than its initial formulation, I am posting a new answer. Assume $\mathcal{V} = \{x_1, x_2, …, x_n\}$ is a set of variables and $\mu \in \{0,1\}^{\mathcal{V}}$ is a truth assignment. For $i\in \{1, …, n\}$, consider $\mu_i$ to be...
It depends on the chosen convention. I often prefer the convention that considers that the input is not part of the space complexity, for different reasons: - the space complexity of a function answer the question "do I have enough memory to finish my computation?". In that aspect, I consider that when calling a fu...
Early termination can be a bad idea. Because if the condition for early termination is not met, you perform the whole processing plus testing the extra condition for nothing on every iteration. The same holds with search in a binary tree: most implementation test for equality of the key to perform early termination....
A recognizer is any algorithm that, given a context-free grammar $G$ and a word $x \in \Sigma^*$, tests whether $x \in L(G)$. There are standard algorithms to do that, e.g., [Earley parsers](https://en.wikipedia.org/wiki/Earley_parser) or [CYK parser](https://en.wikipedia.org/wiki/CYK_algorithm). The paper appears ...
null
(My answer is only about how non-termination relates to inconsistency.) The general idea of the Curry-Howard correspondence is that a term having a type, corresponds to a proof for a theorem. A term is an instruction on how to build a proof. A non-terminating term (i.e. a term that does not have a value) does not ac...
I'm a math background student and not familiar with algorithms and coding. I read [this post][1] on reddit where the author used label propagation, Fruchterman-Reingold algorithm, edge betweenness clustering to classify math subjects based on the data of published articles in 2018 on arxiv.org. I think being able to im...