instruction
stringlengths
0
29.8k
⌀
Time complexity for finding the number of triangles in a graph
|algorithms|time-complexity|runtime-analysis|loops|
Let us look at the `count_triangles_2`. The time it takes to run the function is spent mostly on executing line $5, 6, 7, 8, 9$ and $10$. So, the time-complexity is about $$n_5 * \text{time}(\text{line 5}) + n_{678910} * \text{time}(\text{line 6, 7, 8, 9, 10})$$ where $n_5$ is the number of times line 5 will b...
In our class we considered the problem written in the title. The below given time complexities where simply given, but not derived or explained. Therefore I tried myself to derive them, while I using math or simply intuition. I am able to explain, how one of the complexities comes about, but not the other one. I haven...
null
null
null
The question is LALR(1) parsing of the following: ``` S->AA A->aA A->b ``` The link to the question is on this page:https://www.javatpoint.com/lalr-1-parsing My question concerns I3, where despite a being read there is another production A->aA, a/b, where the a is *not* read. I wish to know the reasons for...
Why do we retain A->.aA,a/b in I3 stage of LALR parsing of S->AA, A->aA|B?
null
The birthday paradox is basically that assume there are 365 days in a year(ignore the effect of Febuary 29th), each person's birthday is uniformly random in these 365 days and independent with others. How many people do we need to have a more than 50% chance that two persons(or more) have the same birthday. my under...
Why using nC2*1/365 to calculate the birthday paradox is incorrect
|algorithms|hash|mathematical-analysis|
**Statement :** A half space is set of all points on one side of a linear separator, i.e., a set of the form $\{x \mid w^{T}x \ge t\}$. The VC-dimension of half space in $d$-dimensions is $d+1$. **Proof Idea.** There exists a set of size $d+1$ that can be shattered by half-spaces. Select the $d$ unit-coordinate vect...
Half-space in $d$-dimensions
|machine-learning|
To represent complexity of an algorithm, Computer Scientist is used to using big-O notation. How about complexity of boolean algebra? Boolean algebra is commonly used in digital circuit design with using logic gates, practically useful in FPGA programming. Speaking about logic gates circuit, This topic maybe loo...
I'm trying to find examples of languages that don't seem regulat, but are. A reference to where such examples may be found is also appreciated. So far I've found two. One is $L_1=\{a^ku\,\,|\,\,u\in \{a,b\}^∗$ and $u$ contains at least $k$ $a$'s, for $k\geq 1\}$, from [this post](https://cs.stackexchange.com/questio...
Regular languages that seem irregular
|regular-languages|reference-request|
null
**Statement :** A half space is set of all points on one side of a linear separator, i.e., a set of the form $\{x \mid w^{T}x \ge t\}$. The VC-dimension of half space in $d$-dimensions is $d+1$. **Proof Idea.** There exists a set of size $d+1$ that can be shattered by half-spaces. Select the $d$ unit-coordinate vect...
null
I'm trying to find examples of languages that don't seem regulat, but are. A reference to where such examples may be found is also appreciated. So far I've found two. One is $L_1=\{a^ku\,\,|\,\,u\in \{a,b\}^∗$ and $u$ contains at least $k$ $a$'s, for $k\geq 1\}$, from [this post](https://cs.stackexchange.com/questio...
I've seen arguments for $P \ne NP$ that rely on certain intuitions about how the real world actually is, generally making the point that it "makes sense" that there exist problems which have an *easily verifiable* solution that's *hard to find.* For example, on his blog, Scott Aaronson has a "Reasons to believe" ent...
Why do some "common sense" $P \ne NP$ arguments seem to disregard high-degree polynomials?
|complexity-theory|p-vs-np|philosophy|
My favorite example of this, which is often used as a difficult/tricky exercise, is the language: $$L=\{w\in \{0,1\}^*:w \text{ has an equal number of } 01\text{ and }10\}$$ This has the strong flavor of the non-regular "same number of $0$ and $1$", but the alternation of $0$ and $1$ makes it regular nonetheless.
I was reading this question over on the [quantum computation stackexchange](https://quantumcomputing.stackexchange.com/questions/5815/why-cant-a-quantum-computer-strongly-simulate-itself), and the top answer stated that you can't (strongly) simulate even a probabilistic turing machine, on itself. I was just curious if ...
Are there any probabilistic models of computation that can strongly simulate themselves?
|turing-machines|quantum-computing|simulation|probabilistic-turing-machines|
Let $L_1$ be a context-free language and $L_2$ be a regular language. Then $L_1 \cap L_2$ is context-free. Part of a proof given in the book "Formal languages and automata": Let $M_{1}=\left(Q, \Sigma, \Gamma, \delta_{1}, q_{0}, z, F_{1}\right)$ be an npda that accepts $L_1$, $M_{2}=\left(P, \Sigma, \delta_{2}, p_{...
proving a step in the proof of regular intersection
|formal-languages|regular-languages|automata|context-free|
null
In order to prove the statement by induction it has to be generalized somewhat. Observe that the current statement refers to final states of the automata involved. To be able to extend arbitrary computations we will have to consider arbitrary states as last state of the computations, so we consider also non-accepting c...
Here is another all time favourite language that looks very non-regular. All these questions refer to the same language. [Is the language of words with as many a's in the first as b's in the second part context-free?](https://cs.stackexchange.com/q/20159/4287) [Finite strings and relationships between words](ht...
Summarizing the comment thread: The state $I_3$ is reached by processing a SHIFT action on the item $A\to \bullet a A$, resulting in the item $A\to a\bullet A$. The original item, with the $\bullet$ at the beginning of the right-hand side, is not "retained". But the new item has the $\bullet$ immediately before the ...
I'm preparing for my finals in "Advance Algorithms". I'm trying to solve the following question: > It is given that the current tree is a string of $n$ vertices, and a search operation is repeated twice, with each search looking for the key that resides at that moment in the deepest leaf of the tree. What is the dep...
What is the depth of the tree after two operations if the tree uses the "Move to Root" heuristics?
|algorithms|data-structures|trees|
null
I'm studying lambda calculus with De Bruijn indexes, and have these functions. $$ zero := (\lambda\lambda.1)\\ succ := (\lambda\lambda\lambda.2 (3 2) 1) $$ Now I want an algorithm to reduce $succ\ zero$ $$ \beta\ succ\ zero \\ \beta\ (\lambda\lambda\lambda.2 (3 2) 1)\ (\lambda\lambda.1)\\ \beta\ \lambda\...
Lambda body reduction in Lambda calculus
|lambda-calculus|
I'm preparing for my finals in "Advance Algorithms". I'm trying to solve the following question: > It is given that the current tree is a string of $n$ vertices, and a search operation is repeated twice, with each search looking for the key that resides at that moment in the deepest leaf of the tree. What is the dep...
My definition of `succ` is wrong, the correct is $\lambda\lambda\lambda.2 (3 2 1)$ not $\lambda\lambda\lambda.2 (3 2) 1$
The [PL Zoo](http://plzoo.andrej.com/) has a programming language [lambda](http://plzoo.andrej.com/language/lambda.html) which uses de Bruijn indices (see the type [`term`](https://github.com/andrejbauer/plzoo/blob/master/src/lambda/syntax.ml#L3)) and explicit substitutions (described [here](http://math.andrej.com/2012...
Let's say I have some splay tree as following: [![enter image description here][1]][1] I want to recrate the exact same Splay tree using `insert(key)` method. Is there an algorithm that given some Splay tree traversal (or any other representation) will create the same Splay tree? In other words, assume you are...
Algorithm to recreate a Splay tree
|algorithms|data-structures|trees|splay-trees|
I believe that something like the [KITTI dataset][1] is what you are looking for. It is a large dataset made for Autonomous Vehicle Research. You can download after providing your email. You can also try looking at the raw [KITTI data][2]. Here is a [paper](https://www.mrt.kit.edu/z/publ/download/2013/GeigerAl20...
null
L is recognizable ----------------- A language $L$ is recognizable if and only if there exists a verifier for $L$, where a verifier is a Turing machine that halts on all inputs and for all $w \in \Sigma^*$, $w \in L \leftrightarrow \exists c \in \Sigma^*. V\text{ accepts }\langle w, c\rangle$. Commonly, $c$ is tho...
null
null
null
null
Right, but you need to suggest a counter-example. Saying that the states might separate in the operation of the minimization algorithm is not a proof. $p\equiv_k q$ means that for all words $w$ of length at most $k$, there is an accepting run from $p$ on $w$ iff there is an accepting run from $q$ on $w$. In words, ...
Right, but you need to suggest a counter-example. Saying that the states might separate in the operation of a minimization algorithm is not a proof. $p\equiv_k q$ means that for all words $w$ of length at most $k$, there is an accepting run from $p$ on $w$ iff there is an accepting run from $q$ on $w$. In words, th...
This is an old exam question, but I never found a solution or somebody who could explain it to me. Here is the problem statement: Let $\Sigma$ be an alphabet with |$\Sigma$| $\geq 2$. Show that for any Languages $L_1 \subseteq \Sigma^*$ and $L_2 \subseteq \Sigma^*$ there is a Language $L \subseteq \Sigma^*$ and the...
show for any Languages $L_1$ and $L_2$ exists a Language $L$ with $L_1 \leq_{log} L$ and $L_2 \leq_{log} L$
|reductions|
I guess it's something like $L = \{ 0x \mid x \in L_1 \} \cup \{ 1y \mid y \in L_2\}$ ..?
I understood Sipser's proof of CFG to PDA but I am having a hard time understanding his proof of conversion from PDA to CFG while demonstrating the equivalence between the two. He splits the proof (Lemma 2.27, page 121) in 4 parts: 1) Modify the PDA so there's 1 start state, 1 final state and every transition incr...
Sipser's proof of PDA equivalent to CFG ( -> direction)
|context-free|pushdown-automata|theory|
Sipser's proof of PDA to CFG
Intuition for Sipser's proof of PDA to CFG
This is very similar in principle to an h.264 decoder where each cell depends on the cell above and the cell to the left. Let k = i + j. Then some A with i + j = k only depends on A with i + j = k-8 and i + j = k-6. Assuming your indices start at 1, you need to define the result for i <= 4, j <= 4 first. Loop f...
Genetic algorithm (GA) is *general purpose* metaheuristic often used in computational science, e.g. computational physics. However, some authors of computational physics software, e.g. [1], tend to *specialize* GA to the given problem on the level of variation operators. I do appreciate this approach and their work, bu...
When should genetic algorithm's variation operators be specialized?
|optimization|genetic-algorithms|
As mentioned in the comments, @xavierm02's answer has a bug. One can try and fix it, but here is a [simpler construction][1] [Kao, Rampersad, Shallit]. Given an NFA $A = (\Sigma, Q, q_0, \delta, F)$ with a single initial state, one can return the NFA $B$ that is obtained from A by turning all of its states to accepting...
As mentioned in the comments, @xavierm02's answer has a bug. One can try and fix it, but here is a [simpler construction][1] [Kao, Rampersad, Shallit]. Given an NFA $A = (\Sigma, Q, q_0, \delta, F)$ with a single initial state, one can return the NFA $B$ that is obtained from A by turning all of its states to accepting...
Let's denote the start state as $s$ and accept state as $t$. To prove that every PDA $P$ can be converted to some CFG, we can: 1. for every PDA $P$ show an CFG $A$. This is part 2: show how to construct the CFG $A_{st}$. 2. prove that the languages recognized by $P$ and $A$ are equivalent. To prove the second poi...
null
This is very similar in principle to an h.264 decoder where each cell depends on the cell above and the cell to the left. Let k = i + j. Then some A with i + j = k only depends on A with i + j = k-8 and i + j = k-6. Assuming your indices start at 1, you need to define the result for i <= 4, j <= 4 first. Loop f...
Let us understand the proof by example. Suppose $d=3$. Select $d+1=4$ points, which are the 3 unit-coordinate vectors $(1,0,0)$, $(0,1,0)$, $(0,0,1)$ and the origin $(0,0,0)$. Let $C$ be the set of these 4 points. Suppose $A$ is any subset of these 4 points. There are two cases. - The origin is not in ...
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
**Statement :** A half space is set of all points on one side of a linear separator, i.e., a set of the form $\{x \mid w^{T}x \ge t\}$. The VC-dimension of half spaces in $d$-dimensions is at least $d+1$. **Proof Idea.** There exists a set of size $d+1$ that can be shattered by half-spaces. Select the $d$ unit-coord...
How can I understand the proof of the VC dimension of half-spaces in d-dimensions?
|machine-learning|vc-dimension|
This is very similar in principle to an h.264 decoder where each cell depends on the cell above and the cell to the left. Let k = i + j. Then some A with i + j = k only depends on A with i + j = k-8 and i + j = k-6. Assuming your indices start at 1, you need to define the result for i <= 4, j <= 4 first. Loop f...
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
It's usually better to customize your approach to things that you know about your specific problem. NFL (the No Free Lunch theorems) applies here, so on average across all possible problem instances, everything performs equally. This implies that there are some problems where approach A will outperform approach B, and ...
I'm studying for my exams and a came through this exercise but I can't prove the result I found. Given this piece of code: ```c int k = 0; while (k < n/2) { for (int l=k+1; l<=n; l=l*2) { printf("\n"); } k = k+2; } ``` I am asked to calculate how many times ```printf()``` will be called...
How to calculate how many times a function inside a for loop inside a while loop will be called?
|complexity-theory|algorithm-analysis|c|
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
null
It's not *necessary*. But customizing the operators might yield better results (either faster convergence, or higher-quality solutions). In some cases this kind of customization can help a lot. In others it might not help much, or at all. There's no surefire way to know a priori whether customization will help. ...
I am working on building ML/DL solution for a problem where that data is considered, naturally similar and I am worried if that would be considered as data redundancy. My question is, is that so? and if yes what can I do about this then, since this is a feature of the actual real data?
Would samples be considered data redundancy if they are similar to each other fairly naturally?
|machine-learning|data-mining|
The secret of the PDA to CFG proof is recursion. CFG's are by definition good in recursion. Sipser explicitly constructs a CGF and the Lemma's are provided to show his construction works. His CFG has nonterminals of the form $A_{pq}$ and the intuitive meaning is that they correspond to "computations of the PDA start...
> Why do some "common sense" ... arguments ... I'm not sure if this question is on topic here, however ... "Common sense" arguments often lead to completely wrong results: This is not only the case for proofs but also for estimations of values that are only very difficult to calculate. The [birthday paradox](h...
It seems that all the mass in the universe, converted to energy, is not enough to perform $2^{256}$ state changes. So an $n^{256}$ algorithm cannot even finish for n = 2. But assume we find an algorithm that solves instances of size n in $n^{10}$ nanoseconds. Then we can solve instances of size 8 in a second, size ...
For a different kind of example, consider the language consisting of the usual decimal representations of integer multiples of 7, namely $\{ \dots, -14, -7, 0, 7, 14, 21, 28, \dots \}$. This is a regular language. (And in fact, the same would be true with any other positive integer instead than 7; but 7 is a cool examp...