instruction
stringlengths
0
29.8k
⌀
How to prove "The power set of a countable set must be uncountable"?
|turing-machines|recursion|uncountability|
This is Cantor's diagonalization lemma: Let $S$ be a countable set and suppose that there is a bijective function $\phi: S \to 2^S$. Let $U = \{x \in S \mid x \notin \phi(x)\}$. (Notice that our only assumption is the existence of the bijective function.) Since $U \in 2^S$, and $\phi$ is bijective, there must b...
Is this variant of the subset sum problem easy/known? <blockquote> Given an integer $m$, and a set of positive integers $A = \{x_1, x_2, ..., x_n\}$ such that every $x_i$ has at most $k=2$ bits set to $1$ ($x_i = 2^{b_{i_1}}+2^{b_{i_2}},\;\; b_{i_1},b_{i_2}\geq 0$); is there a subset $A' \subseteq A$ such that the ...
Complexity of a subset sum variant
|decision-problem|
What you want to solve is a [string matching](https://en.wikipedia.org/wiki/String_matching) problem. Wikipedia (and any textbook on the matter) contains a rich list of algorithms with their respective runtimes. Be aware that they give *worst-case* runtimes. Different algorithms behave differently on natural text; s...
|complexity-theory|reference-request|decision-problem|
|algorithms|computer-networks|routing|
|regular-languages|automata|finite-automata|
A true/false question: If a DFA $M$ contains a self-loop on some state $q$, then $M$ must accept an infinite language. The answer is "false". I've read [this question][1], but I'm still wondering why $M$ does not necessarily accept an infinite language. Isn't the language $b^*$ infinite? Don't all self-loops look li...
Do self-loops in DFA cause infinite languages?
|algorithms|graphs|
null
I am learning about context free languages. I understand how $\{a^n b^n c^n | n \ge 0\}$ can be shown to be not context free using the pumping lemma for CFL's. Intuitively however it seems that a pushdown automata to recognize $\{a^n b^n c^n | n \ge 0\}$ can be constructed. This PDA would initially push two $a$'...
Push down automata for $\{a^n b^n c^n | n \ge 0\}$
|context-free|pushdown-automata|pumping-lemma|
Your PDA would also accept strings of the form $a^nb^ic^j$ where $i+j=2n$ and $i,j>0$. For example the string "aaabbbbbc" is accepted. There is no way to tell that there are exactly $n$ $a$'s still remaining on the stack once you've finished reading the $b$'s.
$L_1=\{a^ku \mid u \in \{a,b\}^* $ and $u$ contains at least $k$ a's, for $k\geq 1\}$. If it is regular, I haven't found its regular expression or any closure property to prove it. If not, it seems pumping theorem holds for it... Also, what about the language where the above "at least" is changed to "at most"?...
Is this language regular or not?
|regular-languages|regular-expressions|pumping-lemma|
|semantics|formal-methods|
Take $k=1$. No need to go further, it just makes the constraint harder to meet and it can be recognized by $u$. You need $u$ to have at least 1 $a$ and only $a$'s or $b$'s. Therefore, $L_1$ is recognized by $a(a|b)^*a(a|b)^*$ and is regular.
|formal-languages|regular-languages|regular-expressions|pumping-lemma|
$L_1=\{a^ku \mid u \in \{a,b\}^* $ and $u$ contains at least $k$ a's, for $k\geq 1\}$. If it is regular, I haven't found its regular expression or any closure property to prove it. If not, it seems pumping theorem holds for it... Also, what about the language where the above "at least" is changed to "at most"?
This is a snippet from some pseudocode for a sorting algorithm. In it, the symbol ← is used to denote assignment, for example for the variable `done`. However, in the `while` loop the statement `done:= false` is written. I would assume it is also an assignment statement but I suspect it means somethings else, or perhap...
Difference between := and ← in pseudocode
|algorithms|algorithm-analysis|
The use of `:=` in this context appears to be a slip-up from whomever it is who wrote that pseudocode. The initial impression given is that they have different meanings (I thought at first that `:=` was perhaps "redefine", and that `←` was "declare and define"). However, with the use of `j ← j + 1` on the line followin...
The usual approach is operational transformation. The [wikipedia page](http://en.wikipedia.org/wiki/Operational_transformation) seems to be pretty good. Here are some other references: * [Understanding and Applying Operational Transformation](http://www.codecommit.com/blog/java/understanding-and-applying-operational...
From what I've read, Big O is the absolute worst ever amount of complexity an algorithm will be given an input. On the side, Big Omega is the best possible efficiency, i.e. lowest complexity. Can it be said then that every algorithm has a complexity of O(∞) since infinite complexity is the worst ever possible? By t...
Is every algorithm's complexity Ω(1) and O(∞)?
|complexity-theory|algorithm-analysis|
Let $\varphi(x)=2x$ if $x$ is a perfect square, $\varphi(x) = 2x+1$ otherwise. Show $\varphi$ is primitive recursive. In proving $\varphi$ to be a p.r. function I think it could come in handy the following theorem: Let $\mathcal C$ be a PRC class. Let the functions $g$, $h$ and the predicate $P$ belong to $\mathc...
Prove $\varphi(x)$ to be primitive recursive
|computability|recursion|check-my-proof|
To be clear, Big O and Big Omega are classes of functions. So if I have for example $\Omega(1)$, that's a set of a whole bunch of functions. An algorithm's complexity is a function giving how many steps the algorithm takes on each input. This function may be in a class like $\Omega(1)$, or not. $\Omega(1)$ is the...
To be clear, Big O and Big Omega are classes of functions. So if I have for example $\Omega(1)$, that's a set of a whole bunch of functions. An algorithm's complexity is a function giving how many steps the algorithm takes on each input. This function may be in a class like $\Omega(1)$, or not. $\Omega(1)$ is the...
From what I've read, Big O is the absolute worst ever amount of complexity an algorithm will be given an input. On the side, Big Omega is the best possible efficiency, i.e. lowest complexity. Can it be said then that every algorithm has a complexity of $O(\infty)$ since infinite complexity is the worst ever possibl...
Is every algorithm's complexity $\Omega(1)$ and $O(\infty)$?
null
null
Finding Big-O is pretty straightforward for an algorithm where $f(n)$ is $$f(n) = 3n^4 + 6n^3 + 10n^2 + 5n + 4$$ The lower powers of $n$ simply fall off because in the long run $3n^4$ outpaces all of them. And with $g(n) = 3n^4$ we say $f(n)$ is $O(n^4)$. But what would Big-O be if instead of 3 we were given a...
Big-O complexity when c is a tiny fraction
|complexity-theory|algorithm-analysis|
Medium answer - yes. As you said for the previous case, in the long run $n^4$ outpaces all of them. This is still true despite the constant in front. Check it out: [plot][1]. Also, remember that $n^3$ and $n^4$ are both $O(n^4)$, and in fact are both $O(n^{10})$ because big-O is an upper bound. So you might ask "...
Is this variant of the subset sum problem easy/known? <blockquote> Given an integer $m$, and a set of positive integers $A = \{x_1, x_2, ..., x_n\}$ such that every $x_i$ has at most $k=2$ bits set to $1$ ($x_i = 2^{b_{i_1}}+2^{b_{i_2}},\;\; b_{i_1},b_{i_2}\geq 0$); is there a subset $A' \subseteq A$ such that the ...
I think is still $\sf{NP}$-complete, even for $k=2$. Given an instance of subset sum, we can transform it in to this variant by splitting up the numbers and adding some extra bits. First, the sum of all numbers in the problem will be less than $2^m$ for some value of $m$. Now, let's take a number $n$ from the or...
If we have an algebraic specification in the form: {S,F,w} where S is the sorts, F are the functions and w are the set of equations. an example is the specification for natural numbers: - Spec: Int - Sort: int - ops: 0:-> int suc,pred: int->int - enqs: suc(pred(x)) = x; pred(suc(x)) = x My questi...
Homomorphism and Isomorphism in Equational Calculus
|semantics|process-algebras|relational-algebra|
Is this variant of the subset sum problem easy/known? <blockquote> Given an integer $m$, and a set of positive integers $A = \{x_1, x_2, ..., x_n\}$ such that every $x_i$ has at most $k=2$ bits set to $1$ ($x_i = 2^{b_{i_1}}+2^{b_{i_2}},\;\; b_{i_1},b_{i_2}\geq 0$); is there a subset $A' \subseteq A$ such that the ...
null
Is this variant of the subset sum problem easy/known? <blockquote> Given an integer $m$, and a set of positive integers $A = \{x_1, x_2, ..., x_n\}$ such that every $x_i$ has at most $k=2$ bits set to $1$ ($x_i = 2^{b_{i_1}}+2^{b_{i_2}},\;\; b_{i_1},b_{i_2}\geq 0$); is there a subset $A' \subseteq A$ such that the ...
Can you come up with two different algebras, say, one where the domain is $\mathbb{N}$ and one where the domain is $\{0,1\}$ and in the former, `suc` and `pred` work as you would assume, and in the latter, they are modulo 2 operations? Then, try to come up with a homomorphism from one to another. Then, try to make ...
Can you come up with two different algebras, say, one where the domain is $\mathbb{N}$ and one where the domain is $\{0,1\}$ and in the former, `suc` and `pred` work as you would assume, and in the latter, they are modulo 2 operations? Then, try to come up with a homomorphism from one to another. Then, try to make ...
null
There's a problem with the formal details of your definition of collision-resistance: if we take it seriously, then *no* function (whose output is shorter than its input) can ever be collision-resistant. By the pigeonhole property, it is guaranteed that *there exists* some pair of messages $x,x' \in \{0,1\}^{2m}$ su...
To see if $x$ is a perfect square is easy (for example, by adding 1 + 3 + 5 ... you get the succesive squares); once that is settled your problem is solved. Think of such problems primarily as _programming_ asignments (in a rather cruel programming language).
The Akra-Bazzi theorem is a strict generalization of the master theorem. As a bonus its proof is a blizzard of integrals that will make your head spin ;-) In any case, Sedgewick in his ["Introduction to the analysis of algorithms"][1] argues convincingly that one should strive to prove $T(n) \sim g(n)$ type asymptot...
Very simple: Suppose numbers are written in decimal (other bases are handled by a trivial modification). Build a DFA, with $a$ states 0, 1, ..., $a - 1$. Start state is 0, and from state $q$ on input the digit $d$ go to state $(10 q + d) \bmod a$. Accepting state is $b \bmod a$ (might need a tweak if $b > a$).
Consider the following problem: Let $k$ be a constant. We are given a $k$-ary array $A_{d_1\times\ldots\times d_k}$ of $0$ and $1$'s. Let $N = \prod_{i=1}^k d_i$. We want to create a data structure by preprocessing $A$ to perform the following type of query operations: 1. Given the coordinates of a $k$-ary b...
|reference-request|data-structures|space-complexity|
Remember, when we write $f(x) = O(g(x))$ we are saying that there are two positive constants, $c$ and $x_0$ such that $f(x) \le cg(x)$ for all $x \ge x_0$. Asymptotic analysis is concerned with how functions behave ***in the limit***. Let's rewrite your function: $$ f(n)=an^4+6n^3+10n^2+5n+4 $$ This functi...
Bit complexity of O(1) time range query in a $k$-ary array
null
To be clear, Big O and Big Omega are classes of functions. So if I have for example $\Omega(1)$, that's a set of a whole bunch of functions. An algorithm's complexity is a function giving how many steps the algorithm takes on each input. This function may be in a class like $\Omega(1)$, or not. $\Omega(1)$ is the...
|complexity-theory|algorithm-analysis|asymptotics|
null
This question follows on previous questions [(1)](http://cs.stackexchange.com/questions/6562/generalizing-the-comparison-sorting-lower-bound-proof), [(2)](http://cs.stackexchange.com/questions/7349/proofs-based-on-narrowing-down-sets-of-possibilities), where we define an initial space of possibilities and reason about ...
Search spaces and computation time
|lower-bounds|
Remember, when we write $f(x) = O(g(x))$ we are saying that there are two positive constants, $c$ and $x_0$ such that $|f(x)| \le c|g(x)|$ for all $x \ge x_0$. Asymptotic analysis is concerned with how functions behave ***in the limit***. Let's rewrite your function: $$ f(n)=an^4+6n^3+10n^2+5n+4 $$ This fu...
No, in general you can't assume that an exponential search space requires exponential time to search. Linear programming generally has an exponential search space but can be done in (weakly) polynomial time.
null
No, it completely depends on how much structure your space has. Suppose you want to search for an element in an exponentially large sorted list. Using binary search you only need to look at a polynomial number of elements. For some special kinds of spaces you can even search infinitely many elements using only finit...
|semantics|
I am following the idea of @vonbrand: **Hint 1:** Solve first for $b=0$. You might use the [Myhill-Nerode](http://en.wikipedia.org/wiki/Myhill%E2%80%93Nerode_theorem) Theorem. >! We define the following relation $\bar x\approx \bar y :\iff x\equiv y \mod 10$. This is obviously an equivalence relation. Furthermor...
Can you come up with two different algebras, say, one where the domain is $\mathbb{N}$ and one where the domain is $\{0,1\}$ and in the former, `suc` and `pred` work as you would assume, and in the latter, they are modulo 2 operations? Then, try to come up with a homomorphism from one to another. Then, try to make ...
No, it completely depends on how much structure your space has. Suppose you want to search for an element in an exponentially large sorted list. Using binary search you only need to look at a polynomial number of elements. For some special kinds of spaces you can even search infinitely many elements using only finit...
RE means a TM generates the strings. Run that one, and each time there is some output, write its prefixes to the real output.
An [initial algebra][1] is an initial object in the category of [$F$-algebras][2] for a given endofunctor $F : \mathcal{C} \rightarrow \mathcal{C}$. This construction is widely used to gives semantics to data-structures in (functional) programming languages. Intuitively, the functor $F$ captures the "shape" of the ...
The short answer is No. Here is the counter-example: Problem P: Find the shortest path from source $s$ to target $t$ in a undirected graph $G = (V, E)$. Input: Initially, the input is |V|, and the complete graph of |V| vertices is assumed. Subsequently, the input consists of edges that need to be *removed* from t...
As a preperation of an exam about algorithms and complexity, I am currently solving old exercises. One concept I have already been struggling with when I encountered it for the first time is the concept of amortised analysis. What is amortised analysis and how to do it? In our lecture notes, it is stated that "amortise...
Questions about amortised analysis
|amortized-analysis|
Take $k=1$. No need to go further, it just makes the constraint harder to meet and it can be recognized by $u$. You need $u$ to have at least 1 $a$ and only $a$'s or $b$'s. Therefore, $L_1$ is recognized by $a(a|b)^*a(a|b)^*$ and is regular. For the side question (at most $k$ $a$'s, let's call that language $L_2$...
Let $a_i$ be the amortized costs of operation $i$, $c_i$ be the actual costs of operation $i$, and $D_i$ the data structure after operation $i$. The amortized costs of an operation are **defined** as $$a_i:=c_ i+ \Phi(D_i) -\Phi(D_{i-1}).$$ You usually assume the following 1. The potential is always positive, tha...
DCFLs have LR(0) grammars, and LR parsers have the property that they report the error on the first symbol that can't be legally there. So the strategy would be simply to run the LR parser and accept whatever doesn't give an error before ending the string. (Way overkill, there must be a "simpler" way to prove it, but ...
(Have no comment power) Another way is to build up the language using operations under which you know they are closed. This is an extension to exhibiting a regular expression, as you have many more operations available (reverse the string, complement, intersection, chop out a piece, just keep a part, homomorphisms and...
OK, "laymanized" a bit. Take DFAs $M_1 = (Q_1, \Sigma, \delta_1, q_1, F_1)$ and $M_2 = (Q_2, \Sigma, \delta_2, q_2, F_2)$. Consider the DFA $M = (Q_1 \times Q_2, \Sigma, \delta, (q_1, q_2), F_1 \times F_2)$, where $\delta$ is defined by: $$ \delta((q', q''), a) = (\delta_1(q', a), \delta_2(q'', a)) $$ The idea is t...
That is wrong. Consider $L_1 = \{a, b\}^*$, $L_2 = \{a^n b^n : n \ge 0\}$. $L_1$ is regular, $L_2$ isn't; but $L_1 \cup L_2 = L_1$.
|complexity-theory|proof-techniques|lower-bounds|
Another way is to build up the language using operations under which you know they are closed. This is an extension to exhibiting a regular expression, as you have many more operations available (reverse the string, complement, intersection, chop out a piece, just keep a part, homomorphisms and inverse homomorphisms, ....
Standard busy beaver function draws attention to final count of nonzero symbols on tape. We could instead look at largest amount of nonzero symbols appearing on tape at _any_ point of computation. This function's lower bound would be Sigma(n) and upper bound would be S(n) (max shifts function). Was there made any resea...
Faster growing busy beaver function
|turing-machines|
Suppose there is a machine using $n$ states which, at some point, has $X$ nonzero symbols on the tape. One can build a machine with $O(n)$ states which simulates a run of the original machine with a tape alphabet of three symbols $\{0,1,2\}$, with the following small change: whenever the original machine changes $1$ to...
null
null