id
int64
1
141k
title
stringlengths
15
150
body
stringlengths
45
28.5k
tags
stringlengths
1
102
label
int64
1
1
text
stringlengths
128
28.6k
source
stringclasses
1 value
4,874
Why are decision problems commonly used in complexity theory?
<p>From <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory#Complexity_classes">Wikipedia</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>The type of computational problem: <strong>The most commonly used problems are&#xA; decision problems</strong>. However, complexity classes can be defined based on&#xA; function problems, counting problems, optimization problems, promise&#xA; problems, etc.</p>&#xA;</blockquote>&#xA;&#xA;<p>I also saw the definitions of NP-complete, NP-hard, NP, ..., are defined for decision problems only. I wonder why that is the case?</p>&#xA;&#xA;<p>Is it because any other problem can be equivalently converted to a decision problem? </p>&#xA;
complexity theory terminology
1
Why are decision problems commonly used in complexity theory? -- (complexity theory terminology) <p>From <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory#Complexity_classes">Wikipedia</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>The type of computational problem: <strong>The most commonly used problems are&#xA; decision problems</strong>. However, complexity classes can be defined based on&#xA; function problems, counting problems, optimization problems, promise&#xA; problems, etc.</p>&#xA;</blockquote>&#xA;&#xA;<p>I also saw the definitions of NP-complete, NP-hard, NP, ..., are defined for decision problems only. I wonder why that is the case?</p>&#xA;&#xA;<p>Is it because any other problem can be equivalently converted to a decision problem? </p>&#xA;
habedi/stack-exchange-dataset
4,880
Relation between problems and algorithms
<p>From <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory" rel="nofollow">Wikipedia</a></p>&#xA;&#xA;<blockquote>&#xA; <p><strong>a computational problem</strong> is understood to be a task that is in principle amenable to being solved by a computer (i.e. the problem can&#xA; be stated by a set of mathematical instructions). Informally, a&#xA; computational problem consists of <strong>problem instances</strong> and <strong>solutions</strong> to&#xA; these problem instances. For example, primality testing is the problem&#xA; of determining whether a given number is prime or not. The instances&#xA; of this problem are natural numbers, and the solution to an instance&#xA; is yes or no based on whether the number is prime or not.</p>&#xA; &#xA; <p>... A key distinction between analysis of algorithms and computational&#xA; complexity theory is that the former is devoted to <strong>analyzing the&#xA; amount of resources needed by a particular algorithm to solve a&#xA; problem</strong>, whereas the latter asks a more general question about <strong>all&#xA; possible algorithms that could be used to solve the same problem</strong>.</p>&#xA;</blockquote>&#xA;&#xA;<p>So a problem can be solved by multiple algorithms. </p>&#xA;&#xA;<p>I was wondering if an algorithm can solve different problems, or can only solve one problem? Note that I distinguish a problem and its instances as in the quote.</p>&#xA;
algorithms complexity theory terminology
1
Relation between problems and algorithms -- (algorithms complexity theory terminology) <p>From <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory" rel="nofollow">Wikipedia</a></p>&#xA;&#xA;<blockquote>&#xA; <p><strong>a computational problem</strong> is understood to be a task that is in principle amenable to being solved by a computer (i.e. the problem can&#xA; be stated by a set of mathematical instructions). Informally, a&#xA; computational problem consists of <strong>problem instances</strong> and <strong>solutions</strong> to&#xA; these problem instances. For example, primality testing is the problem&#xA; of determining whether a given number is prime or not. The instances&#xA; of this problem are natural numbers, and the solution to an instance&#xA; is yes or no based on whether the number is prime or not.</p>&#xA; &#xA; <p>... A key distinction between analysis of algorithms and computational&#xA; complexity theory is that the former is devoted to <strong>analyzing the&#xA; amount of resources needed by a particular algorithm to solve a&#xA; problem</strong>, whereas the latter asks a more general question about <strong>all&#xA; possible algorithms that could be used to solve the same problem</strong>.</p>&#xA;</blockquote>&#xA;&#xA;<p>So a problem can be solved by multiple algorithms. </p>&#xA;&#xA;<p>I was wondering if an algorithm can solve different problems, or can only solve one problem? Note that I distinguish a problem and its instances as in the quote.</p>&#xA;
habedi/stack-exchange-dataset
4,884
Meaning of complexity of a computational problem
<p>If I understand correctly, the complexity of solving a computational problem is defined in terms of which instance $I$ of the problem, what size $n$ of the problem instance, and what algorithm $A$ for solving the problem instance.</p>&#xA;&#xA;<p>Is the complexity of the problem at a given size $n$ of the problem instance defined as&#xA;$$&#xA;\min_A \max_{I\in \{\text{instances of size }n\}} \text{complexity}(A,I,n)?&#xA;$$&#xA;Note that the solution to the above optimization $A^*(n)$ and $I^*(n)$ are both functions of instance size $n$.</p>&#xA;&#xA;<p>Or is the complexity of the problem defined for some same algorithm for all the problem instances and all sizes of the problem instances?</p>&#xA;&#xA;<p>Or is the complexity of the problem defined for some same instance for all the algorithms that solve the problem and all the problem instance sizes?</p>&#xA;
complexity theory terminology
1
Meaning of complexity of a computational problem -- (complexity theory terminology) <p>If I understand correctly, the complexity of solving a computational problem is defined in terms of which instance $I$ of the problem, what size $n$ of the problem instance, and what algorithm $A$ for solving the problem instance.</p>&#xA;&#xA;<p>Is the complexity of the problem at a given size $n$ of the problem instance defined as&#xA;$$&#xA;\min_A \max_{I\in \{\text{instances of size }n\}} \text{complexity}(A,I,n)?&#xA;$$&#xA;Note that the solution to the above optimization $A^*(n)$ and $I^*(n)$ are both functions of instance size $n$.</p>&#xA;&#xA;<p>Or is the complexity of the problem defined for some same algorithm for all the problem instances and all sizes of the problem instances?</p>&#xA;&#xA;<p>Or is the complexity of the problem defined for some same instance for all the algorithms that solve the problem and all the problem instance sizes?</p>&#xA;
habedi/stack-exchange-dataset
4,887
Dijkstra to favor solution with smallest number of edges if several paths have same weight
<p>You can modify any graph $G$ so that Dijkstra's finds the solution with the minimal number of edges thusly:</p>&#xA;&#xA;<p>Multiply every edge weight with a number $a$, then add $1$ to the weight to penalize each additional edge in the solution, i.e. </p>&#xA;&#xA;<p>$w'(u,v)=a*w(u,v)+1$</p>&#xA;&#xA;<p>This does not work for all values of $a$; $a$ needs to be at least $x$ for this to work. If $a$ is not this minimum number, it might not choose the shortest path. How do I find this minimum value $x$?</p>&#xA;&#xA;<p>Ps. This was done recreationally, I'm done with homework long ago.</p>&#xA;
algorithms graphs shortest path
1
Dijkstra to favor solution with smallest number of edges if several paths have same weight -- (algorithms graphs shortest path) <p>You can modify any graph $G$ so that Dijkstra's finds the solution with the minimal number of edges thusly:</p>&#xA;&#xA;<p>Multiply every edge weight with a number $a$, then add $1$ to the weight to penalize each additional edge in the solution, i.e. </p>&#xA;&#xA;<p>$w'(u,v)=a*w(u,v)+1$</p>&#xA;&#xA;<p>This does not work for all values of $a$; $a$ needs to be at least $x$ for this to work. If $a$ is not this minimum number, it might not choose the shortest path. How do I find this minimum value $x$?</p>&#xA;&#xA;<p>Ps. This was done recreationally, I'm done with homework long ago.</p>&#xA;
habedi/stack-exchange-dataset
4,888
Is there any way to distinguish between LL(k) and LR(k) grammar?
<p>I am recently studying about Compilers designing. I came to know about two types of grammar one is LL grammar and other is LR grammar.</p>&#xA;&#xA;<p>We also know the facts that every LL grammar is LR that is LL grammar is a proper subset of LR grammar. First one is used in top-down parsing and the second one is used in bottom-up parsing. </p>&#xA;&#xA;<p>But is there any way to so that we can say that a given grammar is LL or LR?</p>&#xA;
formal grammars compilers parsers lr k ll k
1
Is there any way to distinguish between LL(k) and LR(k) grammar? -- (formal grammars compilers parsers lr k ll k) <p>I am recently studying about Compilers designing. I came to know about two types of grammar one is LL grammar and other is LR grammar.</p>&#xA;&#xA;<p>We also know the facts that every LL grammar is LR that is LL grammar is a proper subset of LR grammar. First one is used in top-down parsing and the second one is used in bottom-up parsing. </p>&#xA;&#xA;<p>But is there any way to so that we can say that a given grammar is LL or LR?</p>&#xA;
habedi/stack-exchange-dataset
4,898
Separate all leaves of a weighted tree with minimum weight cuts
<p>This is part of a larger problem, which I believe I have reduced to this. Given a tree $T$ having positive edge weights, and $k$ leaves (nodes which have exactly one connected node), I need to delete some edges in the tree so that no two leaves in the original tree are connected (by a path) in the newly formed forest (of trees). The total sum of the weights of the deleted edges needs to be minimized.</p>&#xA;&#xA;<p>My understanding is that atleast $k-1$ edges need to be deleted to separate out all the $k$ leaves. Any more deletions will unnecessarily increase the total cost. Thus, we need to perform exactly $k-1$ deletions.</p>&#xA;&#xA;<p>My hypothesis:&#xA;For every pair of leaf nodes $l_i$ and $l_j$, find the edge with the minimum weight in the (unique) path from $l_i$ to $l_j$. The $k-1$ least weight edges from this set of edges need to be deleted. This will minimize the sum of weights of the edges to be deleted in order to disconnect all leaves from each other.</p>&#xA;&#xA;<p>I am unable to prove or disprove this hypothesis. Can someone please prove the correctness of this hypothesis, or give a counter-example along with the correct algorithm to solve this problem? If this is indeed correct, is there a faster way (asymptotic complexity wise) to solve this problem? This approach will take $\Theta({k^2})$ time. Thanks in advance!</p>&#xA;
algorithms graphs trees
1
Separate all leaves of a weighted tree with minimum weight cuts -- (algorithms graphs trees) <p>This is part of a larger problem, which I believe I have reduced to this. Given a tree $T$ having positive edge weights, and $k$ leaves (nodes which have exactly one connected node), I need to delete some edges in the tree so that no two leaves in the original tree are connected (by a path) in the newly formed forest (of trees). The total sum of the weights of the deleted edges needs to be minimized.</p>&#xA;&#xA;<p>My understanding is that atleast $k-1$ edges need to be deleted to separate out all the $k$ leaves. Any more deletions will unnecessarily increase the total cost. Thus, we need to perform exactly $k-1$ deletions.</p>&#xA;&#xA;<p>My hypothesis:&#xA;For every pair of leaf nodes $l_i$ and $l_j$, find the edge with the minimum weight in the (unique) path from $l_i$ to $l_j$. The $k-1$ least weight edges from this set of edges need to be deleted. This will minimize the sum of weights of the edges to be deleted in order to disconnect all leaves from each other.</p>&#xA;&#xA;<p>I am unable to prove or disprove this hypothesis. Can someone please prove the correctness of this hypothesis, or give a counter-example along with the correct algorithm to solve this problem? If this is indeed correct, is there a faster way (asymptotic complexity wise) to solve this problem? This approach will take $\Theta({k^2})$ time. Thanks in advance!</p>&#xA;
habedi/stack-exchange-dataset
4,899
Expected gain of a game of chance with differently-priced tokens
<p>Foo and Bar are playing a game of strategy. At the start of the game, there are $N$ apples, placed in a row (in straight line). The apples are numbered from $1$ to $N$. Each apple has a particular price value.</p>&#xA;&#xA;<p>The price of $i$th apple is $p_i$.</p>&#xA;&#xA;<p>In this game, the players Foo and bar make an alternative move.</p>&#xA;&#xA;<p>In each move, the player does the following:</p>&#xA;&#xA;<ul>&#xA;<li>If there is more than one apple left, the player tosses an unbiased coin. If the outcome is head, the player takes the first apple among the apples that are currently present in a row in a straight line.</li>&#xA;<li>If there is a single apple left, te player takes it.</li>&#xA;</ul>&#xA;&#xA;<p>The goal here is to calculate the expected total price value that Foo will get if Foo plays first.</p>&#xA;&#xA;<pre><code>Example 1:&#xA;N=5&#xA;Apple price val: &#xA;5 2 3 1 5 &#xA;&#xA;Answer is : 11.00&#xA;&#xA;Example 2:&#xA;N=6&#xA;7 8 2 3 7 8&#xA;&#xA;Answer : 21.250&#xA;&#xA;&#xA;Example 3:&#xA;N=3&#xA;1 4 9&#xA;&#xA;First Second Third Foo Total Val&#xA;Foo gets 1 Bar gets 4 Foo gets 9 10&#xA;Foo gets 1 Bar gets 9 Foo gets 4 5&#xA;Foo gets 9 Bar gets 1 Foo gets 4 13&#xA;Foo gets 9 Bar gets 4 Foo gets 1 10&#xA;&#xA;probability 0.5 • 0.5 = 0.25. &#xA;Expected value (Foo)= (0.25 *10 )+ (0.25 *5) + (0.25*13)+ (0.25*10) = 9.500&#xA;</code></pre>&#xA;&#xA;<p>I wrote the following code:</p>&#xA;&#xA;<pre><code>#include&lt;iostream&gt;&#xA;using namespace std;&#xA;double calculate(int start,int end,int num,int current);&#xA;int arr[2010];&#xA;int main()&#xA;{&#xA; int T;&#xA; scanf("%d",&amp;T);&#xA; for(int t=0;t&lt;T;t++)&#xA; {&#xA; int N;&#xA; scanf("%d",&amp;N);&#xA; for(int i=0;i&lt;N;i++)&#xA; {&#xA; scanf("%d",&amp;arr[i]);&#xA; }&#xA; printf("%.3lf\n",calculate(0,N-1,N/2+N%2,0)); &#xA; }&#xA;&#xA; return 0;&#xA;}&#xA;double calculate(int start,int end,int num,int current)&#xA;{&#xA; if(num==current)&#xA; return 0;&#xA; double value=0;&#xA; value=.5*arr[start]+.5*arr[end]+.5*calculate(start+1,end,num,current+1)+.5*calculate(start,end-1,num,current+1);&#xA; return value;&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>But the above code is quite slow. The constraints are: price of apples $p_i \le 1000$; $1 \le N \le 2000$; there are 500 test cases. How can I solve this more efficiently?</p>&#xA;
algorithms game theory
1
Expected gain of a game of chance with differently-priced tokens -- (algorithms game theory) <p>Foo and Bar are playing a game of strategy. At the start of the game, there are $N$ apples, placed in a row (in straight line). The apples are numbered from $1$ to $N$. Each apple has a particular price value.</p>&#xA;&#xA;<p>The price of $i$th apple is $p_i$.</p>&#xA;&#xA;<p>In this game, the players Foo and bar make an alternative move.</p>&#xA;&#xA;<p>In each move, the player does the following:</p>&#xA;&#xA;<ul>&#xA;<li>If there is more than one apple left, the player tosses an unbiased coin. If the outcome is head, the player takes the first apple among the apples that are currently present in a row in a straight line.</li>&#xA;<li>If there is a single apple left, te player takes it.</li>&#xA;</ul>&#xA;&#xA;<p>The goal here is to calculate the expected total price value that Foo will get if Foo plays first.</p>&#xA;&#xA;<pre><code>Example 1:&#xA;N=5&#xA;Apple price val: &#xA;5 2 3 1 5 &#xA;&#xA;Answer is : 11.00&#xA;&#xA;Example 2:&#xA;N=6&#xA;7 8 2 3 7 8&#xA;&#xA;Answer : 21.250&#xA;&#xA;&#xA;Example 3:&#xA;N=3&#xA;1 4 9&#xA;&#xA;First Second Third Foo Total Val&#xA;Foo gets 1 Bar gets 4 Foo gets 9 10&#xA;Foo gets 1 Bar gets 9 Foo gets 4 5&#xA;Foo gets 9 Bar gets 1 Foo gets 4 13&#xA;Foo gets 9 Bar gets 4 Foo gets 1 10&#xA;&#xA;probability 0.5 • 0.5 = 0.25. &#xA;Expected value (Foo)= (0.25 *10 )+ (0.25 *5) + (0.25*13)+ (0.25*10) = 9.500&#xA;</code></pre>&#xA;&#xA;<p>I wrote the following code:</p>&#xA;&#xA;<pre><code>#include&lt;iostream&gt;&#xA;using namespace std;&#xA;double calculate(int start,int end,int num,int current);&#xA;int arr[2010];&#xA;int main()&#xA;{&#xA; int T;&#xA; scanf("%d",&amp;T);&#xA; for(int t=0;t&lt;T;t++)&#xA; {&#xA; int N;&#xA; scanf("%d",&amp;N);&#xA; for(int i=0;i&lt;N;i++)&#xA; {&#xA; scanf("%d",&amp;arr[i]);&#xA; }&#xA; printf("%.3lf\n",calculate(0,N-1,N/2+N%2,0)); &#xA; }&#xA;&#xA; return 0;&#xA;}&#xA;double calculate(int start,int end,int num,int current)&#xA;{&#xA; if(num==current)&#xA; return 0;&#xA; double value=0;&#xA; value=.5*arr[start]+.5*arr[end]+.5*calculate(start+1,end,num,current+1)+.5*calculate(start,end-1,num,current+1);&#xA; return value;&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>But the above code is quite slow. The constraints are: price of apples $p_i \le 1000$; $1 \le N \le 2000$; there are 500 test cases. How can I solve this more efficiently?</p>&#xA;
habedi/stack-exchange-dataset
4,905
How do I write a proof using induction on the length of the input string?
<p>In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it if someone would go through the process of making such a proof step by step.</p>&#xA;&#xA;<p>Here's an example problem (Exercise 2.2.10 from Hopcroft and Ullman 3rd Edition):</p>&#xA;&#xA;<blockquote>&#xA; <p>Consider the DFA with the following transition table:</p>&#xA;&#xA;<pre>&#xA; 0 1&#xA; ________&#xA;-> A | A B&#xA; *B | B A&#xA;</pre>&#xA; &#xA; <p>Informally describe the language accepted by this DFA, and prove by induction on the length of an input string that your description is correct.</p>&#xA;</blockquote>&#xA;&#xA;<p>This is an answered problem in the book, so I'm not looking for someone to do my homework. I just need someone to explain it to me straight.</p>&#xA;&#xA;<p><strong>Book's Answer:</strong>&#xA;(taken from <a href="http://infolab.stanford.edu/~ullman/ialcsols/sol2.html">here</a>)</p>&#xA;&#xA;<blockquote>&#xA; <p>The automaton tells whether the number of 1's seen is even (state A) or odd (state B), accepting in the latter case. It is an easy induction on |w| to show that dh(A,w) = A if and only if w has an even number of 1's.&#xA; Basis: |w| = 0. Then w, the empty string surely has an even number of 1's, namely zero 1's, and δ-hat(A,w) = A.</p>&#xA; &#xA; <p>Induction: Assume the statement for strings shorter than w. Then w = za, where a is either 0 or 1.</p>&#xA; &#xA; <ul>&#xA; <li><p><strong>Case 1:</strong> a = 0. If w has an even number of 1's, so does z. By the inductive hypothesis, δ-hat(A,z) = A. The transitions of the DFA tell us δ-hat(A,w) = A. If w has an odd number of 1's, then so does z. By the inductive hypothesis, δ-hat(A,z) = B, and the transitions of the DFA tell us δ-hat(A,w) = B. Thus, in this case, δ-hat(A,w) = A if and only if w has an even number of 1's.</p></li>&#xA; <li><p><strong>Case 2:</strong> a = 1. If w has an even number of 1's, then z has an odd number of 1's. By the inductive hypothesis, δ-hat(A,z) = B. The transitions of the DFA tell us δ-hat(A,w) = A. If w has an odd number of 1's, then z has an even number of 1's. By the inductive hypothesis, δ-hat(A,z) = A, and the transitions of the DFA tell us δ-hat(A,w) = B. Thus, in this case as well, δ-hat(A,w) = A if and only if w has an even number of 1's.</p></li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>I understand how to prove things like $\sum_{i=0}^{n}i = \frac{n(n+1)}{2}$ using induction. I'm just confused by how this works with building strings. I'm confused by the bolded parts. I don't understand how they are come up with/how it actually proves what is accepted/how it is inductive.</p>&#xA;&#xA;<p>δ-hat is the extended transition function, by the way.</p>&#xA;
automata finite automata proof techniques reference question induction
1
How do I write a proof using induction on the length of the input string? -- (automata finite automata proof techniques reference question induction) <p>In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it if someone would go through the process of making such a proof step by step.</p>&#xA;&#xA;<p>Here's an example problem (Exercise 2.2.10 from Hopcroft and Ullman 3rd Edition):</p>&#xA;&#xA;<blockquote>&#xA; <p>Consider the DFA with the following transition table:</p>&#xA;&#xA;<pre>&#xA; 0 1&#xA; ________&#xA;-> A | A B&#xA; *B | B A&#xA;</pre>&#xA; &#xA; <p>Informally describe the language accepted by this DFA, and prove by induction on the length of an input string that your description is correct.</p>&#xA;</blockquote>&#xA;&#xA;<p>This is an answered problem in the book, so I'm not looking for someone to do my homework. I just need someone to explain it to me straight.</p>&#xA;&#xA;<p><strong>Book's Answer:</strong>&#xA;(taken from <a href="http://infolab.stanford.edu/~ullman/ialcsols/sol2.html">here</a>)</p>&#xA;&#xA;<blockquote>&#xA; <p>The automaton tells whether the number of 1's seen is even (state A) or odd (state B), accepting in the latter case. It is an easy induction on |w| to show that dh(A,w) = A if and only if w has an even number of 1's.&#xA; Basis: |w| = 0. Then w, the empty string surely has an even number of 1's, namely zero 1's, and δ-hat(A,w) = A.</p>&#xA; &#xA; <p>Induction: Assume the statement for strings shorter than w. Then w = za, where a is either 0 or 1.</p>&#xA; &#xA; <ul>&#xA; <li><p><strong>Case 1:</strong> a = 0. If w has an even number of 1's, so does z. By the inductive hypothesis, δ-hat(A,z) = A. The transitions of the DFA tell us δ-hat(A,w) = A. If w has an odd number of 1's, then so does z. By the inductive hypothesis, δ-hat(A,z) = B, and the transitions of the DFA tell us δ-hat(A,w) = B. Thus, in this case, δ-hat(A,w) = A if and only if w has an even number of 1's.</p></li>&#xA; <li><p><strong>Case 2:</strong> a = 1. If w has an even number of 1's, then z has an odd number of 1's. By the inductive hypothesis, δ-hat(A,z) = B. The transitions of the DFA tell us δ-hat(A,w) = A. If w has an odd number of 1's, then z has an even number of 1's. By the inductive hypothesis, δ-hat(A,z) = A, and the transitions of the DFA tell us δ-hat(A,w) = B. Thus, in this case as well, δ-hat(A,w) = A if and only if w has an even number of 1's.</p></li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>I understand how to prove things like $\sum_{i=0}^{n}i = \frac{n(n+1)}{2}$ using induction. I'm just confused by how this works with building strings. I'm confused by the bolded parts. I don't understand how they are come up with/how it actually proves what is accepted/how it is inductive.</p>&#xA;&#xA;<p>δ-hat is the extended transition function, by the way.</p>&#xA;
habedi/stack-exchange-dataset
4,913
Nested Big O-notation
<p>Let's say I have a graph $|G|$ with $|E|=O(V^2)$ edges. I want to run BFS on $G$ which has a running time of $O(V+E)$.</p>&#xA;&#xA;<p>It feels natural to write that the running time on this graph would be $O(O(V^2)+V)$ and then simplify to $O(V^2)$.</p>&#xA;&#xA;<p>Are there any pitfalls to using such a "remove-the-nested-O" shortcut (not just in this case, but more generally)?</p>&#xA;
terminology asymptotics landau notation
1
Nested Big O-notation -- (terminology asymptotics landau notation) <p>Let's say I have a graph $|G|$ with $|E|=O(V^2)$ edges. I want to run BFS on $G$ which has a running time of $O(V+E)$.</p>&#xA;&#xA;<p>It feels natural to write that the running time on this graph would be $O(O(V^2)+V)$ and then simplify to $O(V^2)$.</p>&#xA;&#xA;<p>Are there any pitfalls to using such a "remove-the-nested-O" shortcut (not just in this case, but more generally)?</p>&#xA;
habedi/stack-exchange-dataset
4,914
Why can't DFS be used to find shortest paths in unweighted graphs?
<p>I understand that using DFS "as is" will not find a shortest path in an unweighted graph. </p>&#xA;&#xA;<p>But why is tweaking DFS to allow it to find shortest paths in unweighted graphs such a hopeless prospect? All texts on the subject simply state that it cannot be done. I'm unconvinced (without having tried it myself). </p>&#xA;&#xA;<p>Do you know any modifications that will allow DFS to find the shortest paths in unweighted graphs? If not, what is it about the algorithm that makes it so difficult?</p>&#xA;
algorithms graphs shortest path
1
Why can't DFS be used to find shortest paths in unweighted graphs? -- (algorithms graphs shortest path) <p>I understand that using DFS "as is" will not find a shortest path in an unweighted graph. </p>&#xA;&#xA;<p>But why is tweaking DFS to allow it to find shortest paths in unweighted graphs such a hopeless prospect? All texts on the subject simply state that it cannot be done. I'm unconvinced (without having tried it myself). </p>&#xA;&#xA;<p>Do you know any modifications that will allow DFS to find the shortest paths in unweighted graphs? If not, what is it about the algorithm that makes it so difficult?</p>&#xA;
habedi/stack-exchange-dataset
4,918
How to make a parse tree for the following propositional logic formula?
<p>I have a formula $ \neg((q \implies \neg q) \vee p \vee (\neg q \implies (r \wedge p))) $.</p>&#xA;&#xA;<p>As it contains 3 subformulas between the $\vee$'s, how can i put it into a parse tree, as a parse tree contains 2 branches from each node.</p>&#xA;
formal languages logic binary trees parsing
1
How to make a parse tree for the following propositional logic formula? -- (formal languages logic binary trees parsing) <p>I have a formula $ \neg((q \implies \neg q) \vee p \vee (\neg q \implies (r \wedge p))) $.</p>&#xA;&#xA;<p>As it contains 3 subformulas between the $\vee$'s, how can i put it into a parse tree, as a parse tree contains 2 branches from each node.</p>&#xA;
habedi/stack-exchange-dataset
4,924
Closure of Deterministic context-free languages under prefix
<p>For a formal language $L \subseteq \Sigma^{*}$ I define the set Pref(L) to be:</p>&#xA;&#xA;<p>$\text{pref}(L) = \{\alpha \in \Sigma^{*} : \exists \beta \in \Sigma^{*} \text{ such that } \alpha \beta \in L\}$</p>&#xA;&#xA;<p>ie. the set of all (not necessarily proper) prefixes of words in $L$. I know that if $L$ is context-free then pref(L) is context-free but if $L$ is deterministic context-free then is pref(L) deterministic context-free?</p>&#xA;&#xA;<p>I am sure this is known but I cannot find the answer anywhere and it's not in Hopcroft and Ullman.</p>&#xA;
formal languages context free closure properties
1
Closure of Deterministic context-free languages under prefix -- (formal languages context free closure properties) <p>For a formal language $L \subseteq \Sigma^{*}$ I define the set Pref(L) to be:</p>&#xA;&#xA;<p>$\text{pref}(L) = \{\alpha \in \Sigma^{*} : \exists \beta \in \Sigma^{*} \text{ such that } \alpha \beta \in L\}$</p>&#xA;&#xA;<p>ie. the set of all (not necessarily proper) prefixes of words in $L$. I know that if $L$ is context-free then pref(L) is context-free but if $L$ is deterministic context-free then is pref(L) deterministic context-free?</p>&#xA;&#xA;<p>I am sure this is known but I cannot find the answer anywhere and it's not in Hopcroft and Ullman.</p>&#xA;
habedi/stack-exchange-dataset
4,941
Dynamic programming with large number of subproblems
<p>Dynamic programming with large number of subproblems. So I'm trying to solve this problem from Interview Street:</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Grid Walking</strong> (Score 50 points)<br>&#xA; You are situated in an $N$-dimensional grid at position $(x_1,x_2,\dots,x_N)$. The dimensions of the grid are $(D_1,D_2,\dots,D_N$). In one step, you can walk one step ahead or behind in any one of the $N$ dimensions. (So there are always $2N$ possible different moves). In how many ways can you take $M$ steps such that you do not leave the grid at any point? You leave the grid if for any $x_i$, either $x_i \leq 0$ or $x_i &gt; D_i$.</p>&#xA;</blockquote>&#xA;&#xA;<p>My first try was this memoized recursive solution:</p>&#xA;&#xA;<pre><code>def number_of_ways(steps, starting_point):&#xA; global n, dimensions, mem&#xA; #print steps, starting_point&#xA; if (steps, tuple(starting_point)) in mem:&#xA; return mem[(steps, tuple(starting_point))]&#xA; val = 0&#xA; if steps == 0:&#xA; val = 1&#xA; else:&#xA; for i in range(0, n):&#xA; tuple_copy = starting_point[:]&#xA; tuple_copy[i] += 1&#xA; if tuple_copy[i] &lt;= dimensions[i]:&#xA; val += number_of_ways(steps - 1, tuple_copy)&#xA; tuple_copy = starting_point[:]&#xA; tuple_copy[i] -= 1&#xA; if tuple_copy[i] &gt; 0:&#xA; val += number_of_ways(steps - 1, tuple_copy)&#xA; mem[(steps, tuple(starting_point))] = val&#xA; return val&#xA;</code></pre>&#xA;&#xA;<p>Big surprise: it fails for a large number of steps and/or dimensions due to a lack of memory.</p>&#xA;&#xA;<p>So the next step is to improve my solution by using dynamic programming. But before starting, I'm seeing a major problem with the approach. The argument <code>starting_point</code> is an $n$-tuple, where $n$ is as large as $10$. So in fact, the function could be <code>number_of_ways(steps, x1, x2, x3, ... x10)</code> with $1 \leq x_i \leq 100$.</p>&#xA;&#xA;<p>The dynamic programming problems I've seen in textbooks almost all have twp variables, so that only a two-dimensional matrix is needed. In this case, a ten-dimensional matrix would be needed. So $100^{10}$ cells in total.</p>&#xA;&#xA;<p>With 2-D matrixes in dynamic programming, usually only the previous row of calculations is needed for the next calculation, hence reducing the spatial complexity from $mn$ to $\min(m,n)$. I'm not sure how I would do the same in this case. Visualizing a table isn't feasible, so the answer would have to come directly from the recursion above. </p>&#xA;&#xA;<p><strong>UPDATE</strong></p>&#xA;&#xA;<p>Using Peter Shor's suggestions, and making some minor corrections, notably the need to keep track of position in the $W(i, t_i)$ function, and rather than only splitting dimensions into two sets A and B, doing the splitting recursively, effectively using a divide-and-conquer method, until a base case is reached where only one dimension is in the set.</p>&#xA;&#xA;<p>I came up with the following implementation, which passed all tests below the maximum execution time:</p>&#xA;&#xA;<pre><code>def ways(di, offset, steps):&#xA; global mem, dimensions&#xA; if steps in mem[di] and offset in mem[di][steps]:&#xA; return mem[di][steps][offset]&#xA; val = 0&#xA; if steps == 0:&#xA; val = 1&#xA; else:&#xA; if offset - 1 &gt;= 1:&#xA; val += ways(di, offset - 1, steps - 1)&#xA; if offset + 1 &lt;= dimensions[di]:&#xA; val += ways(di, offset + 1, steps - 1)&#xA; mem[di][steps][offset] = val&#xA; return val&#xA;&#xA;&#xA;def set_ways(left, right, steps):&#xA; # must create t1, t2, t3 .. ti for steps&#xA; global mem_set, mem, starting_point&#xA; #print left, right&#xA; #sleep(2)&#xA; if (left, right) in mem_set and steps in mem_set[(left, right)]:&#xA; return mem_set[(left, right)][steps]&#xA; if right - left == 1:&#xA; #print 'getting steps for', left, steps, starting_point[left]&#xA; #print 'got ', mem[left][steps][starting_point[left]], 'steps'&#xA; return mem[left][steps][starting_point[left]]&#xA; #return ways(left, starting_point[left], steps)&#xA; val = 0&#xA; split_point = left + (right - left) / 2 &#xA; for i in xrange(steps + 1):&#xA; t1 = i&#xA; t2 = steps - i&#xA; mix_factor = fact[steps] / (fact[t1] * fact[t2])&#xA; #print "mix_factor = %d, dimension: %d - %d steps, dimension %d - %d steps" % (mix_factor, left, t1, split_point, t2)&#xA; val += mix_factor * set_ways(left, split_point, t1) * set_ways(split_point, right, t2)&#xA; mem_set[(left, right)][steps] = val&#xA; return val&#xA;&#xA;import sys&#xA;from time import sleep, time&#xA;&#xA;fact = {}&#xA;fact[0] = 1&#xA;start = time()&#xA;accum = 1&#xA;for k in xrange(1, 300+1):&#xA; accum *= k&#xA; fact[k] = accum&#xA;#print 'fact_time', time() - start&#xA;&#xA;data = sys.stdin.readlines()&#xA;num_tests = int(data.pop(0))&#xA;for ignore in xrange(0, num_tests):&#xA; n_and_steps = data.pop(0)&#xA; n, steps = map(lambda x: int(x), n_and_steps.split())&#xA; starting_point = map(lambda x: int(x), data.pop(0).split())&#xA; dimensions = map(lambda x: int(x), data.pop(0).split())&#xA; mem = {}&#xA; for di in xrange(n):&#xA; mem[di] = {}&#xA; for i in xrange(steps + 1):&#xA; mem[di][i] = {}&#xA; ways(di, starting_point[di], i)&#xA; start = time()&#xA; #print 'mem vector is done'&#xA; mem_set = {}&#xA; for i in xrange(n + 1):&#xA; for j in xrange(n + 1):&#xA; mem_set[(i, j)] = {}&#xA; answer = set_ways(0, n, steps)&#xA; #print answer&#xA; print answer % 1000000007&#xA; #print time() - start&#xA;</code></pre>&#xA;
algorithms efficiency dynamic programming
1
Dynamic programming with large number of subproblems -- (algorithms efficiency dynamic programming) <p>Dynamic programming with large number of subproblems. So I'm trying to solve this problem from Interview Street:</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Grid Walking</strong> (Score 50 points)<br>&#xA; You are situated in an $N$-dimensional grid at position $(x_1,x_2,\dots,x_N)$. The dimensions of the grid are $(D_1,D_2,\dots,D_N$). In one step, you can walk one step ahead or behind in any one of the $N$ dimensions. (So there are always $2N$ possible different moves). In how many ways can you take $M$ steps such that you do not leave the grid at any point? You leave the grid if for any $x_i$, either $x_i \leq 0$ or $x_i &gt; D_i$.</p>&#xA;</blockquote>&#xA;&#xA;<p>My first try was this memoized recursive solution:</p>&#xA;&#xA;<pre><code>def number_of_ways(steps, starting_point):&#xA; global n, dimensions, mem&#xA; #print steps, starting_point&#xA; if (steps, tuple(starting_point)) in mem:&#xA; return mem[(steps, tuple(starting_point))]&#xA; val = 0&#xA; if steps == 0:&#xA; val = 1&#xA; else:&#xA; for i in range(0, n):&#xA; tuple_copy = starting_point[:]&#xA; tuple_copy[i] += 1&#xA; if tuple_copy[i] &lt;= dimensions[i]:&#xA; val += number_of_ways(steps - 1, tuple_copy)&#xA; tuple_copy = starting_point[:]&#xA; tuple_copy[i] -= 1&#xA; if tuple_copy[i] &gt; 0:&#xA; val += number_of_ways(steps - 1, tuple_copy)&#xA; mem[(steps, tuple(starting_point))] = val&#xA; return val&#xA;</code></pre>&#xA;&#xA;<p>Big surprise: it fails for a large number of steps and/or dimensions due to a lack of memory.</p>&#xA;&#xA;<p>So the next step is to improve my solution by using dynamic programming. But before starting, I'm seeing a major problem with the approach. The argument <code>starting_point</code> is an $n$-tuple, where $n$ is as large as $10$. So in fact, the function could be <code>number_of_ways(steps, x1, x2, x3, ... x10)</code> with $1 \leq x_i \leq 100$.</p>&#xA;&#xA;<p>The dynamic programming problems I've seen in textbooks almost all have twp variables, so that only a two-dimensional matrix is needed. In this case, a ten-dimensional matrix would be needed. So $100^{10}$ cells in total.</p>&#xA;&#xA;<p>With 2-D matrixes in dynamic programming, usually only the previous row of calculations is needed for the next calculation, hence reducing the spatial complexity from $mn$ to $\min(m,n)$. I'm not sure how I would do the same in this case. Visualizing a table isn't feasible, so the answer would have to come directly from the recursion above. </p>&#xA;&#xA;<p><strong>UPDATE</strong></p>&#xA;&#xA;<p>Using Peter Shor's suggestions, and making some minor corrections, notably the need to keep track of position in the $W(i, t_i)$ function, and rather than only splitting dimensions into two sets A and B, doing the splitting recursively, effectively using a divide-and-conquer method, until a base case is reached where only one dimension is in the set.</p>&#xA;&#xA;<p>I came up with the following implementation, which passed all tests below the maximum execution time:</p>&#xA;&#xA;<pre><code>def ways(di, offset, steps):&#xA; global mem, dimensions&#xA; if steps in mem[di] and offset in mem[di][steps]:&#xA; return mem[di][steps][offset]&#xA; val = 0&#xA; if steps == 0:&#xA; val = 1&#xA; else:&#xA; if offset - 1 &gt;= 1:&#xA; val += ways(di, offset - 1, steps - 1)&#xA; if offset + 1 &lt;= dimensions[di]:&#xA; val += ways(di, offset + 1, steps - 1)&#xA; mem[di][steps][offset] = val&#xA; return val&#xA;&#xA;&#xA;def set_ways(left, right, steps):&#xA; # must create t1, t2, t3 .. ti for steps&#xA; global mem_set, mem, starting_point&#xA; #print left, right&#xA; #sleep(2)&#xA; if (left, right) in mem_set and steps in mem_set[(left, right)]:&#xA; return mem_set[(left, right)][steps]&#xA; if right - left == 1:&#xA; #print 'getting steps for', left, steps, starting_point[left]&#xA; #print 'got ', mem[left][steps][starting_point[left]], 'steps'&#xA; return mem[left][steps][starting_point[left]]&#xA; #return ways(left, starting_point[left], steps)&#xA; val = 0&#xA; split_point = left + (right - left) / 2 &#xA; for i in xrange(steps + 1):&#xA; t1 = i&#xA; t2 = steps - i&#xA; mix_factor = fact[steps] / (fact[t1] * fact[t2])&#xA; #print "mix_factor = %d, dimension: %d - %d steps, dimension %d - %d steps" % (mix_factor, left, t1, split_point, t2)&#xA; val += mix_factor * set_ways(left, split_point, t1) * set_ways(split_point, right, t2)&#xA; mem_set[(left, right)][steps] = val&#xA; return val&#xA;&#xA;import sys&#xA;from time import sleep, time&#xA;&#xA;fact = {}&#xA;fact[0] = 1&#xA;start = time()&#xA;accum = 1&#xA;for k in xrange(1, 300+1):&#xA; accum *= k&#xA; fact[k] = accum&#xA;#print 'fact_time', time() - start&#xA;&#xA;data = sys.stdin.readlines()&#xA;num_tests = int(data.pop(0))&#xA;for ignore in xrange(0, num_tests):&#xA; n_and_steps = data.pop(0)&#xA; n, steps = map(lambda x: int(x), n_and_steps.split())&#xA; starting_point = map(lambda x: int(x), data.pop(0).split())&#xA; dimensions = map(lambda x: int(x), data.pop(0).split())&#xA; mem = {}&#xA; for di in xrange(n):&#xA; mem[di] = {}&#xA; for i in xrange(steps + 1):&#xA; mem[di][i] = {}&#xA; ways(di, starting_point[di], i)&#xA; start = time()&#xA; #print 'mem vector is done'&#xA; mem_set = {}&#xA; for i in xrange(n + 1):&#xA; for j in xrange(n + 1):&#xA; mem_set[(i, j)] = {}&#xA; answer = set_ways(0, n, steps)&#xA; #print answer&#xA; print answer % 1000000007&#xA; #print time() - start&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
4,942
Finding paths with smallest maximum edge weight
<p>I need to find the easiest cost path between two vertices of a graph. Easiest here means the path with the smallest maximum-weigth edge. </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/WWszV.png" alt="enter image description here"></p>&#xA;&#xA;<p>In the above graph, the easiest path from 1 to 2 is: </p>&#xA;&#xA;<pre><code>1 &gt; 3 &gt; 4 &gt; 2&#xA;</code></pre>&#xA;&#xA;<p>Because the maximum edge weight is only 2. On the other hand, the shortest path <code>1 -&gt; 2</code> has maximum weight 4. </p>&#xA;&#xA;<p>So it's an MST problem. I am thinking I will use Kruskal's algorithm to build the tree, but I'm not sure how exactly. I will know the edges but how do I "reconstruct" the path? For example, given vertices <code>3</code> and <code>2</code>, how do I know to go left (top) of right in the tree? Or do I try both ways? </p>&#xA;
algorithms graphs shortest path
1
Finding paths with smallest maximum edge weight -- (algorithms graphs shortest path) <p>I need to find the easiest cost path between two vertices of a graph. Easiest here means the path with the smallest maximum-weigth edge. </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/WWszV.png" alt="enter image description here"></p>&#xA;&#xA;<p>In the above graph, the easiest path from 1 to 2 is: </p>&#xA;&#xA;<pre><code>1 &gt; 3 &gt; 4 &gt; 2&#xA;</code></pre>&#xA;&#xA;<p>Because the maximum edge weight is only 2. On the other hand, the shortest path <code>1 -&gt; 2</code> has maximum weight 4. </p>&#xA;&#xA;<p>So it's an MST problem. I am thinking I will use Kruskal's algorithm to build the tree, but I'm not sure how exactly. I will know the edges but how do I "reconstruct" the path? For example, given vertices <code>3</code> and <code>2</code>, how do I know to go left (top) of right in the tree? Or do I try both ways? </p>&#xA;
habedi/stack-exchange-dataset
4,960
Clarifications on polynomial reducibility for problems in P and NP-complete
<p><strong>Can I always increase the complexity of a problem via polynomial reduction?</strong> (in which case '<em>reduction</em>' is really a misnomer) For example, if I have a classic P problem (say, finding the smallest element in an array, by iterating through and making comparisons with the smallest value found thus far), what would be a corresponding problem in NP-complete (obtained via polynomial reduction)? Or, would it be possible to polynomially reduce a constant time (worst case) algorithm into a polynomial time algorithm (basically performing unnecessary executions for all n of the input for nothing)? </p>&#xA;&#xA;<p>As a side request, I'm looking for a basic reference that deals with how one problem (in P or NP-complete) can be reduced (in polynomial time) to a problem in (P or NP-complete). Most of the things I found online are beyond scope or vague. I'm looking for an easy way to figure out whether a certain Problem A (in P or NP-complete) can be polynomially reduced to a Problem B (in P or NP-complete).</p>&#xA;
complexity theory time complexity
1
Clarifications on polynomial reducibility for problems in P and NP-complete -- (complexity theory time complexity) <p><strong>Can I always increase the complexity of a problem via polynomial reduction?</strong> (in which case '<em>reduction</em>' is really a misnomer) For example, if I have a classic P problem (say, finding the smallest element in an array, by iterating through and making comparisons with the smallest value found thus far), what would be a corresponding problem in NP-complete (obtained via polynomial reduction)? Or, would it be possible to polynomially reduce a constant time (worst case) algorithm into a polynomial time algorithm (basically performing unnecessary executions for all n of the input for nothing)? </p>&#xA;&#xA;<p>As a side request, I'm looking for a basic reference that deals with how one problem (in P or NP-complete) can be reduced (in polynomial time) to a problem in (P or NP-complete). Most of the things I found online are beyond scope or vague. I'm looking for an easy way to figure out whether a certain Problem A (in P or NP-complete) can be polynomially reduced to a Problem B (in P or NP-complete).</p>&#xA;
habedi/stack-exchange-dataset
4,968
Are $\log_{10}(x)$ and $\log_2(x)$ in the same big-O class of functions?
<p>Are $\log_{10}(x)$ and $\log_{2}(x)$ in the same big-O class of functions? In other words, can one say that $\log_{10}(x)=O(\log x)$ and $\log_{2}(x)=O(\log x)$?</p>&#xA;
landau notation
1
Are $\log_{10}(x)$ and $\log_2(x)$ in the same big-O class of functions? -- (landau notation) <p>Are $\log_{10}(x)$ and $\log_{2}(x)$ in the same big-O class of functions? In other words, can one say that $\log_{10}(x)=O(\log x)$ and $\log_{2}(x)=O(\log x)$?</p>&#xA;
habedi/stack-exchange-dataset
4,972
What's the difference between a rule based system and an artificial neural network?
<p>I'm currently doing some reading into AI and up to this point couldn't find a satisfying answer to this question: what's the difference between a rule based system and an artificial neural network?</p>&#xA;&#xA;<p>From my understanding both are trying to do inference based on a variety of different inputs.</p>&#xA;
artificial intelligence neural networks
1
What's the difference between a rule based system and an artificial neural network? -- (artificial intelligence neural networks) <p>I'm currently doing some reading into AI and up to this point couldn't find a satisfying answer to this question: what's the difference between a rule based system and an artificial neural network?</p>&#xA;&#xA;<p>From my understanding both are trying to do inference based on a variety of different inputs.</p>&#xA;
habedi/stack-exchange-dataset
4,984
Prove that the language of non-prime numbers written in unary is not regular
<p>Im trying to prove that the following language is not regular.&#xA;$$\text{Notprime} = \{a^n \text{where \(n\) isn't prime}\}&#xA; = \{\epsilon, a, aaaa, aaaaaa, aaaaaaaa, \ldots\}$$</p>&#xA;&#xA;<p>Heres what I have:</p>&#xA;&#xA;<p>"If Notprime were regular, then its complement would be regular also. However, the complement of Notprime is the language Prime, hence Notprime is non-regular." </p>&#xA;&#xA;<p>Is this the right way of proving it? Any help is appreciated!</p>&#xA;
regular languages finite automata
1
Prove that the language of non-prime numbers written in unary is not regular -- (regular languages finite automata) <p>Im trying to prove that the following language is not regular.&#xA;$$\text{Notprime} = \{a^n \text{where \(n\) isn't prime}\}&#xA; = \{\epsilon, a, aaaa, aaaaaa, aaaaaaaa, \ldots\}$$</p>&#xA;&#xA;<p>Heres what I have:</p>&#xA;&#xA;<p>"If Notprime were regular, then its complement would be regular also. However, the complement of Notprime is the language Prime, hence Notprime is non-regular." </p>&#xA;&#xA;<p>Is this the right way of proving it? Any help is appreciated!</p>&#xA;
habedi/stack-exchange-dataset
4,989
Why does it take $O(f(n)^2)$ to simulate a 3-tape $O(f(n))$-time TM on a 1-tape TM?
<p>This looks like a fundamental result but I can't find a resource online that gives an intuitive interpretation of this complexity. Any basic explanation is appreciated.</p>&#xA;
turing machines tape complexity
1
Why does it take $O(f(n)^2)$ to simulate a 3-tape $O(f(n))$-time TM on a 1-tape TM? -- (turing machines tape complexity) <p>This looks like a fundamental result but I can't find a resource online that gives an intuitive interpretation of this complexity. Any basic explanation is appreciated.</p>&#xA;
habedi/stack-exchange-dataset
4,992
Which properties of context sensitive languages are decidable?
<p>There are two context-sensitive languages, $L_1$ and $L_2$. Which of the following statements about them are decidable respectively undecidable?</p>&#xA;&#xA;<ol>&#xA;<li>$L_1 = \emptyset$</li>&#xA;<li>$L_1 = \Sigma^*$</li>&#xA;<li>$L_1 \cap L_2 = \emptyset$</li>&#xA;<li>$\overline{L_1}$ is also a context-sensitive language.</li>&#xA;<li>$L_1 = L_2$</li>&#xA;</ol>&#xA;
formal languages undecidability context sensitive
1
Which properties of context sensitive languages are decidable? -- (formal languages undecidability context sensitive) <p>There are two context-sensitive languages, $L_1$ and $L_2$. Which of the following statements about them are decidable respectively undecidable?</p>&#xA;&#xA;<ol>&#xA;<li>$L_1 = \emptyset$</li>&#xA;<li>$L_1 = \Sigma^*$</li>&#xA;<li>$L_1 \cap L_2 = \emptyset$</li>&#xA;<li>$\overline{L_1}$ is also a context-sensitive language.</li>&#xA;<li>$L_1 = L_2$</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
4,994
Dynamic programming table for finding similar substrings is too large
<blockquote>&#xA; <p><strong>Substring Diff</strong><br>&#xA; Given two strings of length $n$, $P = p_1\dots p_n$ and $Q = q_1 \dots q_n$, we define $M(i, j, L)$ as the number of&#xA; mismatches between $p_i \dots p_{i+L-1}$ and $q_j \dots q_{j+L-1}$. In set&#xA; notation, $M(i, j, L)$ refers to the size of the set $\{0 \leq x &lt; L \mid p_{i + x} \neq q_{j + x}\}$.</p>&#xA; &#xA; <p>Given an integer $K$, your task is to find the maximum length $L$ such&#xA; that there exists pair of indices $(i,j)$ for which we have $M(i, j, L) \leq K$. Of course, we should also have $i + L - 1 \leq n$ and $j + L - 1 \leq n$.</p>&#xA; &#xA; <p><strong>Constraints</strong></p>&#xA; &#xA; <ul>&#xA; <li>$0 \leq K \leq |P|$</li>&#xA; <li>Both $P$ &amp; $Q$ would have the same length</li>&#xA; <li>The size of each of the string would be at the max <strong>1500</strong> </li>&#xA; <li>All characters in $P$ and $Q$ are lower-case English letters.</li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>The recursive function will have the form:</p>&#xA;&#xA;<pre><code>longest(string1, string2, allowed_mismatches) = &#xA; {&#xA; ... (something :P )&#xA; }&#xA;</code></pre>&#xA;&#xA;<p>The state space then has size $K^3$. With an upper bound on $K$ of 1500, the running time and space usage will be terrible... So direct dynamic programming will not work without some additional property to reduce the state space.</p>&#xA;&#xA;<p>Ideas?</p>&#xA;&#xA;<p><strong>UPDATE</strong></p>&#xA;&#xA;<p>Using the ideas suggested by both Yuval and Vor, I came up with the following solution that works like a charm, running in $O(K^2)$ time and using $K$ space.</p>&#xA;&#xA;<pre><code>def longest_range_min_sum(str1, str2, start1, start2, slice_size, max_sum):&#xA; longest = 0&#xA; i = 0&#xA; running_sum = 0&#xA; while i + longest &lt; slice_size:&#xA; if str1[start1 + i + longest] != str2[start2 + i + longest]:&#xA; running_sum += 1&#xA; if running_sum &gt; max_sum:&#xA; if str1[start1 + i] != str2[start2 + i]:&#xA; running_sum -= 1&#xA; i += 1&#xA; else:&#xA; longest += 1&#xA; return longest&#xA;&#xA;import sys&#xA;&#xA;data = sys.stdin.readlines()&#xA;num_cases = int(data.pop(0))&#xA;for ignore in xrange(num_cases):&#xA; max_mismatches, str1, str2 = data.pop(0).split()&#xA; max_mismatches = int(max_mismatches)&#xA; m = n = len(str1)&#xA; longest = 0&#xA; for i in xrange(m + n + 1):&#xA; if i &gt; n:&#xA; slice_size = m - (i - n)&#xA; else:&#xA; slice_size = min(i, m)&#xA; if slice_size == 0:&#xA; continue&#xA; end1 = max(m, m - i)&#xA; if i &gt; n:&#xA; end1 = m - (i - n)&#xA; start1 = end1 - slice_size&#xA; end2 = min(i, n)&#xA; start2 = end2 - slice_size&#xA; #print zeros_and_ones &#xA; #print str1[start1:end1], ' - ', str2[start2:end2]&#xA; longest_in_sub = longest_range_min_sum(str1, str2, start1, start2, slice_size, max_mismatches)&#xA; #print longest_in_sub&#xA; longest = max(longest, longest_in_sub)&#xA; print longest&#xA;</code></pre>&#xA;
strings dynamic programming substrings
1
Dynamic programming table for finding similar substrings is too large -- (strings dynamic programming substrings) <blockquote>&#xA; <p><strong>Substring Diff</strong><br>&#xA; Given two strings of length $n$, $P = p_1\dots p_n$ and $Q = q_1 \dots q_n$, we define $M(i, j, L)$ as the number of&#xA; mismatches between $p_i \dots p_{i+L-1}$ and $q_j \dots q_{j+L-1}$. In set&#xA; notation, $M(i, j, L)$ refers to the size of the set $\{0 \leq x &lt; L \mid p_{i + x} \neq q_{j + x}\}$.</p>&#xA; &#xA; <p>Given an integer $K$, your task is to find the maximum length $L$ such&#xA; that there exists pair of indices $(i,j)$ for which we have $M(i, j, L) \leq K$. Of course, we should also have $i + L - 1 \leq n$ and $j + L - 1 \leq n$.</p>&#xA; &#xA; <p><strong>Constraints</strong></p>&#xA; &#xA; <ul>&#xA; <li>$0 \leq K \leq |P|$</li>&#xA; <li>Both $P$ &amp; $Q$ would have the same length</li>&#xA; <li>The size of each of the string would be at the max <strong>1500</strong> </li>&#xA; <li>All characters in $P$ and $Q$ are lower-case English letters.</li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>The recursive function will have the form:</p>&#xA;&#xA;<pre><code>longest(string1, string2, allowed_mismatches) = &#xA; {&#xA; ... (something :P )&#xA; }&#xA;</code></pre>&#xA;&#xA;<p>The state space then has size $K^3$. With an upper bound on $K$ of 1500, the running time and space usage will be terrible... So direct dynamic programming will not work without some additional property to reduce the state space.</p>&#xA;&#xA;<p>Ideas?</p>&#xA;&#xA;<p><strong>UPDATE</strong></p>&#xA;&#xA;<p>Using the ideas suggested by both Yuval and Vor, I came up with the following solution that works like a charm, running in $O(K^2)$ time and using $K$ space.</p>&#xA;&#xA;<pre><code>def longest_range_min_sum(str1, str2, start1, start2, slice_size, max_sum):&#xA; longest = 0&#xA; i = 0&#xA; running_sum = 0&#xA; while i + longest &lt; slice_size:&#xA; if str1[start1 + i + longest] != str2[start2 + i + longest]:&#xA; running_sum += 1&#xA; if running_sum &gt; max_sum:&#xA; if str1[start1 + i] != str2[start2 + i]:&#xA; running_sum -= 1&#xA; i += 1&#xA; else:&#xA; longest += 1&#xA; return longest&#xA;&#xA;import sys&#xA;&#xA;data = sys.stdin.readlines()&#xA;num_cases = int(data.pop(0))&#xA;for ignore in xrange(num_cases):&#xA; max_mismatches, str1, str2 = data.pop(0).split()&#xA; max_mismatches = int(max_mismatches)&#xA; m = n = len(str1)&#xA; longest = 0&#xA; for i in xrange(m + n + 1):&#xA; if i &gt; n:&#xA; slice_size = m - (i - n)&#xA; else:&#xA; slice_size = min(i, m)&#xA; if slice_size == 0:&#xA; continue&#xA; end1 = max(m, m - i)&#xA; if i &gt; n:&#xA; end1 = m - (i - n)&#xA; start1 = end1 - slice_size&#xA; end2 = min(i, n)&#xA; start2 = end2 - slice_size&#xA; #print zeros_and_ones &#xA; #print str1[start1:end1], ' - ', str2[start2:end2]&#xA; longest_in_sub = longest_range_min_sum(str1, str2, start1, start2, slice_size, max_mismatches)&#xA; #print longest_in_sub&#xA; longest = max(longest, longest_in_sub)&#xA; print longest&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
4,998
Is there a O(log n) algorithm for matrix exponentiation?
<p>Is there an algorithm to raise a matrix to the <span class="math-container">$n$</span>th power in <span class="math-container">$O(\log n)$</span> time? </p>&#xA;&#xA;<p>I have been searching online, but have been unsuccessful thus far.</p>&#xA;
algorithms time complexity matrices
1
Is there a O(log n) algorithm for matrix exponentiation? -- (algorithms time complexity matrices) <p>Is there an algorithm to raise a matrix to the <span class="math-container">$n$</span>th power in <span class="math-container">$O(\log n)$</span> time? </p>&#xA;&#xA;<p>I have been searching online, but have been unsuccessful thus far.</p>&#xA;
habedi/stack-exchange-dataset
5,006
What's an intuitive distinction between semi-computable problems and noncomputable problems/functions?
<p>The definitions I've found were highly technical and using terms I've never seen before. </p>&#xA;&#xA;<p>Say, I have a certain irrational number <em>e</em> that I get get closer and closer to with a computer and I want to determine if there is a particular digit <em>d</em> appearing after a certain position. Or what about the halting problem (give a program and ask 'will the computer ever halt?')? Are these problems semi-computable problems or noncomputable?</p>&#xA;
computability terminology
1
What's an intuitive distinction between semi-computable problems and noncomputable problems/functions? -- (computability terminology) <p>The definitions I've found were highly technical and using terms I've never seen before. </p>&#xA;&#xA;<p>Say, I have a certain irrational number <em>e</em> that I get get closer and closer to with a computer and I want to determine if there is a particular digit <em>d</em> appearing after a certain position. Or what about the halting problem (give a program and ask 'will the computer ever halt?')? Are these problems semi-computable problems or noncomputable?</p>&#xA;
habedi/stack-exchange-dataset
5,009
What is the relationship between NP/NP-Complete/NP-Hard to time complexity?
<p>I'm familiar with a few problems of each class and even though the definitions are based on sets and polynomial reducibility, I see a pattern with time complexity. NP problems appear to be $O(2^n)$ (minus the P problems of course), and NP-hard problems seem to be worse: $n^n$ or $n!$ (Chess, TSP). Is this a misleading interpretation?</p>&#xA;
complexity theory terminology time complexity np hard
1
What is the relationship between NP/NP-Complete/NP-Hard to time complexity? -- (complexity theory terminology time complexity np hard) <p>I'm familiar with a few problems of each class and even though the definitions are based on sets and polynomial reducibility, I see a pattern with time complexity. NP problems appear to be $O(2^n)$ (minus the P problems of course), and NP-hard problems seem to be worse: $n^n$ or $n!$ (Chess, TSP). Is this a misleading interpretation?</p>&#xA;
habedi/stack-exchange-dataset
5,010
Finding an isomorphism between finite automata
<p>Im having trouble figuring out how to determine if two finite automata are the same apart from renumbered states. </p>&#xA;&#xA;<p>More specifically, heres an example:&#xA;<img src="https://i.stack.imgur.com/EPdpg.jpg" alt="example"> </p>&#xA;&#xA;<p>It's easy to generate a regular expression by hand and see that both FA produce: &#xA;b + (ab*a(a+b)), though their states are renumbered, they are identical.</p>&#xA;&#xA;<p>What I'm trying to do is figure out a way to check if the two states are the same apart from state renumbering without generating a regular expression. </p>&#xA;&#xA;<p>Since the states are just renumbered, I'm thinking it has something to do with permutations of the states(1 2 3 4) but am not seeing how to determine if they are equivalent. I'm thinking it has something to do with input like this and relating it to the 24 permutations of the states:</p>&#xA;&#xA;<pre><code>Left Right&#xA;1 a 2 4 a 3&#xA;1 b 4 4 b 1&#xA;2 a 3 3 a 2&#xA;2 b 2 3 b 3&#xA;3 a 4 2 a 1&#xA;3 b 4 2 b 1&#xA;</code></pre>&#xA;&#xA;<p>Im more so trying to figure out the algorithm to renumber the states Any ideas or help is greatly appreciated! </p>&#xA;
automata finite automata graph isomorphism
1
Finding an isomorphism between finite automata -- (automata finite automata graph isomorphism) <p>Im having trouble figuring out how to determine if two finite automata are the same apart from renumbered states. </p>&#xA;&#xA;<p>More specifically, heres an example:&#xA;<img src="https://i.stack.imgur.com/EPdpg.jpg" alt="example"> </p>&#xA;&#xA;<p>It's easy to generate a regular expression by hand and see that both FA produce: &#xA;b + (ab*a(a+b)), though their states are renumbered, they are identical.</p>&#xA;&#xA;<p>What I'm trying to do is figure out a way to check if the two states are the same apart from state renumbering without generating a regular expression. </p>&#xA;&#xA;<p>Since the states are just renumbered, I'm thinking it has something to do with permutations of the states(1 2 3 4) but am not seeing how to determine if they are equivalent. I'm thinking it has something to do with input like this and relating it to the 24 permutations of the states:</p>&#xA;&#xA;<pre><code>Left Right&#xA;1 a 2 4 a 3&#xA;1 b 4 4 b 1&#xA;2 a 3 3 a 2&#xA;2 b 2 3 b 3&#xA;3 a 4 2 a 1&#xA;3 b 4 2 b 1&#xA;</code></pre>&#xA;&#xA;<p>Im more so trying to figure out the algorithm to renumber the states Any ideas or help is greatly appreciated! </p>&#xA;
habedi/stack-exchange-dataset
5,036
Alternative to Hamming distance for permutations
<p>I have two strings, where one is a permutation of the other. I was wondering if there is an alternative to <a href="http://en.wikipedia.org/wiki/Hamming_distance">Hamming distance</a> where instead of finding the minimum number of substitutions required, it would find the minimum number of translocations required to go from string a to string b.</p>&#xA;&#xA;<p>My strings are always of the same size and I know there are no errors/substitutions.</p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<pre><code>1 2 3 4 5&#xA;3 2 5 4 1&#xA;</code></pre>&#xA;&#xA;<p>This would give me two:</p>&#xA;&#xA;<pre><code>3 2 5 4 1 (start)&#xA;-&gt; 3 2 1 4 5 &#xA;-&gt; -&gt; 1 2 3 4 5&#xA;</code></pre>&#xA;&#xA;<p>If this is already implemented in R that would be even better.</p>&#xA;
terminology string metrics permutations edit distance
1
Alternative to Hamming distance for permutations -- (terminology string metrics permutations edit distance) <p>I have two strings, where one is a permutation of the other. I was wondering if there is an alternative to <a href="http://en.wikipedia.org/wiki/Hamming_distance">Hamming distance</a> where instead of finding the minimum number of substitutions required, it would find the minimum number of translocations required to go from string a to string b.</p>&#xA;&#xA;<p>My strings are always of the same size and I know there are no errors/substitutions.</p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<pre><code>1 2 3 4 5&#xA;3 2 5 4 1&#xA;</code></pre>&#xA;&#xA;<p>This would give me two:</p>&#xA;&#xA;<pre><code>3 2 5 4 1 (start)&#xA;-&gt; 3 2 1 4 5 &#xA;-&gt; -&gt; 1 2 3 4 5&#xA;</code></pre>&#xA;&#xA;<p>If this is already implemented in R that would be even better.</p>&#xA;
habedi/stack-exchange-dataset
5,040
What is the difference between bounding and pruning in branch-and-bound algorithms?
<p>Could anybody please explain what the difference between "bounding" and "pruning" in branch and bound algorithms is?</p>&#xA;&#xA;<p>I'd also appreciate references (preferably books), where this distinction is made clear.</p>&#xA;
algorithms terminology branch and bound
1
What is the difference between bounding and pruning in branch-and-bound algorithms? -- (algorithms terminology branch and bound) <p>Could anybody please explain what the difference between "bounding" and "pruning" in branch and bound algorithms is?</p>&#xA;&#xA;<p>I'd also appreciate references (preferably books), where this distinction is made clear.</p>&#xA;
habedi/stack-exchange-dataset
5,042
Indirection in IAS computer
<p>From <a href="http://rads.stackoverflow.com/amzn/click/013293633X">Computer Organisation and Architecture</a>: </p>&#xA;&#xA;<blockquote>&#xA; <p>The IAS operates by repetitively performing an instruction cycle. Each&#xA; instruction cycle consists of two sub cycles. During a fetch cycle,&#xA; the opcode of the next instruction is loaded into the IR and the&#xA; address portion is loaded into MAR. This instruction may be taken from&#xA; the IBR, or it can be obtained from memory by loading a word int he&#xA; MBR, and then down to the IBR, IR, and MAR.</p>&#xA;</blockquote>&#xA;&#xA;<p>Now here, is there part I do not understand: </p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Why the indirection?</strong> These operations are controlled by electronic circuitry and result in the use of data paths. To simplify the&#xA; electronics, there is only register that is used to specify the&#xA; address in memory for a read or write and only one register used for&#xA; the source or destination.</p>&#xA;</blockquote>&#xA;&#xA;<p>Can anyone explain this to me more intuitively? Why is this indirection being used?</p>&#xA;
computer architecture
1
Indirection in IAS computer -- (computer architecture) <p>From <a href="http://rads.stackoverflow.com/amzn/click/013293633X">Computer Organisation and Architecture</a>: </p>&#xA;&#xA;<blockquote>&#xA; <p>The IAS operates by repetitively performing an instruction cycle. Each&#xA; instruction cycle consists of two sub cycles. During a fetch cycle,&#xA; the opcode of the next instruction is loaded into the IR and the&#xA; address portion is loaded into MAR. This instruction may be taken from&#xA; the IBR, or it can be obtained from memory by loading a word int he&#xA; MBR, and then down to the IBR, IR, and MAR.</p>&#xA;</blockquote>&#xA;&#xA;<p>Now here, is there part I do not understand: </p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Why the indirection?</strong> These operations are controlled by electronic circuitry and result in the use of data paths. To simplify the&#xA; electronics, there is only register that is used to specify the&#xA; address in memory for a read or write and only one register used for&#xA; the source or destination.</p>&#xA;</blockquote>&#xA;&#xA;<p>Can anyone explain this to me more intuitively? Why is this indirection being used?</p>&#xA;
habedi/stack-exchange-dataset
6,046
What is a good resource to learn about oriented matroids in the context of digraphs and optimization?
<p>I am interested in <a href="http://en.wikipedia.org/wiki/Oriented_matroid" rel="nofollow">oriented matroids</a> in the context of directed graphs and optimization. Unfortunately, I know very little of the topic. Is there a book, article or a resource that serves as a good introduction to oriented matroids, especially in the context of directed graphs? It's a bonus if the resource is suitable for an (under)graduate level course and is preferably even free.</p>&#xA;
optimization reference request discrete mathematics matroids
1
What is a good resource to learn about oriented matroids in the context of digraphs and optimization? -- (optimization reference request discrete mathematics matroids) <p>I am interested in <a href="http://en.wikipedia.org/wiki/Oriented_matroid" rel="nofollow">oriented matroids</a> in the context of directed graphs and optimization. Unfortunately, I know very little of the topic. Is there a book, article or a resource that serves as a good introduction to oriented matroids, especially in the context of directed graphs? It's a bonus if the resource is suitable for an (under)graduate level course and is preferably even free.</p>&#xA;
habedi/stack-exchange-dataset
6,055
Compute relational composition in $O(|E||V|)$
<p>Definitions: Let $G=(V,E)$ be a DAG without self-loops, and $X \subseteq G$ and $Y \subseteq G$ be graphs.</p>&#xA;&#xA;<p>Input: $X,Y$. Output: The relational composition <a href="http://en.wikipedia.org/wiki/Relation_composition">relational composition</a> $X \circ Y$ in $\mathcal{O}(|E||V|)$.</p>&#xA;&#xA;<ul>&#xA;<li>Case 1: $|E| \le |V|$. Two for loops over $E(X)$ and $E(Y)$: Runtime $ \le \mathcal{O}(|E|^2) \le \mathcal{O}(|E||V|)$.</li>&#xA;<li>Case 2: $|V| \le |E|$&#xA;<ol>&#xA;<li>Draw the graph $(V(G),E(X) \cup E(Y))$: $(O(|V|)+\mathcal{O}(|2E|)))$. We call edges from $E(X)$ black and from $E(Y)$ red.</li>&#xA;<li>Topologically sort it (Kahn: $\mathcal{O}(|V|) + \mathcal{O}(|E|)$). Let the first level be $0$, and edges go from a level to a higher level.</li>&#xA;<li>Draw this graph twice.</li>&#xA;<li>In the first copy, remove every red edge beginning at even level, and every black edge beginning at odd level: $\mathcal{O}(E)$.</li>&#xA;<li>In the second copy, remove every "black even" and "red odd": $\mathcal{O}(E)$.</li>&#xA;<li>For the first copy:&#xA;<ul>&#xA;<li>for all nodes $u$ on level $2i$</li>&#xA;<li>for all nodes $v$ on level $2i+1$</li>&#xA;<li>report edge $(u,v)$ (Runtime $\mathcal{O}(V^2) \le \mathcal{O}(EV)$).</li>&#xA;</ul></li>&#xA;<li>For the second copy: The same for "$2i+1$".</li>&#xA;<li>Union the reported nodes, throw out duplicates $\mathcal{O}(V^2) &lt;= \mathcal{O}(EV)$ (I hope the graph representation allows this).</li>&#xA;</ol></li>&#xA;</ul>&#xA;&#xA;<p>Could some of you please look over my algorithm and check whether </p>&#xA;&#xA;<ul>&#xA;<li>it is correct</li>&#xA;<li>it is in $\mathcal{O}(|E||V|)$</li>&#xA;</ul>&#xA;&#xA;<p>If it's correct, does my algorithm already "exist"? If not, could you provide an alternative? I'll accept the first answer, but upvote if some more people are so kind to check.</p>&#xA;&#xA;<p>EDIT: Step 6 Seems to be in $O(E^2)$ sometimes. I wish this would not be true. Has anyone a working algorithm?</p>&#xA;
algorithms graphs algorithm analysis check my algorithm
1
Compute relational composition in $O(|E||V|)$ -- (algorithms graphs algorithm analysis check my algorithm) <p>Definitions: Let $G=(V,E)$ be a DAG without self-loops, and $X \subseteq G$ and $Y \subseteq G$ be graphs.</p>&#xA;&#xA;<p>Input: $X,Y$. Output: The relational composition <a href="http://en.wikipedia.org/wiki/Relation_composition">relational composition</a> $X \circ Y$ in $\mathcal{O}(|E||V|)$.</p>&#xA;&#xA;<ul>&#xA;<li>Case 1: $|E| \le |V|$. Two for loops over $E(X)$ and $E(Y)$: Runtime $ \le \mathcal{O}(|E|^2) \le \mathcal{O}(|E||V|)$.</li>&#xA;<li>Case 2: $|V| \le |E|$&#xA;<ol>&#xA;<li>Draw the graph $(V(G),E(X) \cup E(Y))$: $(O(|V|)+\mathcal{O}(|2E|)))$. We call edges from $E(X)$ black and from $E(Y)$ red.</li>&#xA;<li>Topologically sort it (Kahn: $\mathcal{O}(|V|) + \mathcal{O}(|E|)$). Let the first level be $0$, and edges go from a level to a higher level.</li>&#xA;<li>Draw this graph twice.</li>&#xA;<li>In the first copy, remove every red edge beginning at even level, and every black edge beginning at odd level: $\mathcal{O}(E)$.</li>&#xA;<li>In the second copy, remove every "black even" and "red odd": $\mathcal{O}(E)$.</li>&#xA;<li>For the first copy:&#xA;<ul>&#xA;<li>for all nodes $u$ on level $2i$</li>&#xA;<li>for all nodes $v$ on level $2i+1$</li>&#xA;<li>report edge $(u,v)$ (Runtime $\mathcal{O}(V^2) \le \mathcal{O}(EV)$).</li>&#xA;</ul></li>&#xA;<li>For the second copy: The same for "$2i+1$".</li>&#xA;<li>Union the reported nodes, throw out duplicates $\mathcal{O}(V^2) &lt;= \mathcal{O}(EV)$ (I hope the graph representation allows this).</li>&#xA;</ol></li>&#xA;</ul>&#xA;&#xA;<p>Could some of you please look over my algorithm and check whether </p>&#xA;&#xA;<ul>&#xA;<li>it is correct</li>&#xA;<li>it is in $\mathcal{O}(|E||V|)$</li>&#xA;</ul>&#xA;&#xA;<p>If it's correct, does my algorithm already "exist"? If not, could you provide an alternative? I'll accept the first answer, but upvote if some more people are so kind to check.</p>&#xA;&#xA;<p>EDIT: Step 6 Seems to be in $O(E^2)$ sometimes. I wish this would not be true. Has anyone a working algorithm?</p>&#xA;
habedi/stack-exchange-dataset
6,058
How can lazy learning systems simultaneously solve multiple problems?
<p>On the english Wikipedia <a href="http://en.wikipedia.org/wiki/Lazy_learning" rel="nofollow">it says about lazy learning systems</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>Because the target function is approximated locally for each query to the system, lazy learning systems can simultaneously solve multiple problems […]</p>&#xA;</blockquote>&#xA;&#xA;<p>What does this mean? I can only guess what "approximated locally" is supposed to say but even then I have no idea how one is supposed to follow from the other.</p>&#xA;
terminology machine learning
1
How can lazy learning systems simultaneously solve multiple problems? -- (terminology machine learning) <p>On the english Wikipedia <a href="http://en.wikipedia.org/wiki/Lazy_learning" rel="nofollow">it says about lazy learning systems</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>Because the target function is approximated locally for each query to the system, lazy learning systems can simultaneously solve multiple problems […]</p>&#xA;</blockquote>&#xA;&#xA;<p>What does this mean? I can only guess what "approximated locally" is supposed to say but even then I have no idea how one is supposed to follow from the other.</p>&#xA;
habedi/stack-exchange-dataset
6,063
How to prove that DFAs from NFAs can have exponential number of states?
<p>All non-deterministic finite automata can be turned into equivalent deterministic finite automata. However, a deterministic finite automata only allows a single arrow per symbol pointing from a state. Therefore, its states should be members of the power set of states of the NFA. This seems to indicate that the number of states of the DFA could scale exponentially in terms of the number of states of the NFA. However, I was wondering how to actually prove this.</p>&#xA;
automata finite automata nondeterminism
1
How to prove that DFAs from NFAs can have exponential number of states? -- (automata finite automata nondeterminism) <p>All non-deterministic finite automata can be turned into equivalent deterministic finite automata. However, a deterministic finite automata only allows a single arrow per symbol pointing from a state. Therefore, its states should be members of the power set of states of the NFA. This seems to indicate that the number of states of the DFA could scale exponentially in terms of the number of states of the NFA. However, I was wondering how to actually prove this.</p>&#xA;
habedi/stack-exchange-dataset
6,067
What is the difference between operator and function?
<p>We have operator and operands, function and formal arguments. Is the difference purely lexical (we use alphanumerics for funciton identifiers but identify operators with special characters, e.g. "+" and ">=") or it is syntactical, like <a href="http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.vhdl/2012-10/msg00007.html" rel="nofollow">I guessed here</a></p>&#xA;&#xA;<pre><code>f(a,b) -- prefix notation used for functions&#xA;a.f(b) -- infix notation for method invocation (used in OOP)&#xA;a f b -- infix notation without dot and parenthesis used in operator invocations&#xA;</code></pre>&#xA;&#xA;<p>so that when we write <code>a + b</code> we have an operator but <code>"+"(a, b)</code> (both ways are acceptable in VHDL) makes it a function? Do tools treat them differently? Can you differentiate them? Can you say that this is not a function, it is an operator or vice-verse? When I read the definitions in wikipedia, I do not see that syntax is a distinguishing feature of a concept. So, is it right that operators and functions are synonyms, two different words for the same thing, same meaning, same notion? I have such guess but have never seen it stated explicitly. Please agree with my guess or say what is the difference.</p>&#xA;
terminology programming languages
1
What is the difference between operator and function? -- (terminology programming languages) <p>We have operator and operands, function and formal arguments. Is the difference purely lexical (we use alphanumerics for funciton identifiers but identify operators with special characters, e.g. "+" and ">=") or it is syntactical, like <a href="http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.vhdl/2012-10/msg00007.html" rel="nofollow">I guessed here</a></p>&#xA;&#xA;<pre><code>f(a,b) -- prefix notation used for functions&#xA;a.f(b) -- infix notation for method invocation (used in OOP)&#xA;a f b -- infix notation without dot and parenthesis used in operator invocations&#xA;</code></pre>&#xA;&#xA;<p>so that when we write <code>a + b</code> we have an operator but <code>"+"(a, b)</code> (both ways are acceptable in VHDL) makes it a function? Do tools treat them differently? Can you differentiate them? Can you say that this is not a function, it is an operator or vice-verse? When I read the definitions in wikipedia, I do not see that syntax is a distinguishing feature of a concept. So, is it right that operators and functions are synonyms, two different words for the same thing, same meaning, same notion? I have such guess but have never seen it stated explicitly. Please agree with my guess or say what is the difference.</p>&#xA;
habedi/stack-exchange-dataset
6,072
Why is Uniform cost search called "uniform" cost search?
<p>By <a href="https://math.stackexchange.com/questions/112734/in-what-sense-is-uniform-cost-search-uniform">this</a> possibly good attempt to explain this, the "uniformity" in the Uniform cost search <em>is actually the uniformity of the heuristic function</em>.</p>&#xA;&#xA;<p>Is this explanation correct ? If yes, then don't all <code>un-informed</code> cost searches (like <code>BFS</code>, <code>DFS</code>, etc) have no heurstic and thus, be called as "<code>uniform cost</code> searches" ?</p>&#xA;
terminology artificial intelligence search algorithms heuristics
1
Why is Uniform cost search called "uniform" cost search? -- (terminology artificial intelligence search algorithms heuristics) <p>By <a href="https://math.stackexchange.com/questions/112734/in-what-sense-is-uniform-cost-search-uniform">this</a> possibly good attempt to explain this, the "uniformity" in the Uniform cost search <em>is actually the uniformity of the heuristic function</em>.</p>&#xA;&#xA;<p>Is this explanation correct ? If yes, then don't all <code>un-informed</code> cost searches (like <code>BFS</code>, <code>DFS</code>, etc) have no heurstic and thus, be called as "<code>uniform cost</code> searches" ?</p>&#xA;
habedi/stack-exchange-dataset
6,075
How to prove $(n+1)! = O(2^{(2^n)})$
<p>I am trying to prove $(n+1)! = O(2^{(2^n)})$. I am trying to use L'Hospital rule but I am stuck with infinite derivatives.</p>&#xA;&#xA;<p>Can anyone tell me how i can prove this?</p>&#xA;
asymptotics mathematical analysis landau notation
1
How to prove $(n+1)! = O(2^{(2^n)})$ -- (asymptotics mathematical analysis landau notation) <p>I am trying to prove $(n+1)! = O(2^{(2^n)})$. I am trying to use L'Hospital rule but I am stuck with infinite derivatives.</p>&#xA;&#xA;<p>Can anyone tell me how i can prove this?</p>&#xA;
habedi/stack-exchange-dataset
6,078
A d-ary heap problem from CLRS
<p>I got confused while solving the following problem (questions 1–3).</p>&#xA;&#xA;<h3>Question</h3>&#xA;&#xA;<blockquote>&#xA; <p>A <em>d</em>-ary heap is like a binary heap, but(with one possible exception) non-leaf nodes have <em>d</em> children instead of 2 children.</p>&#xA; &#xA; <ol>&#xA; <li><p>How would you represent a <em>d</em>-ary heap in an array?</p></li>&#xA; <li><p>What is the height of a <em>d</em>-ary heap of <em>n</em> elements in terms of <em>n</em> and <em>d</em>?</p></li>&#xA; <li><p>Give an efficient implementation of EXTRACT-MAX in a <em>d</em>-ary max-heap. Analyze its running time in terms of <em>d</em> and <em>n</em>.</p></li>&#xA; <li><p><sub> Give an efficient implementation of INSERT in a <em>d</em>-ary max-heap. Analyze its running time in terms of <em>d</em> and <em>n</em>. </sub></p></li>&#xA; <li><p><sub> Give an efficient implementation of INCREASE-KEY(<em>A</em>, <em>i</em>, <em>k</em>), which flags an error if <em>k</em> &lt; A[i] = k and then updates the <em>d</em>-ary matrix heap structure appropriately. Analyze its running time in terms of <em>d</em> and <em>n</em>. </sub></p></li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<h3>My Solution</h3>&#xA;&#xA;<ol>&#xA;<li><p>Give an array $A[a_1 .. a_n]$</p>&#xA;&#xA;<p>$\qquad \begin{align}&#xA; \text{root} &amp;: a_1\\&#xA; \text{level 1} &amp;: a_{2} \dots a_{2+d-1}\\&#xA; \text{level 2} &amp;: a_{2+d} \dots a_{2+d+d^2-1}\\&#xA; &amp;\vdots\\&#xA; \text{level k} &amp;: a_{2+\sum\limits_{i=1}^{k-1}d^i} \dots a_{2+\sum\limits_{i=1}^{k}d^i-1}&#xA; \end{align}$</p>&#xA;&#xA;<p>→ <strong>My notation seems a bit sophisticated. Is there any other simpler one?</strong></p></li>&#xA;<li><p>Let <em>h</em> denotes the height of the <em>d</em>-ary heap.</p>&#xA;&#xA;<p>Suppose that the heap is a complete <em>d</em>-ary tree&#xA;$$&#xA; 1+d+d^2+..+d^h=n\\&#xA; \dfrac{d^{h+1}-1}{d-1}=n\\&#xA; h=log_d[n{d-1}+1] - 1&#xA; $$</p></li>&#xA;<li><p>This is my implementation:</p>&#xA;&#xA;<pre><code>EXTRACT-MAX(A)&#xA;1 if A.heapsize &lt; 1&#xA;2 error "heap underflow"&#xA;3 max = A[1]&#xA;4 A[1] = A[A.heapsize]&#xA;5 A.heap-size = A.heap-size - 1&#xA;6 MAX-HEAPIFY(A, 1)&#xA;7 return max&#xA;&#xA;MAX-HEAPIFY(A, i)&#xA;1 assign depthk-children to AUX[1..d]&#xA;2 for k=1 to d&#xA;3 compare A[i] with AUX[k]&#xA;4 if A[i] &lt;= AUX[k]&#xA;5 exchange A[i] with AUX[k]&#xA;6 k = largest&#xA;7 assign AUX[1..d] back to A[depthk-children]&#xA;8 if largest != i&#xA;9 MAX-HEAPIFY(A, (2+(1+d+d^2+..+d^{k-1})+(largest-1) )&#xA;</code></pre>&#xA;&#xA;<ul>&#xA;<li><p>The running time of MAX-HEAPIFY:</p>&#xA;&#xA;<p>$$T_M = d(c_8*d + (c_9+..+c_13)*d +c_14*d)$$&#xA;where $c_i$ denotes the cost of <em>i</em>-th line above.</p></li>&#xA;<li><p>EXTRACT-MAX:&#xA;$$&#xA; T_E = (c_1+..+c_7) + T_M \leq C*d*h\\&#xA; = C*d*(log_d[n(d-1)+1] - 1)\\&#xA; = O(dlog_d[n(d-1)])&#xA; $$</p></li>&#xA;</ul>&#xA;&#xA;<p>→ <strong>Is this an efficient solution? Or there is something wrong within my solution?</strong></p></li>&#xA;</ol>&#xA;
data structures time complexity runtime analysis
1
A d-ary heap problem from CLRS -- (data structures time complexity runtime analysis) <p>I got confused while solving the following problem (questions 1–3).</p>&#xA;&#xA;<h3>Question</h3>&#xA;&#xA;<blockquote>&#xA; <p>A <em>d</em>-ary heap is like a binary heap, but(with one possible exception) non-leaf nodes have <em>d</em> children instead of 2 children.</p>&#xA; &#xA; <ol>&#xA; <li><p>How would you represent a <em>d</em>-ary heap in an array?</p></li>&#xA; <li><p>What is the height of a <em>d</em>-ary heap of <em>n</em> elements in terms of <em>n</em> and <em>d</em>?</p></li>&#xA; <li><p>Give an efficient implementation of EXTRACT-MAX in a <em>d</em>-ary max-heap. Analyze its running time in terms of <em>d</em> and <em>n</em>.</p></li>&#xA; <li><p><sub> Give an efficient implementation of INSERT in a <em>d</em>-ary max-heap. Analyze its running time in terms of <em>d</em> and <em>n</em>. </sub></p></li>&#xA; <li><p><sub> Give an efficient implementation of INCREASE-KEY(<em>A</em>, <em>i</em>, <em>k</em>), which flags an error if <em>k</em> &lt; A[i] = k and then updates the <em>d</em>-ary matrix heap structure appropriately. Analyze its running time in terms of <em>d</em> and <em>n</em>. </sub></p></li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<h3>My Solution</h3>&#xA;&#xA;<ol>&#xA;<li><p>Give an array $A[a_1 .. a_n]$</p>&#xA;&#xA;<p>$\qquad \begin{align}&#xA; \text{root} &amp;: a_1\\&#xA; \text{level 1} &amp;: a_{2} \dots a_{2+d-1}\\&#xA; \text{level 2} &amp;: a_{2+d} \dots a_{2+d+d^2-1}\\&#xA; &amp;\vdots\\&#xA; \text{level k} &amp;: a_{2+\sum\limits_{i=1}^{k-1}d^i} \dots a_{2+\sum\limits_{i=1}^{k}d^i-1}&#xA; \end{align}$</p>&#xA;&#xA;<p>→ <strong>My notation seems a bit sophisticated. Is there any other simpler one?</strong></p></li>&#xA;<li><p>Let <em>h</em> denotes the height of the <em>d</em>-ary heap.</p>&#xA;&#xA;<p>Suppose that the heap is a complete <em>d</em>-ary tree&#xA;$$&#xA; 1+d+d^2+..+d^h=n\\&#xA; \dfrac{d^{h+1}-1}{d-1}=n\\&#xA; h=log_d[n{d-1}+1] - 1&#xA; $$</p></li>&#xA;<li><p>This is my implementation:</p>&#xA;&#xA;<pre><code>EXTRACT-MAX(A)&#xA;1 if A.heapsize &lt; 1&#xA;2 error "heap underflow"&#xA;3 max = A[1]&#xA;4 A[1] = A[A.heapsize]&#xA;5 A.heap-size = A.heap-size - 1&#xA;6 MAX-HEAPIFY(A, 1)&#xA;7 return max&#xA;&#xA;MAX-HEAPIFY(A, i)&#xA;1 assign depthk-children to AUX[1..d]&#xA;2 for k=1 to d&#xA;3 compare A[i] with AUX[k]&#xA;4 if A[i] &lt;= AUX[k]&#xA;5 exchange A[i] with AUX[k]&#xA;6 k = largest&#xA;7 assign AUX[1..d] back to A[depthk-children]&#xA;8 if largest != i&#xA;9 MAX-HEAPIFY(A, (2+(1+d+d^2+..+d^{k-1})+(largest-1) )&#xA;</code></pre>&#xA;&#xA;<ul>&#xA;<li><p>The running time of MAX-HEAPIFY:</p>&#xA;&#xA;<p>$$T_M = d(c_8*d + (c_9+..+c_13)*d +c_14*d)$$&#xA;where $c_i$ denotes the cost of <em>i</em>-th line above.</p></li>&#xA;<li><p>EXTRACT-MAX:&#xA;$$&#xA; T_E = (c_1+..+c_7) + T_M \leq C*d*h\\&#xA; = C*d*(log_d[n(d-1)+1] - 1)\\&#xA; = O(dlog_d[n(d-1)])&#xA; $$</p></li>&#xA;</ul>&#xA;&#xA;<p>→ <strong>Is this an efficient solution? Or there is something wrong within my solution?</strong></p></li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
6,085
Average number of comparisons to locate item in BST
<p>This is a GRE practice question. </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/dUavw.png" alt="BST n=8"></p>&#xA;&#xA;<p>If a node in the binary search tree above is to be located by binary tree search, what is the expected number of comparisons required to locate one of the items (nodes) in the tree chosen at random?</p>&#xA;&#xA;<p>(A) 1.75 </p>&#xA;&#xA;<p>(B) 2 </p>&#xA;&#xA;<p>(C) 2.75 </p>&#xA;&#xA;<p>(D) 3 </p>&#xA;&#xA;<p>(E) 3.25</p>&#xA;&#xA;<p>My answer was 3 because $n=8$ and $\lg(n)$ comparisons should be made, and $\lg(8) = 3$. But the correct answer is 2.75. Can someone explain the correct answer? Thanks!</p>&#xA;
algorithm analysis data structures binary trees search trees average case
1
Average number of comparisons to locate item in BST -- (algorithm analysis data structures binary trees search trees average case) <p>This is a GRE practice question. </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/dUavw.png" alt="BST n=8"></p>&#xA;&#xA;<p>If a node in the binary search tree above is to be located by binary tree search, what is the expected number of comparisons required to locate one of the items (nodes) in the tree chosen at random?</p>&#xA;&#xA;<p>(A) 1.75 </p>&#xA;&#xA;<p>(B) 2 </p>&#xA;&#xA;<p>(C) 2.75 </p>&#xA;&#xA;<p>(D) 3 </p>&#xA;&#xA;<p>(E) 3.25</p>&#xA;&#xA;<p>My answer was 3 because $n=8$ and $\lg(n)$ comparisons should be made, and $\lg(8) = 3$. But the correct answer is 2.75. Can someone explain the correct answer? Thanks!</p>&#xA;
habedi/stack-exchange-dataset
6,086
Which of the following regular expressions generate(s) no string with two consecutive 1’s?
<p>This is a GRE practice question. </p>&#xA;&#xA;<p>Which of the following regular expressions generate(s) no string with two consecutive 1’s? (Note that ε denotes the empty string.)</p>&#xA;&#xA;<p>I. (1 + ε)(01 + 0)* </p>&#xA;&#xA;<p>II. (01+10)*</p>&#xA;&#xA;<p>III. (0+1)*(0+ε)</p>&#xA;&#xA;<p>(A) I only</p>&#xA;&#xA;<p>(B) II only</p>&#xA;&#xA;<p>(C) III only</p>&#xA;&#xA;<p>(D) I and II only</p>&#xA;&#xA;<p>(E) II and III only</p>&#xA;&#xA;<p>My understanding is that neither I nor III generates strings with <code>11</code>. In I, a string containing <code>1</code> is either <code>1</code> or <code>1</code> surrounded by <code>0</code>'s. In III, all <code>1</code>'s are preceded by <code>0</code>'s. But the correct answer is A, so III must generate a string with <code>11</code> somehow. Please explain. Thanks!</p>&#xA;
regular expressions
1
Which of the following regular expressions generate(s) no string with two consecutive 1’s? -- (regular expressions) <p>This is a GRE practice question. </p>&#xA;&#xA;<p>Which of the following regular expressions generate(s) no string with two consecutive 1’s? (Note that ε denotes the empty string.)</p>&#xA;&#xA;<p>I. (1 + ε)(01 + 0)* </p>&#xA;&#xA;<p>II. (01+10)*</p>&#xA;&#xA;<p>III. (0+1)*(0+ε)</p>&#xA;&#xA;<p>(A) I only</p>&#xA;&#xA;<p>(B) II only</p>&#xA;&#xA;<p>(C) III only</p>&#xA;&#xA;<p>(D) I and II only</p>&#xA;&#xA;<p>(E) II and III only</p>&#xA;&#xA;<p>My understanding is that neither I nor III generates strings with <code>11</code>. In I, a string containing <code>1</code> is either <code>1</code> or <code>1</code> surrounded by <code>0</code>'s. In III, all <code>1</code>'s are preceded by <code>0</code>'s. But the correct answer is A, so III must generate a string with <code>11</code> somehow. Please explain. Thanks!</p>&#xA;
habedi/stack-exchange-dataset
6,088
Decidability of a problem concerning polynomials
<p>I have come across the following interesting problem: let $p,q$ be polynomials over the field of real numbers, and let us suppose that their coefficients are all integer (that is, there is a finite exact representation of these polynomials). If needed, we may suppose that the degree of both polynomials is equal. Let us denote by $x_p$ (resp. $x_q$) the greatest absolute value of some (real or complex) root of the polynomial $p$ (resp. $q$). Is the property $x_p = x_q$ decidable?</p>&#xA;&#xA;<p>If not, does this property hold for some restricted families of polynomials? In the context from which this problem arises, the polynomials are characteristic polynomials of matrices, and their roots are eigenvalues. </p>&#xA;&#xA;<p>I am aware of some numerical algorithms for computing roots of polynomials / eigenvalues, however these seem to be of no use here, since the output of these algorithms is only approximate. It seems to me that computer algebra might be useful here, however, unfortunately, I do not have almost any knowledge in that field.</p>&#xA;&#xA;<p>I am not searching for a detailed solution to this problem, however any intuition and ideas where to search for the solution would be helpful. </p>&#xA;&#xA;<p>Thank you in advance.</p>&#xA;
computability undecidability computer algebra
1
Decidability of a problem concerning polynomials -- (computability undecidability computer algebra) <p>I have come across the following interesting problem: let $p,q$ be polynomials over the field of real numbers, and let us suppose that their coefficients are all integer (that is, there is a finite exact representation of these polynomials). If needed, we may suppose that the degree of both polynomials is equal. Let us denote by $x_p$ (resp. $x_q$) the greatest absolute value of some (real or complex) root of the polynomial $p$ (resp. $q$). Is the property $x_p = x_q$ decidable?</p>&#xA;&#xA;<p>If not, does this property hold for some restricted families of polynomials? In the context from which this problem arises, the polynomials are characteristic polynomials of matrices, and their roots are eigenvalues. </p>&#xA;&#xA;<p>I am aware of some numerical algorithms for computing roots of polynomials / eigenvalues, however these seem to be of no use here, since the output of these algorithms is only approximate. It seems to me that computer algebra might be useful here, however, unfortunately, I do not have almost any knowledge in that field.</p>&#xA;&#xA;<p>I am not searching for a detailed solution to this problem, however any intuition and ideas where to search for the solution would be helpful. </p>&#xA;&#xA;<p>Thank you in advance.</p>&#xA;
habedi/stack-exchange-dataset
6,108
Are all context-sensitive languages decidable?
<p>I was going through the <a href="http://en.wikipedia.org/wiki/Context-sensitive_language">Wikipedia definition of <em>context-sensitive language</em></a> and I found this:</p>&#xA;&#xA;<blockquote>&#xA; <p>Each category of languages is a proper subset of the category directly above it. Any automaton and any grammar in each category has an equivalent automaton or grammar in the category directly above it.</p>&#xA;</blockquote>&#xA;&#xA;<p>I could see that linear-bounded automaton is directly below decider in the article's ordering. If this is the case, then that means every computation on a LBA will halt at some point (since every LBA would be a decider). But I feel that there may be some computation which can run on a LBA at the same time never to halt. For example we can write a computation on LBA which would</p>&#xA;&#xA;<ol>&#xA;<li>read the first symbol on the tape and move right;</li>&#xA;<li>read the next symbol and move back left.</li>&#xA;</ol>&#xA;&#xA;<p>This (useless) computation (which is obviously a LB computation) would run indefinitely oscillating left and right and never halt and hence cannot be a decider. Where am I thinking wrong?</p>&#xA;
formal grammars turing machines undecidability context sensitive
1
Are all context-sensitive languages decidable? -- (formal grammars turing machines undecidability context sensitive) <p>I was going through the <a href="http://en.wikipedia.org/wiki/Context-sensitive_language">Wikipedia definition of <em>context-sensitive language</em></a> and I found this:</p>&#xA;&#xA;<blockquote>&#xA; <p>Each category of languages is a proper subset of the category directly above it. Any automaton and any grammar in each category has an equivalent automaton or grammar in the category directly above it.</p>&#xA;</blockquote>&#xA;&#xA;<p>I could see that linear-bounded automaton is directly below decider in the article's ordering. If this is the case, then that means every computation on a LBA will halt at some point (since every LBA would be a decider). But I feel that there may be some computation which can run on a LBA at the same time never to halt. For example we can write a computation on LBA which would</p>&#xA;&#xA;<ol>&#xA;<li>read the first symbol on the tape and move right;</li>&#xA;<li>read the next symbol and move back left.</li>&#xA;</ol>&#xA;&#xA;<p>This (useless) computation (which is obviously a LB computation) would run indefinitely oscillating left and right and never halt and hence cannot be a decider. Where am I thinking wrong?</p>&#xA;
habedi/stack-exchange-dataset
6,111
How can I reduce Subset Sum to Partition?
<p>Maybe this is quite simple but I have some trouble to get this reduction. I want to reduce <a href="http://en.wikipedia.org/wiki/Subset_sum_problem">Subset Sum</a> to <a href="http://en.wikipedia.org/wiki/Partition_problem">Partition</a> but at this time I don't see the relation!</p>&#xA;&#xA;<p>Is it possible to reduce this problem using a Levin Reduction ?</p>&#xA;&#xA;<p>If you don't understand write for clarification!</p>&#xA;
complexity theory np complete reductions
1
How can I reduce Subset Sum to Partition? -- (complexity theory np complete reductions) <p>Maybe this is quite simple but I have some trouble to get this reduction. I want to reduce <a href="http://en.wikipedia.org/wiki/Subset_sum_problem">Subset Sum</a> to <a href="http://en.wikipedia.org/wiki/Partition_problem">Partition</a> but at this time I don't see the relation!</p>&#xA;&#xA;<p>Is it possible to reduce this problem using a Levin Reduction ?</p>&#xA;&#xA;<p>If you don't understand write for clarification!</p>&#xA;
habedi/stack-exchange-dataset
6,114
Represent string as concatenations
<p>If $S_1,S_2$ are set of strings, then $S_1S_2 = \{s_1s_2|s_1\in S_1, s_2\in S_2\}$. $S^0=\{\epsilon\}$, $\epsilon$ is the empty string. $S^n = S^{n-1}S$. </p>&#xA;&#xA;<p>Two related problems about represent string as concatenation of other strings. </p>&#xA;&#xA;<ol>&#xA;<li><p>Given a finite set $S$ of strings, how to decide if there exist a string can be written as concatenations of elements in $S$ in two different ways?</p></li>&#xA;<li><p>Given a finite set $S$ of strings and $n$, how can one compute the smallest set of strings $T$, such that $S\subset T^n$?</p></li>&#xA;</ol>&#xA;&#xA;<p>(Bonus: what about infinite $S$, at least when it's regular? For the second problem when $S$ is infinite, we might ask to find a minimal $T$ under set inclusion.)</p>&#xA;
algorithms formal languages strings
1
Represent string as concatenations -- (algorithms formal languages strings) <p>If $S_1,S_2$ are set of strings, then $S_1S_2 = \{s_1s_2|s_1\in S_1, s_2\in S_2\}$. $S^0=\{\epsilon\}$, $\epsilon$ is the empty string. $S^n = S^{n-1}S$. </p>&#xA;&#xA;<p>Two related problems about represent string as concatenation of other strings. </p>&#xA;&#xA;<ol>&#xA;<li><p>Given a finite set $S$ of strings, how to decide if there exist a string can be written as concatenations of elements in $S$ in two different ways?</p></li>&#xA;<li><p>Given a finite set $S$ of strings and $n$, how can one compute the smallest set of strings $T$, such that $S\subset T^n$?</p></li>&#xA;</ol>&#xA;&#xA;<p>(Bonus: what about infinite $S$, at least when it's regular? For the second problem when $S$ is infinite, we might ask to find a minimal $T$ under set inclusion.)</p>&#xA;
habedi/stack-exchange-dataset
6,115
What's a fast algorithm to decide whether there is an $A_G$ corresponding to a given $\chi_G(\lambda)$?
<p>Given an adjacency matrix <span class="math-container">$A_G$</span> of an undirected graph <span class="math-container">$G$</span>, it is easy and straightforward to compute the characteristic polynomial <span class="math-container">$\chi_G(\lambda)$</span>. What about the other way around? The problem can be formulated as follows.</p>&#xA;<blockquote>&#xA;<p><strong>Problem</strong> Given a polynomial <span class="math-container">$P$</span>, decide whether there is a graph <span class="math-container">$G$</span> with the corresponding adjacency matrix <span class="math-container">$A_G$</span> such that its characteristic polynomial <span class="math-container">$\chi_G(\lambda)$</span> equals the given <span class="math-container">$P$</span>.</p>&#xA;</blockquote>&#xA;<p>For an arbitrary <span class="math-container">$P$</span>, it is not always the case that there is a corresponding <span class="math-container">$A_G$</span>. The naive exhaustive algorithm for the problem uses a basic theorem in algebraic graph theory:</p>&#xA;<blockquote>&#xA;<p><strong>Theorem</strong> Let <span class="math-container">$G=(V,E)$</span> be a graph with adjacency matrix <span class="math-container">$A_G$</span> and <span class="math-container">$\chi_G(\lambda) = \lambda^n+c_1\lambda^{n-1}+c_2\lambda^{n-2}+\cdots+c_{n-1}\lambda+c_n$</span>, then</p>&#xA;<p><strong>(1)</strong> <span class="math-container">$c_1=0$</span>,</p>&#xA;<p><strong>(2)</strong> <span class="math-container">$-c_2 = |E|$</span>, and</p>&#xA;<p><strong>(3)</strong> <span class="math-container">$-c_3 = \text{twice the # of triangles in G}$</span>.</p>&#xA;</blockquote>&#xA;<p>Now, given <span class="math-container">$P$</span>, the algorithm goes through every candidate <span class="math-container">$A_G$</span> of a corresponding <span class="math-container">$G$</span> with <span class="math-container">$|E|=-c_2$</span> and number of triangles (<span class="math-container">$K_3$</span>) equal to <span class="math-container">$-c_3$</span>. For each <span class="math-container">$A_G$</span>, compute <span class="math-container">$\text{det}(A_G - \lambda I)$</span> and see if it equals the given <span class="math-container">$P$</span>. If none match, return false. Otherwise, return the <span class="math-container">$A_G$</span>.</p>&#xA;<p>This works, but is clearly not fast. The exhaustive algorithm would work even without the above theorem. Its use makes the search space smaller. What's a fast and more clever algorithm?</p>&#xA;
algorithms graphs discrete mathematics matrices
1
What's a fast algorithm to decide whether there is an $A_G$ corresponding to a given $\chi_G(\lambda)$? -- (algorithms graphs discrete mathematics matrices) <p>Given an adjacency matrix <span class="math-container">$A_G$</span> of an undirected graph <span class="math-container">$G$</span>, it is easy and straightforward to compute the characteristic polynomial <span class="math-container">$\chi_G(\lambda)$</span>. What about the other way around? The problem can be formulated as follows.</p>&#xA;<blockquote>&#xA;<p><strong>Problem</strong> Given a polynomial <span class="math-container">$P$</span>, decide whether there is a graph <span class="math-container">$G$</span> with the corresponding adjacency matrix <span class="math-container">$A_G$</span> such that its characteristic polynomial <span class="math-container">$\chi_G(\lambda)$</span> equals the given <span class="math-container">$P$</span>.</p>&#xA;</blockquote>&#xA;<p>For an arbitrary <span class="math-container">$P$</span>, it is not always the case that there is a corresponding <span class="math-container">$A_G$</span>. The naive exhaustive algorithm for the problem uses a basic theorem in algebraic graph theory:</p>&#xA;<blockquote>&#xA;<p><strong>Theorem</strong> Let <span class="math-container">$G=(V,E)$</span> be a graph with adjacency matrix <span class="math-container">$A_G$</span> and <span class="math-container">$\chi_G(\lambda) = \lambda^n+c_1\lambda^{n-1}+c_2\lambda^{n-2}+\cdots+c_{n-1}\lambda+c_n$</span>, then</p>&#xA;<p><strong>(1)</strong> <span class="math-container">$c_1=0$</span>,</p>&#xA;<p><strong>(2)</strong> <span class="math-container">$-c_2 = |E|$</span>, and</p>&#xA;<p><strong>(3)</strong> <span class="math-container">$-c_3 = \text{twice the # of triangles in G}$</span>.</p>&#xA;</blockquote>&#xA;<p>Now, given <span class="math-container">$P$</span>, the algorithm goes through every candidate <span class="math-container">$A_G$</span> of a corresponding <span class="math-container">$G$</span> with <span class="math-container">$|E|=-c_2$</span> and number of triangles (<span class="math-container">$K_3$</span>) equal to <span class="math-container">$-c_3$</span>. For each <span class="math-container">$A_G$</span>, compute <span class="math-container">$\text{det}(A_G - \lambda I)$</span> and see if it equals the given <span class="math-container">$P$</span>. If none match, return false. Otherwise, return the <span class="math-container">$A_G$</span>.</p>&#xA;<p>This works, but is clearly not fast. The exhaustive algorithm would work even without the above theorem. Its use makes the search space smaller. What's a fast and more clever algorithm?</p>&#xA;
habedi/stack-exchange-dataset
6,122
How to show that f(x) is primitive recursive?
<blockquote>&#xA; <p>Let </p>&#xA; &#xA; <p>$$f(x)=\begin{cases} x \quad \text{if Goldbach's conjecture is true&#xA; }\\ 0 \quad \text{otherwise}\end{cases}$$</p>&#xA; &#xA; <p>Show that f(x) is primitive recursive.</p>&#xA;</blockquote>&#xA;&#xA;<p>I know a primitive recursive function is obtained by composition or recursion, but I don't know what should I do about this problem. </p>&#xA;
computability recursion
1
How to show that f(x) is primitive recursive? -- (computability recursion) <blockquote>&#xA; <p>Let </p>&#xA; &#xA; <p>$$f(x)=\begin{cases} x \quad \text{if Goldbach's conjecture is true&#xA; }\\ 0 \quad \text{otherwise}\end{cases}$$</p>&#xA; &#xA; <p>Show that f(x) is primitive recursive.</p>&#xA;</blockquote>&#xA;&#xA;<p>I know a primitive recursive function is obtained by composition or recursion, but I don't know what should I do about this problem. </p>&#xA;
habedi/stack-exchange-dataset
6,125
When would best first search be worse than breadth first search?
<p>I am studying <a href="http://en.wikipedia.org/wiki/Best-first_search" rel="noreferrer">best first search</a> as it compares to BFS (breadth-first search) and DFS (depth-first search), but I don't know when BFS is better than best-first search. So, my question is </p>&#xA;&#xA;<blockquote>&#xA; <p>When would best-first search be worse than breadth-first search?</p>&#xA;</blockquote>&#xA;&#xA;<p>This question is one of the back exercises in <em>Artificial Intelligence</em> by Rich &amp; Knight, and it asks for an answer in terms of time &amp; space complexity and allows you to define any heuristic function.</p>&#xA;
graphs artificial intelligence search algorithms
1
When would best first search be worse than breadth first search? -- (graphs artificial intelligence search algorithms) <p>I am studying <a href="http://en.wikipedia.org/wiki/Best-first_search" rel="noreferrer">best first search</a> as it compares to BFS (breadth-first search) and DFS (depth-first search), but I don't know when BFS is better than best-first search. So, my question is </p>&#xA;&#xA;<blockquote>&#xA; <p>When would best-first search be worse than breadth-first search?</p>&#xA;</blockquote>&#xA;&#xA;<p>This question is one of the back exercises in <em>Artificial Intelligence</em> by Rich &amp; Knight, and it asks for an answer in terms of time &amp; space complexity and allows you to define any heuristic function.</p>&#xA;
habedi/stack-exchange-dataset
6,128
Complement of HAMPATH
<p>Is the complement of the <a href="http://en.wikipedia.org/wiki/Hamiltonian_path" rel="nofollow">Hamiltonian Path problem</a> known to be in $\mathsf{NP}$? I could not find explanations saying that it is, but then neither were there any claims saying that it is <strong>not</strong> in $\mathsf{NP}$.</p>&#xA;
complexity theory decision problem
1
Complement of HAMPATH -- (complexity theory decision problem) <p>Is the complement of the <a href="http://en.wikipedia.org/wiki/Hamiltonian_path" rel="nofollow">Hamiltonian Path problem</a> known to be in $\mathsf{NP}$? I could not find explanations saying that it is, but then neither were there any claims saying that it is <strong>not</strong> in $\mathsf{NP}$.</p>&#xA;
habedi/stack-exchange-dataset
6,138
Problem with implementing Brzozowski's algorithm
<p>I've been trying to implement Brzozowski's algorithm but I've just discovered that it creates suboptimal automata for a certain class of inputs, having one more state than what is really needed in the result. I can show it on a trivial automaton:</p>&#xA;&#xA;<pre><code> a b a b a b a b a b&#xA;&gt;0 0 1 rev *0 0,2 - det &gt;0 - 1 rev *0 - - det &gt;0 1 2&#xA; 1 1 2 --&gt; 1 1 0 --&gt; 1 2 5 --&gt; 1 - 0,4 --&gt; 1 1 2&#xA;*2 0 2 &gt;2 - 1,2 2 2 3 2 1,2 - 2 2 3&#xA; *3 4 - 3 - 2 *3 1 3&#xA; *4 4 1 4 3,4 - &#xA; *5 5 5 5 5 1,5 &#xA; &gt;6 3,4,5 1,2,5 &#xA;</code></pre>&#xA;&#xA;<p>Here <em>rev</em> is the edge reversal part, where I'd already removed the transitions on epsilon, and <em>det</em> is determinization through powerset construction, creating new states as soon as it discovers them, recursively.</p>&#xA;&#xA;<p>The problem here is this: once I add the extra state to make up for the three different start states after the first edge reversal and powerset construction, nothing ever returns to that state and thus I can't get rid of it later for being equivalent to the original start state.</p>&#xA;&#xA;<p>Is there something wrong with the way I'm doing it? Am I missing something?</p>&#xA;
algorithms automata finite automata
1
Problem with implementing Brzozowski's algorithm -- (algorithms automata finite automata) <p>I've been trying to implement Brzozowski's algorithm but I've just discovered that it creates suboptimal automata for a certain class of inputs, having one more state than what is really needed in the result. I can show it on a trivial automaton:</p>&#xA;&#xA;<pre><code> a b a b a b a b a b&#xA;&gt;0 0 1 rev *0 0,2 - det &gt;0 - 1 rev *0 - - det &gt;0 1 2&#xA; 1 1 2 --&gt; 1 1 0 --&gt; 1 2 5 --&gt; 1 - 0,4 --&gt; 1 1 2&#xA;*2 0 2 &gt;2 - 1,2 2 2 3 2 1,2 - 2 2 3&#xA; *3 4 - 3 - 2 *3 1 3&#xA; *4 4 1 4 3,4 - &#xA; *5 5 5 5 5 1,5 &#xA; &gt;6 3,4,5 1,2,5 &#xA;</code></pre>&#xA;&#xA;<p>Here <em>rev</em> is the edge reversal part, where I'd already removed the transitions on epsilon, and <em>det</em> is determinization through powerset construction, creating new states as soon as it discovers them, recursively.</p>&#xA;&#xA;<p>The problem here is this: once I add the extra state to make up for the three different start states after the first edge reversal and powerset construction, nothing ever returns to that state and thus I can't get rid of it later for being equivalent to the original start state.</p>&#xA;&#xA;<p>Is there something wrong with the way I'm doing it? Am I missing something?</p>&#xA;
habedi/stack-exchange-dataset
6,139
Universality of NOT and CNOT
<p>I'm trying to figure out why NOT and CNOT gates are not sufficient to create all bijective functions in classical circuits. I have been struggling on this for hours, and just can't make sense of it.</p>&#xA;&#xA;<p>I feel it has something to do with the Toffoli gate, as it contains an (implicit) AND operation, and I feel that's what missing in the NOT and CNOT gates. However I can't find a proper way to actually 'show' this.</p>&#xA;
logic circuits
1
Universality of NOT and CNOT -- (logic circuits) <p>I'm trying to figure out why NOT and CNOT gates are not sufficient to create all bijective functions in classical circuits. I have been struggling on this for hours, and just can't make sense of it.</p>&#xA;&#xA;<p>I feel it has something to do with the Toffoli gate, as it contains an (implicit) AND operation, and I feel that's what missing in the NOT and CNOT gates. However I can't find a proper way to actually 'show' this.</p>&#xA;
habedi/stack-exchange-dataset
6,144
Rigorous proof against pseudo random function
<p>I have the following problem:</p>&#xA;&#xA;<p>Define the keyed function F as follows: On input k ∈ {0, 1}$^n$&#xA;and x ∈ {0, 1}$^n$ , Fk(x) = k ⊕ x.Rigorously prove that F is not a pseudorandom function.</p>&#xA;&#xA;<p>How do I approach a proof against pseudorandomness for a keyed function? I don't know where to start with this one.</p>&#xA;
proof techniques cryptography
1
Rigorous proof against pseudo random function -- (proof techniques cryptography) <p>I have the following problem:</p>&#xA;&#xA;<p>Define the keyed function F as follows: On input k ∈ {0, 1}$^n$&#xA;and x ∈ {0, 1}$^n$ , Fk(x) = k ⊕ x.Rigorously prove that F is not a pseudorandom function.</p>&#xA;&#xA;<p>How do I approach a proof against pseudorandomness for a keyed function? I don't know where to start with this one.</p>&#xA;
habedi/stack-exchange-dataset
6,146
Lower bounds: queues that return their min elements in $O(1)$ time
<p>First, consider this simple problem --- design a data structure of <em>comparable</em> elements that behaves just like a stack (in particular, push(), pop() and top() take constant time), but can also return its min value in $O(1)$ time, without removing it from the stack. This is easy by maintaining a second stack of min values.</p>&#xA;&#xA;<p>Now, consider the same problem, where the stack is replaced by a queue. This seems impossible because one would need to keep track of $\Theta(n^2)$ values (min values between elements $i$ and $j$ in the queue). True or false ?</p>&#xA;&#xA;<p>Update: $O(1)$ amortized time is quite straightforward as explained in one of the answers (using two min-stacks). A colleague pointed out to me that one can de-amortize such data structures by performing maintenance operations proactively. This is a little tricky, but seems to work.</p>&#xA;
data structures priority queues lower bounds
1
Lower bounds: queues that return their min elements in $O(1)$ time -- (data structures priority queues lower bounds) <p>First, consider this simple problem --- design a data structure of <em>comparable</em> elements that behaves just like a stack (in particular, push(), pop() and top() take constant time), but can also return its min value in $O(1)$ time, without removing it from the stack. This is easy by maintaining a second stack of min values.</p>&#xA;&#xA;<p>Now, consider the same problem, where the stack is replaced by a queue. This seems impossible because one would need to keep track of $\Theta(n^2)$ values (min values between elements $i$ and $j$ in the queue). True or false ?</p>&#xA;&#xA;<p>Update: $O(1)$ amortized time is quite straightforward as explained in one of the answers (using two min-stacks). A colleague pointed out to me that one can de-amortize such data structures by performing maintenance operations proactively. This is a little tricky, but seems to work.</p>&#xA;
habedi/stack-exchange-dataset
6,150
Designing context free grammar for a language with range restriction on repetition of alphabets
<p>I am having issue with designing contex free grammar for the following language:</p>&#xA;&#xA;<p>$L = \{0^n 1^m \, | \, 2n \leq m \leq 3n \}$ </p>&#xA;&#xA;<p>I can design for the individual cases i.e. for $m \geq 2n$ and $m \leq 3n$ but don't know how should i combine both. Or is it a different approach altogether?</p>&#xA;
context free
1
Designing context free grammar for a language with range restriction on repetition of alphabets -- (context free) <p>I am having issue with designing contex free grammar for the following language:</p>&#xA;&#xA;<p>$L = \{0^n 1^m \, | \, 2n \leq m \leq 3n \}$ </p>&#xA;&#xA;<p>I can design for the individual cases i.e. for $m \geq 2n$ and $m \leq 3n$ but don't know how should i combine both. Or is it a different approach altogether?</p>&#xA;
habedi/stack-exchange-dataset
6,154
Given the phrase "Where NONE of the following are TRUE" and two statements how should a boolean logic be composed?
<p>Let's have two statements</p>&#xA;&#xA;<ol>&#xA;<li><strong>(value > 10)</strong></li>&#xA;<li><strong>(value &lt; 25)</strong></li>&#xA;</ol>&#xA;&#xA;<p>And a list of items with the following values</p>&#xA;&#xA;<ul>&#xA;<li>10</li>&#xA;<li>20</li>&#xA;<li>30</li>&#xA;</ul>&#xA;&#xA;<p>This is what a truth table would give</p>&#xA;&#xA;<pre><code>Item Value (value &gt; 10) (value &lt; 25)&#xA;---- ----- ------------ ------------&#xA;1 10 FALSE TRUE&#xA;2 20 TRUE TRUE&#xA;3 30 TRUE FALSE&#xA;</code></pre>&#xA;&#xA;<h2>Example 1</h2>&#xA;&#xA;<pre><code>Where ALL of the following are TRUE&#xA; value &gt; 10&#xA; value &lt; 25&#xA;</code></pre>&#xA;&#xA;<p>This one is easy and we get the following</p>&#xA;&#xA;<pre><code>Where (value &gt; 10) AND (value &lt; 25)&#xA;</code></pre>&#xA;&#xA;<p>The result is then a single value of 20</p>&#xA;&#xA;<h2>Example 2</h2>&#xA;&#xA;<pre><code>Where NONE of the following are TRUE&#xA; value &gt; 10&#xA; value &lt; 25&#xA;</code></pre>&#xA;&#xA;<p>This is where I am not sure of what to generate.</p>&#xA;&#xA;<p>This would be "simple" as it is only a NOT of the whole expression</p>&#xA;&#xA;<pre><code>Where NOT ((value &gt; 10) AND (value &lt; 25))&#xA;</code></pre>&#xA;&#xA;<p>However, the result is then two values (10 and 30)</p>&#xA;&#xA;<p>From what someone would think of NONE of the two statements would be something like:</p>&#xA;&#xA;<pre><code>Where NOT ((value &gt; 10) OR (value &lt; 25))&#xA;</code></pre>&#xA;&#xA;<p>And the result would be that no items are produced.</p>&#xA;&#xA;<p>What is the correct meaning of NONE here?</p>&#xA;
logic
1
Given the phrase "Where NONE of the following are TRUE" and two statements how should a boolean logic be composed? -- (logic) <p>Let's have two statements</p>&#xA;&#xA;<ol>&#xA;<li><strong>(value > 10)</strong></li>&#xA;<li><strong>(value &lt; 25)</strong></li>&#xA;</ol>&#xA;&#xA;<p>And a list of items with the following values</p>&#xA;&#xA;<ul>&#xA;<li>10</li>&#xA;<li>20</li>&#xA;<li>30</li>&#xA;</ul>&#xA;&#xA;<p>This is what a truth table would give</p>&#xA;&#xA;<pre><code>Item Value (value &gt; 10) (value &lt; 25)&#xA;---- ----- ------------ ------------&#xA;1 10 FALSE TRUE&#xA;2 20 TRUE TRUE&#xA;3 30 TRUE FALSE&#xA;</code></pre>&#xA;&#xA;<h2>Example 1</h2>&#xA;&#xA;<pre><code>Where ALL of the following are TRUE&#xA; value &gt; 10&#xA; value &lt; 25&#xA;</code></pre>&#xA;&#xA;<p>This one is easy and we get the following</p>&#xA;&#xA;<pre><code>Where (value &gt; 10) AND (value &lt; 25)&#xA;</code></pre>&#xA;&#xA;<p>The result is then a single value of 20</p>&#xA;&#xA;<h2>Example 2</h2>&#xA;&#xA;<pre><code>Where NONE of the following are TRUE&#xA; value &gt; 10&#xA; value &lt; 25&#xA;</code></pre>&#xA;&#xA;<p>This is where I am not sure of what to generate.</p>&#xA;&#xA;<p>This would be "simple" as it is only a NOT of the whole expression</p>&#xA;&#xA;<pre><code>Where NOT ((value &gt; 10) AND (value &lt; 25))&#xA;</code></pre>&#xA;&#xA;<p>However, the result is then two values (10 and 30)</p>&#xA;&#xA;<p>From what someone would think of NONE of the two statements would be something like:</p>&#xA;&#xA;<pre><code>Where NOT ((value &gt; 10) OR (value &lt; 25))&#xA;</code></pre>&#xA;&#xA;<p>And the result would be that no items are produced.</p>&#xA;&#xA;<p>What is the correct meaning of NONE here?</p>&#xA;
habedi/stack-exchange-dataset
6,161
What is the depth of a complete binary tree with $N$ nodes?
<p>This question uses the following definition of a complete binary tree<sup>†</sup>:</p>&#xA;&#xA;<blockquote>&#xA; <p>A binary tree $T$ with $N$ levels is complete if all levels except possibly the last are completely full, and the last level has all its nodes to the left side.</p>&#xA;</blockquote>&#xA;&#xA;<p>The following is an excerpt from <em><a href="http://www.amazon.ca/Algorithms-Sanjoy-Dasgupta/dp/0073523402" rel="noreferrer">Algorithms</a></em>:</p>&#xA;&#xA;<blockquote>&#xA; <p>It ($\log N$) is also the depth of a complete binary tree with $N$ nodes. (More precisely: $⌊\log N⌋$.)</p>&#xA;</blockquote>&#xA;&#xA;<p>Why is the above excerpt true?</p>&#xA;&#xA;<p><sup>†</sup> Originally defined <a href="http://courses.cs.vt.edu/~cs3114/Summer11/Notes/T03a.BinaryTreeTheorems.pdf" rel="noreferrer">here</a> </p>&#xA;
data structures binary trees
1
What is the depth of a complete binary tree with $N$ nodes? -- (data structures binary trees) <p>This question uses the following definition of a complete binary tree<sup>†</sup>:</p>&#xA;&#xA;<blockquote>&#xA; <p>A binary tree $T$ with $N$ levels is complete if all levels except possibly the last are completely full, and the last level has all its nodes to the left side.</p>&#xA;</blockquote>&#xA;&#xA;<p>The following is an excerpt from <em><a href="http://www.amazon.ca/Algorithms-Sanjoy-Dasgupta/dp/0073523402" rel="noreferrer">Algorithms</a></em>:</p>&#xA;&#xA;<blockquote>&#xA; <p>It ($\log N$) is also the depth of a complete binary tree with $N$ nodes. (More precisely: $⌊\log N⌋$.)</p>&#xA;</blockquote>&#xA;&#xA;<p>Why is the above excerpt true?</p>&#xA;&#xA;<p><sup>†</sup> Originally defined <a href="http://courses.cs.vt.edu/~cs3114/Summer11/Notes/T03a.BinaryTreeTheorems.pdf" rel="noreferrer">here</a> </p>&#xA;
habedi/stack-exchange-dataset
6,163
A context-free grammar for all strings that end in b and have an even number of bs
<p>I'm trying to find CFG's that generate a regular language over the alphabet {a b}</p>&#xA;&#xA;<p>I believe I got this one right: All strings that end in b and have an <strong>even</strong> number of b's in total:</p>&#xA;&#xA;<p>$\qquad S \to SS \\&#xA;\qquad S \to YbYb \mid \varepsilon \\&#xA;\qquad Y \to aY \mid \varepsilon$</p>&#xA;&#xA;<p>However, Im not sure how to accomplish this with an odd number of <em>b</em>'s.</p>&#xA;&#xA;<p>So for example, how could I find a CFG that generates all strings that end in b and have an <strong>odd</strong> number of b's in total: So far I have this,</p>&#xA;&#xA;<p>$\qquad S \to SS \\&#xA; \qquad S \to YYb \mid \varepsilon \\&#xA; \qquad Y \to abY \mid baY \mid \varepsilon$</p>&#xA;&#xA;<p>But this can generate abababb so it's incorrect and Im stumped at this point. </p>&#xA;
regular languages formal grammars context free
1
A context-free grammar for all strings that end in b and have an even number of bs -- (regular languages formal grammars context free) <p>I'm trying to find CFG's that generate a regular language over the alphabet {a b}</p>&#xA;&#xA;<p>I believe I got this one right: All strings that end in b and have an <strong>even</strong> number of b's in total:</p>&#xA;&#xA;<p>$\qquad S \to SS \\&#xA;\qquad S \to YbYb \mid \varepsilon \\&#xA;\qquad Y \to aY \mid \varepsilon$</p>&#xA;&#xA;<p>However, Im not sure how to accomplish this with an odd number of <em>b</em>'s.</p>&#xA;&#xA;<p>So for example, how could I find a CFG that generates all strings that end in b and have an <strong>odd</strong> number of b's in total: So far I have this,</p>&#xA;&#xA;<p>$\qquad S \to SS \\&#xA; \qquad S \to YYb \mid \varepsilon \\&#xA; \qquad Y \to abY \mid baY \mid \varepsilon$</p>&#xA;&#xA;<p>But this can generate abababb so it's incorrect and Im stumped at this point. </p>&#xA;
habedi/stack-exchange-dataset
6,167
If a Language is Non-Recognizable then what about its complement?
<p>Is the complement of a Non-Recognizable language</p>&#xA;&#xA;<ol>&#xA;<li>Recognizable</li>&#xA;<li>Non-Recognizable</li>&#xA;<li>May be Recognizable, May be Non-recognizable. I.e cant comment.</li>&#xA;</ol>&#xA;&#xA;<p>A mathematical proof would be of great help since im unable to think of any way to prove this.</p>&#xA;&#xA;<p>I did some research on this and found below examples. Im specifying complement using a "!"</p>&#xA;&#xA;<ol>&#xA;<li>!A(TM) is a non-recognizable language while A(TM) is a recognizable language.</li>&#xA;<li>EQ(TM) is a non-recognizable language and !EQ(TM) is also non-recognizable language</li>&#xA;</ol>&#xA;&#xA;<p>The above two would mean that we simply cant comment on the Recognizability of the complement of non-recognizable language. But I feel that there should be some way to prove (or disprove) this.</p>&#xA;
computability turing machines
1
If a Language is Non-Recognizable then what about its complement? -- (computability turing machines) <p>Is the complement of a Non-Recognizable language</p>&#xA;&#xA;<ol>&#xA;<li>Recognizable</li>&#xA;<li>Non-Recognizable</li>&#xA;<li>May be Recognizable, May be Non-recognizable. I.e cant comment.</li>&#xA;</ol>&#xA;&#xA;<p>A mathematical proof would be of great help since im unable to think of any way to prove this.</p>&#xA;&#xA;<p>I did some research on this and found below examples. Im specifying complement using a "!"</p>&#xA;&#xA;<ol>&#xA;<li>!A(TM) is a non-recognizable language while A(TM) is a recognizable language.</li>&#xA;<li>EQ(TM) is a non-recognizable language and !EQ(TM) is also non-recognizable language</li>&#xA;</ol>&#xA;&#xA;<p>The above two would mean that we simply cant comment on the Recognizability of the complement of non-recognizable language. But I feel that there should be some way to prove (or disprove) this.</p>&#xA;
habedi/stack-exchange-dataset
6,176
Finding big O notation of function with two parameters
<p>I'm looking to work out the big-O notation for the following:</p>&#xA;&#xA;<p>$$\frac{n^{s + 1} - 1}{n - 1} - 1$$</p>&#xA;&#xA;<p>I have a feeling the result is $O\left( n^s \right)$ but I'm not sure how to prove it.</p>&#xA;&#xA;<p>Any help greatly appreciated! :)</p>&#xA;
time complexity
1
Finding big O notation of function with two parameters -- (time complexity) <p>I'm looking to work out the big-O notation for the following:</p>&#xA;&#xA;<p>$$\frac{n^{s + 1} - 1}{n - 1} - 1$$</p>&#xA;&#xA;<p>I have a feeling the result is $O\left( n^s \right)$ but I'm not sure how to prove it.</p>&#xA;&#xA;<p>Any help greatly appreciated! :)</p>&#xA;
habedi/stack-exchange-dataset
6,187
Program compilation and execution flow
<p>I was studying operating system concepts from <a href="http://rads.stackoverflow.com/amzn/click/0471417432" rel="nofollow noreferrer">Silberschatz, Galvin and Gagne's book</a> (sixth edition) and I have some questions about the flow of execution of a program. A figure explains the processing of the user program:</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/we3Si.jpg" alt="program flow diagram"></p>&#xA;&#xA;<p>We get an executable binary file when we reach the <strong>linkage editor</strong> point. As the book says,</p>&#xA;&#xA;<blockquote>&#xA; <p>The program must be brought into memory and placed within a process for it to be executed.</p>&#xA;</blockquote>&#xA;&#xA;<p>I have several questions about this flow:</p>&#xA;&#xA;<ol>&#xA;<li><p>Before the program is loaded into the memory, the binary executable file generated by the linkage editor is stored in the hard disk. The address where the binary executable file is stored in the hard disk is the logical address as generated by the CPU ? </p></li>&#xA;<li><p>If the previous answer is yes, Why CPU has to generate the logical address ? I mean the executable file is stored somewhere in the hard disk which pertains to an address, why does CPU has to separately do the stuff ? CPU's main aim is processing after all! </p></li>&#xA;<li><p>Why does the executable file needs to be in the physical memory i.e ram and can not be executed in the hard disk? Is it due to speed issues ?</p></li>&#xA;</ol>&#xA;
compilers operating systems memory management virtual memory
1
Program compilation and execution flow -- (compilers operating systems memory management virtual memory) <p>I was studying operating system concepts from <a href="http://rads.stackoverflow.com/amzn/click/0471417432" rel="nofollow noreferrer">Silberschatz, Galvin and Gagne's book</a> (sixth edition) and I have some questions about the flow of execution of a program. A figure explains the processing of the user program:</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/we3Si.jpg" alt="program flow diagram"></p>&#xA;&#xA;<p>We get an executable binary file when we reach the <strong>linkage editor</strong> point. As the book says,</p>&#xA;&#xA;<blockquote>&#xA; <p>The program must be brought into memory and placed within a process for it to be executed.</p>&#xA;</blockquote>&#xA;&#xA;<p>I have several questions about this flow:</p>&#xA;&#xA;<ol>&#xA;<li><p>Before the program is loaded into the memory, the binary executable file generated by the linkage editor is stored in the hard disk. The address where the binary executable file is stored in the hard disk is the logical address as generated by the CPU ? </p></li>&#xA;<li><p>If the previous answer is yes, Why CPU has to generate the logical address ? I mean the executable file is stored somewhere in the hard disk which pertains to an address, why does CPU has to separately do the stuff ? CPU's main aim is processing after all! </p></li>&#xA;<li><p>Why does the executable file needs to be in the physical memory i.e ram and can not be executed in the hard disk? Is it due to speed issues ?</p></li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
6,192
Explanation of recursive structure of Van Emde Boas Tree
<p>From <a href="http://fileadmin.cs.lth.se/cs/Personal/Rolf_Karlsson/lect12.pdf" rel="nofollow">Van Emde Boas trees lecture</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>We will use the idea of superimposing a tree of degree ${u^{1/2}}$ on top of&#xA; a bit vector, but <strong>shrink the universe size recursively</strong> by a square&#xA; root at each tree level. The ${u^{1/2}}$ items on the first level each hold&#xA; structures of ${u^{1/4}}$ items, which hold structures of ${u^{1/8}}$ items, and&#xA; so on, down to size 2.&#xA; I have a question regarding van Emde Boas trees :</p>&#xA;</blockquote>&#xA;&#xA;<ol>&#xA;<li>How is the universe size getting reduced ? Aren't we just spreading the universe keys which is always constant at $u$ to different levels ? I can not understand the idea of "<strong>shriniking</strong>" the universe size . I find similar language is used in defining the recursive structure for Van Emde Boas tree in <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/" rel="nofollow">Introduction to Algorithms</a> by CLRS also .</li>&#xA;</ol>&#xA;
algorithms data structures algorithm analysis search trees trees
1
Explanation of recursive structure of Van Emde Boas Tree -- (algorithms data structures algorithm analysis search trees trees) <p>From <a href="http://fileadmin.cs.lth.se/cs/Personal/Rolf_Karlsson/lect12.pdf" rel="nofollow">Van Emde Boas trees lecture</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>We will use the idea of superimposing a tree of degree ${u^{1/2}}$ on top of&#xA; a bit vector, but <strong>shrink the universe size recursively</strong> by a square&#xA; root at each tree level. The ${u^{1/2}}$ items on the first level each hold&#xA; structures of ${u^{1/4}}$ items, which hold structures of ${u^{1/8}}$ items, and&#xA; so on, down to size 2.&#xA; I have a question regarding van Emde Boas trees :</p>&#xA;</blockquote>&#xA;&#xA;<ol>&#xA;<li>How is the universe size getting reduced ? Aren't we just spreading the universe keys which is always constant at $u$ to different levels ? I can not understand the idea of "<strong>shriniking</strong>" the universe size . I find similar language is used in defining the recursive structure for Van Emde Boas tree in <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/" rel="nofollow">Introduction to Algorithms</a> by CLRS also .</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
6,193
Size of the universe for van Emde Boas Trees
<p>In order to achieve the time complexity of $O(\log \log u)$ for van Emde Boas trees I read in <a href="http://fileadmin.cs.lth.se/cs/Personal/Rolf_Karlsson/lect12.pdf" rel="nofollow">this lecture</a> that the the universe size $u$ is chosen as $u = 2^{2^k}$ for some integer $k$ for van Emde Boas trees. Why choose $u$ to be of this specific form ?</p>&#xA;
algorithms data structures algorithm analysis binary trees trees
1
Size of the universe for van Emde Boas Trees -- (algorithms data structures algorithm analysis binary trees trees) <p>In order to achieve the time complexity of $O(\log \log u)$ for van Emde Boas trees I read in <a href="http://fileadmin.cs.lth.se/cs/Personal/Rolf_Karlsson/lect12.pdf" rel="nofollow">this lecture</a> that the the universe size $u$ is chosen as $u = 2^{2^k}$ for some integer $k$ for van Emde Boas trees. Why choose $u$ to be of this specific form ?</p>&#xA;
habedi/stack-exchange-dataset
6,200
Using Amdahl's law how do you determine execution time after an improvement?
<p>Speeding up a new floating-point unit by 2 slows down data cache accesses by a factor of 2/3 (or a 1.5 slowdown for data caches). If old FP unit took 20% of program's execution time and data cache accesses took 10% of program's execution time, what is the overall speed up? </p>&#xA;&#xA;<p>I solved this problem using amdahl's law: </p>&#xA;&#xA;<p>FeFP = floating point enhanced fraction = .2</p>&#xA;&#xA;<p>FeDC = data cache access enhanced fraction = .1</p>&#xA;&#xA;<p>SeFP = floating point enhanced speedup = 2</p>&#xA;&#xA;<p>SeDC = data cache access enhanced speedup = 2/3</p>&#xA;&#xA;<p>Speedup overall = 1 / ( (1 - FeFP - FeDC) + FeFP/SeFP + FeDC * SeDC )</p>&#xA;&#xA;<p>= 1 / ( ( 1 - .2 - .1 ) + .2/2 + (.1) * (2/3) )&#xA; = 1.154. </p>&#xA;&#xA;<p>I hope I did this correctly, but I'm confused about the next part asking what percentage of execution time is spent on floating point operations after implementing the new FP unit? </p>&#xA;&#xA;<p>I know that T[improved ] = T[affected] / improvement factor + T[unaffected]</p>&#xA;&#xA;<p>But I'm unclear how to use it in the context of this problem. Would appreciate all / any advice. </p>&#xA;
computer architecture program optimization
1
Using Amdahl's law how do you determine execution time after an improvement? -- (computer architecture program optimization) <p>Speeding up a new floating-point unit by 2 slows down data cache accesses by a factor of 2/3 (or a 1.5 slowdown for data caches). If old FP unit took 20% of program's execution time and data cache accesses took 10% of program's execution time, what is the overall speed up? </p>&#xA;&#xA;<p>I solved this problem using amdahl's law: </p>&#xA;&#xA;<p>FeFP = floating point enhanced fraction = .2</p>&#xA;&#xA;<p>FeDC = data cache access enhanced fraction = .1</p>&#xA;&#xA;<p>SeFP = floating point enhanced speedup = 2</p>&#xA;&#xA;<p>SeDC = data cache access enhanced speedup = 2/3</p>&#xA;&#xA;<p>Speedup overall = 1 / ( (1 - FeFP - FeDC) + FeFP/SeFP + FeDC * SeDC )</p>&#xA;&#xA;<p>= 1 / ( ( 1 - .2 - .1 ) + .2/2 + (.1) * (2/3) )&#xA; = 1.154. </p>&#xA;&#xA;<p>I hope I did this correctly, but I'm confused about the next part asking what percentage of execution time is spent on floating point operations after implementing the new FP unit? </p>&#xA;&#xA;<p>I know that T[improved ] = T[affected] / improvement factor + T[unaffected]</p>&#xA;&#xA;<p>But I'm unclear how to use it in the context of this problem. Would appreciate all / any advice. </p>&#xA;
habedi/stack-exchange-dataset
6,206
What does 'computable in the limit from above' mean?
<p>$H(x)$ is the program size complexity of $x$ for some universal Turing machine $U$. $H$ is not computable, however $H$ is "<em>computable in the limit from above</em>".</p>&#xA;&#xA;<p>From my notes:</p>&#xA;&#xA;<blockquote>&#xA; <p>i.e the set $\{(x,n) \mid x \in B^*,n \geq 0, H(x) \leq n\}$ is computably enumerable.</p>&#xA;</blockquote>&#xA;&#xA;<p>Can someone tell me what this means? I understand the incomputability of $H$ but the term "limit from above" is confusing me.</p>&#xA;
computability terminology
1
What does 'computable in the limit from above' mean? -- (computability terminology) <p>$H(x)$ is the program size complexity of $x$ for some universal Turing machine $U$. $H$ is not computable, however $H$ is "<em>computable in the limit from above</em>".</p>&#xA;&#xA;<p>From my notes:</p>&#xA;&#xA;<blockquote>&#xA; <p>i.e the set $\{(x,n) \mid x \in B^*,n \geq 0, H(x) \leq n\}$ is computably enumerable.</p>&#xA;</blockquote>&#xA;&#xA;<p>Can someone tell me what this means? I understand the incomputability of $H$ but the term "limit from above" is confusing me.</p>&#xA;
habedi/stack-exchange-dataset
6,210
Assignment problem for multiple days
<p>I have a problem that can be reduced to an assignment problem.&#xA;(In a previous <a href="https://cstheory.stackexchange.com/questions/12850/matching-on-bipartite-graph-multiple-edges">question</a> i found out how to do that.)</p>&#xA;&#xA;<p>Which means we have a set $A$ of agents and a set $T$ of tasks as well as a cost function $c(i,j)$. We need to find an assignment so that the total cost is minimal.</p>&#xA;&#xA;<p>The <a href="http://en.wikipedia.org/wiki/Hungarian_algorithm" rel="nofollow noreferrer">hungarian algorithm</a> can find an optimal solution in at least $O(n^4)$. Which sounds good to me.</p>&#xA;&#xA;<p>My new Problem is:&#xA;There is a given number of days. I have to solve the assignment problem for each day so that <strong>every task is done every day</strong> and <strong>no agent does the same task twice</strong>.</p>&#xA;&#xA;<p>What I have tried:&#xA;We could run the hungarian algorithm separately for each day and limit the number of possible combinations based on the result of the previous day. But this would get us into trouble at some of the later days, where most likely it will be impossible to find a feasibly solution.</p>&#xA;&#xA;<p>Another idea is to somehow integrate local search to change decisions made at a previous day. But I think we can't rely on this.</p>&#xA;&#xA;<p>The problem instances I have to face will be somewhere around $|A| = |T| = 500$. The cost matrix $C(i,j)$ will have lots of same values (E.g. mostly 1 or infinity, only some 2 or 3). So during the hungarian algorithm there is a lot of space to create different optimal solutions for a single day.</p>&#xA;&#xA;<p>I'd be glad to hear some ideas or advises how to find a good solution for the problem.&#xA;Thanks in advance.</p>&#xA;
algorithms graphs assignment problem
1
Assignment problem for multiple days -- (algorithms graphs assignment problem) <p>I have a problem that can be reduced to an assignment problem.&#xA;(In a previous <a href="https://cstheory.stackexchange.com/questions/12850/matching-on-bipartite-graph-multiple-edges">question</a> i found out how to do that.)</p>&#xA;&#xA;<p>Which means we have a set $A$ of agents and a set $T$ of tasks as well as a cost function $c(i,j)$. We need to find an assignment so that the total cost is minimal.</p>&#xA;&#xA;<p>The <a href="http://en.wikipedia.org/wiki/Hungarian_algorithm" rel="nofollow noreferrer">hungarian algorithm</a> can find an optimal solution in at least $O(n^4)$. Which sounds good to me.</p>&#xA;&#xA;<p>My new Problem is:&#xA;There is a given number of days. I have to solve the assignment problem for each day so that <strong>every task is done every day</strong> and <strong>no agent does the same task twice</strong>.</p>&#xA;&#xA;<p>What I have tried:&#xA;We could run the hungarian algorithm separately for each day and limit the number of possible combinations based on the result of the previous day. But this would get us into trouble at some of the later days, where most likely it will be impossible to find a feasibly solution.</p>&#xA;&#xA;<p>Another idea is to somehow integrate local search to change decisions made at a previous day. But I think we can't rely on this.</p>&#xA;&#xA;<p>The problem instances I have to face will be somewhere around $|A| = |T| = 500$. The cost matrix $C(i,j)$ will have lots of same values (E.g. mostly 1 or infinity, only some 2 or 3). So during the hungarian algorithm there is a lot of space to create different optimal solutions for a single day.</p>&#xA;&#xA;<p>I'd be glad to hear some ideas or advises how to find a good solution for the problem.&#xA;Thanks in advance.</p>&#xA;
habedi/stack-exchange-dataset
6,211
How can I improve my Algorithm?
<blockquote>&#xA; <p>This is a problem from Interview Street in Dynamic Programming section.&#xA; <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb" rel="nofollow">https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb</a></p>&#xA; &#xA; <p>Billboards(20 points)</p>&#xA; &#xA; <p>ADZEN is a very popular advertising firm in your city. In every road you can see their advertising billboards. Recently they are facing a serious challenge , MG Road the most used and beautiful road in your city has been almost filled by the billboards and this is having a negative effect on the natural view.</p>&#xA; &#xA; <p>On people's demand ADZEN has decided to remove some of the billboards in such a way that there are no more than K billboards standing together in any part of the road.</p>&#xA; &#xA; <p>You may assume the MG Road to be a straight line with N billboards.Initially there is no gap between any two adjecent billboards.</p>&#xA; &#xA; <p>ADZEN's primary income comes from these billboards so the billboard removing process has to be done in such a way that the billboards remaining at end should give maximum possible profit among all possible final configurations.Total profit of a configuration is the sum of the profit values of all billboards present in that configuration.</p>&#xA; &#xA; <p>Given N,K and the profit value of each of the N billboards, output the maximum profit that can be obtained from the remaining billboards under the conditions given.</p>&#xA;</blockquote>&#xA;&#xA;<pre><code>Constraints&#xA;1 &lt;= N &lt;= 1,00,000(10^5)&#xA;1 &lt;= K &lt;= N&#xA;0 &lt;= profit value of any billboard &lt;= 2,000,000,000(2*10^9)&#xA;</code></pre>&#xA;&#xA;<blockquote>&#xA; <p>My Solution (Psuedocode):</p>&#xA;</blockquote>&#xA;&#xA;<pre><code>Let Profit[i] denote the Profit from ith billboard.&#xA;(i, j) denotes the range of billboards&#xA;MaxProfit(i, j) for all (i, j) such that i&lt;=j and i-j+1 &lt;= K is:&#xA; MaxProfit(i, j) = Profit[i] + Profit[i+1] + ... + Profit[j];&#xA;&#xA;For other (i,j) MaxProfit equals,&#xA;&#xA;MaxProfit(i, j)&#xA;{&#xA; if(MaxProfit(i, j) is already calculated)&#xA; then return its value;&#xA; max = 0;&#xA; for all k such that i&lt;=k&lt;=j // k denotes that, that position has no billboard&#xA; {&#xA; temp = MaxProfit(i, k-1) + MaxProfit(k+1, j);&#xA; if(temp &gt; max)&#xA; max = temp;&#xA; }&#xA;return max;&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>My solution is of order $$N^2$$. So I get TLE and Segmentation fault for larger N. I have already passed 6/10 test cases. I need to pass remaining 4. Help needed.</p>&#xA;
algorithms data structures dynamic programming
1
How can I improve my Algorithm? -- (algorithms data structures dynamic programming) <blockquote>&#xA; <p>This is a problem from Interview Street in Dynamic Programming section.&#xA; <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb" rel="nofollow">https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb</a></p>&#xA; &#xA; <p>Billboards(20 points)</p>&#xA; &#xA; <p>ADZEN is a very popular advertising firm in your city. In every road you can see their advertising billboards. Recently they are facing a serious challenge , MG Road the most used and beautiful road in your city has been almost filled by the billboards and this is having a negative effect on the natural view.</p>&#xA; &#xA; <p>On people's demand ADZEN has decided to remove some of the billboards in such a way that there are no more than K billboards standing together in any part of the road.</p>&#xA; &#xA; <p>You may assume the MG Road to be a straight line with N billboards.Initially there is no gap between any two adjecent billboards.</p>&#xA; &#xA; <p>ADZEN's primary income comes from these billboards so the billboard removing process has to be done in such a way that the billboards remaining at end should give maximum possible profit among all possible final configurations.Total profit of a configuration is the sum of the profit values of all billboards present in that configuration.</p>&#xA; &#xA; <p>Given N,K and the profit value of each of the N billboards, output the maximum profit that can be obtained from the remaining billboards under the conditions given.</p>&#xA;</blockquote>&#xA;&#xA;<pre><code>Constraints&#xA;1 &lt;= N &lt;= 1,00,000(10^5)&#xA;1 &lt;= K &lt;= N&#xA;0 &lt;= profit value of any billboard &lt;= 2,000,000,000(2*10^9)&#xA;</code></pre>&#xA;&#xA;<blockquote>&#xA; <p>My Solution (Psuedocode):</p>&#xA;</blockquote>&#xA;&#xA;<pre><code>Let Profit[i] denote the Profit from ith billboard.&#xA;(i, j) denotes the range of billboards&#xA;MaxProfit(i, j) for all (i, j) such that i&lt;=j and i-j+1 &lt;= K is:&#xA; MaxProfit(i, j) = Profit[i] + Profit[i+1] + ... + Profit[j];&#xA;&#xA;For other (i,j) MaxProfit equals,&#xA;&#xA;MaxProfit(i, j)&#xA;{&#xA; if(MaxProfit(i, j) is already calculated)&#xA; then return its value;&#xA; max = 0;&#xA; for all k such that i&lt;=k&lt;=j // k denotes that, that position has no billboard&#xA; {&#xA; temp = MaxProfit(i, k-1) + MaxProfit(k+1, j);&#xA; if(temp &gt; max)&#xA; max = temp;&#xA; }&#xA;return max;&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>My solution is of order $$N^2$$. So I get TLE and Segmentation fault for larger N. I have already passed 6/10 test cases. I need to pass remaining 4. Help needed.</p>&#xA;
habedi/stack-exchange-dataset
6,221
Classfication of randomized algorithms
<p>From <a href="http://en.wikipedia.org/wiki/Randomized_algorithm">Wikipedia</a> about randomized algorithms</p>&#xA;&#xA;<blockquote>&#xA; <p>One has to distinguish between <strong>algorithms</strong> that use the random&#xA; input to reduce the expected running time or memory usage, but always&#xA; terminate with a correct result in a bounded amount of time, and&#xA; <strong>probabilistic algorithms</strong>, which, depending on the random input, have a chance of producing an incorrect result (Monte Carlo&#xA; algorithms) or fail to produce a result (Las Vegas algorithms) either&#xA; by signalling a failure or failing to terminate.</p>&#xA;</blockquote>&#xA;&#xA;<ol>&#xA;<li>I was wondering how the first kind of "<strong>algorithms</strong> use the random&#xA;input to reduce the expected running time or memory usage, but&#xA;always terminate with a correct result in a bounded amount of time?</li>&#xA;<li>What differences are between it and Las Vegas algorithms which may&#xA;fail to produce a result?</li>&#xA;<li>If I understand correctly, probabilistic algorithms and randomized algorithms are not the same concept. Probabilistic algorithms are just one&#xA;kind of randomized algorithms, and the other kind is those use the&#xA;random input to reduce the expected running time or memory usage,&#xA;but always terminate with a correct result in a bounded amount of&#xA;time?</li>&#xA;</ol>&#xA;
algorithms terminology randomized algorithms nondeterminism machine models
1
Classfication of randomized algorithms -- (algorithms terminology randomized algorithms nondeterminism machine models) <p>From <a href="http://en.wikipedia.org/wiki/Randomized_algorithm">Wikipedia</a> about randomized algorithms</p>&#xA;&#xA;<blockquote>&#xA; <p>One has to distinguish between <strong>algorithms</strong> that use the random&#xA; input to reduce the expected running time or memory usage, but always&#xA; terminate with a correct result in a bounded amount of time, and&#xA; <strong>probabilistic algorithms</strong>, which, depending on the random input, have a chance of producing an incorrect result (Monte Carlo&#xA; algorithms) or fail to produce a result (Las Vegas algorithms) either&#xA; by signalling a failure or failing to terminate.</p>&#xA;</blockquote>&#xA;&#xA;<ol>&#xA;<li>I was wondering how the first kind of "<strong>algorithms</strong> use the random&#xA;input to reduce the expected running time or memory usage, but&#xA;always terminate with a correct result in a bounded amount of time?</li>&#xA;<li>What differences are between it and Las Vegas algorithms which may&#xA;fail to produce a result?</li>&#xA;<li>If I understand correctly, probabilistic algorithms and randomized algorithms are not the same concept. Probabilistic algorithms are just one&#xA;kind of randomized algorithms, and the other kind is those use the&#xA;random input to reduce the expected running time or memory usage,&#xA;but always terminate with a correct result in a bounded amount of&#xA;time?</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
6,230
What is tail recursion?
<p>I know the general concept of recursion. I came across the concept of <strong>tail recursion</strong> while studying the quicksort algorithm. In this <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/lecture-4-quicksort-randomized-algorithms/" rel="noreferrer">video of quick sort algorithm from MIT</a> at 18:30 seconds the professor says that this is a tail recursive algorithm. It is not clear to me what tail recursion really means.</p>&#xA;&#xA;<p>Can someone explain the concept with a proper example?</p>&#xA;&#xA;<p><em>Some answers provided by the SO community <a href="https://stackoverflow.com/questions/11864006/why-is-quick-sort-called-a-tail-recursive-algorithm">here</a>.</em></p>&#xA;
algorithms reference request recursion
1
What is tail recursion? -- (algorithms reference request recursion) <p>I know the general concept of recursion. I came across the concept of <strong>tail recursion</strong> while studying the quicksort algorithm. In this <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/lecture-4-quicksort-randomized-algorithms/" rel="noreferrer">video of quick sort algorithm from MIT</a> at 18:30 seconds the professor says that this is a tail recursive algorithm. It is not clear to me what tail recursion really means.</p>&#xA;&#xA;<p>Can someone explain the concept with a proper example?</p>&#xA;&#xA;<p><em>Some answers provided by the SO community <a href="https://stackoverflow.com/questions/11864006/why-is-quick-sort-called-a-tail-recursive-algorithm">here</a>.</em></p>&#xA;
habedi/stack-exchange-dataset
6,236
Minimum space needed to sort a stream of integers
<p>This question has gotten a lot of attention on SO:<br>&#xA;<a href="https://stackoverflow.com/questions/12748246/sorting-1-million-8-digit-numbers-in-1mb-of-ram">Sorting 1 million 8-digit numbers in 1MB of RAM</a></p>&#xA;&#xA;<p>The problem is to sort a stream of 1 million 8-digit numbers (integers in the range $[0,\: 99\mathord{,}999\mathord{,}999]$) using only 1 MB of memory ($2^{20}$ bytes = $2^{23}$ bits) and no external storage. The program must read values from an input stream and write the sorted result to an output stream.</p>&#xA;&#xA;<p>Obviously the entire input can't fit into memory, but clearly the result can be represented in under 1 MB since $2^{23} \geq \log_2 \binom{10^8}{10^6} \approx 8079302$ (it's a tight fit).</p>&#xA;&#xA;<p>So, what is the minimum amount of space needed to sort n integers with duplicates in this streaming manner, and is there an algorithm to accomplish the specified task?</p>&#xA;
algorithms sorting space complexity data compression streaming algorithm
1
Minimum space needed to sort a stream of integers -- (algorithms sorting space complexity data compression streaming algorithm) <p>This question has gotten a lot of attention on SO:<br>&#xA;<a href="https://stackoverflow.com/questions/12748246/sorting-1-million-8-digit-numbers-in-1mb-of-ram">Sorting 1 million 8-digit numbers in 1MB of RAM</a></p>&#xA;&#xA;<p>The problem is to sort a stream of 1 million 8-digit numbers (integers in the range $[0,\: 99\mathord{,}999\mathord{,}999]$) using only 1 MB of memory ($2^{20}$ bytes = $2^{23}$ bits) and no external storage. The program must read values from an input stream and write the sorted result to an output stream.</p>&#xA;&#xA;<p>Obviously the entire input can't fit into memory, but clearly the result can be represented in under 1 MB since $2^{23} \geq \log_2 \binom{10^8}{10^6} \approx 8079302$ (it's a tight fit).</p>&#xA;&#xA;<p>So, what is the minimum amount of space needed to sort n integers with duplicates in this streaming manner, and is there an algorithm to accomplish the specified task?</p>&#xA;
habedi/stack-exchange-dataset
6,237
What units should Shannon entropy be measured in?
<p>The only examples I've seen use bits as a measurement of entropy, but all these examples happen to use binary code alphabets. If we wanted to see how well a coding with a code alphabet of length n works, would we measure entropy in units of n?</p>&#xA;&#xA;<p>Or would it make sense to stay using bits if we're comparing codings with binary and n-length code alphabets?</p>&#xA;
information theory entropy
1
What units should Shannon entropy be measured in? -- (information theory entropy) <p>The only examples I've seen use bits as a measurement of entropy, but all these examples happen to use binary code alphabets. If we wanted to see how well a coding with a code alphabet of length n works, would we measure entropy in units of n?</p>&#xA;&#xA;<p>Or would it make sense to stay using bits if we're comparing codings with binary and n-length code alphabets?</p>&#xA;
habedi/stack-exchange-dataset
6,239
Constructing deterministic PDA for not regular language
<p>Let the input alphabet be $\Sigma = \{a,b,c\}$ and <em>L</em> be the language of all words in which all of the <em>a</em>’s come before all of the <em>b</em>’s and there are the same number of <em>a</em>’s as <em>b</em>'s and arbitrarily many <em>c</em>’s that can be in front, behind or among the <em>a</em>’s and <em>b</em>’s. &#xA;Some words in <em>L</em> are: <em>abc ccacaabcccbccbc</em></p>&#xA;&#xA;<p>I know that the language is not regular but how can I find a deterministic PDA (in a drawing fashion) that accepts <em>L</em>?</p>&#xA;&#xA;<p>Edit: So far I've ended up with this which takes care of having the same number of a's as b's and all a's come before all b's. However I cannot figure out how to account for the arbitrary amount of c's in-between b's. Any ideas? <img src="https://i.stack.imgur.com/Daoc6.png" alt="enter image description here"></p>&#xA;&#xA;<p>Sorry for the horrible drawing in advance.</p>&#xA;
automata pushdown automata
1
Constructing deterministic PDA for not regular language -- (automata pushdown automata) <p>Let the input alphabet be $\Sigma = \{a,b,c\}$ and <em>L</em> be the language of all words in which all of the <em>a</em>’s come before all of the <em>b</em>’s and there are the same number of <em>a</em>’s as <em>b</em>'s and arbitrarily many <em>c</em>’s that can be in front, behind or among the <em>a</em>’s and <em>b</em>’s. &#xA;Some words in <em>L</em> are: <em>abc ccacaabcccbccbc</em></p>&#xA;&#xA;<p>I know that the language is not regular but how can I find a deterministic PDA (in a drawing fashion) that accepts <em>L</em>?</p>&#xA;&#xA;<p>Edit: So far I've ended up with this which takes care of having the same number of a's as b's and all a's come before all b's. However I cannot figure out how to account for the arbitrary amount of c's in-between b's. Any ideas? <img src="https://i.stack.imgur.com/Daoc6.png" alt="enter image description here"></p>&#xA;&#xA;<p>Sorry for the horrible drawing in advance.</p>&#xA;
habedi/stack-exchange-dataset
6,241
In the Miller-Rabin primality test, for a composite number, why are at least $\frac{3}{4}$ of the bases witnesses of compositeness?
<p>The following is an excerpt from the <a href="http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Accuracy_of_the_test" rel="nofollow">Wikipedia article on the Miller-Rabin primality test</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>It can be shown that for any odd composite $n$, at least $\frac{3}{4}$ of the bases $a$ are witnesses for the compositeness of $n$.</p>&#xA;</blockquote>&#xA;&#xA;<p>In the Fermat primality test, if $n$ is not a Carmichael number, <a href="http://en.wikipedia.org/wiki/Fermat_primality_test#Flaw" rel="nofollow">at least half of the bases $a$ are Fermat witnesses</a>. Testing for non-trivial roots in the Miller-Rabin primality test however increases the minimum number of witnesses to $\frac{3}{4}$.</p>&#xA;
cryptography number theory
1
In the Miller-Rabin primality test, for a composite number, why are at least $\frac{3}{4}$ of the bases witnesses of compositeness? -- (cryptography number theory) <p>The following is an excerpt from the <a href="http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Accuracy_of_the_test" rel="nofollow">Wikipedia article on the Miller-Rabin primality test</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>It can be shown that for any odd composite $n$, at least $\frac{3}{4}$ of the bases $a$ are witnesses for the compositeness of $n$.</p>&#xA;</blockquote>&#xA;&#xA;<p>In the Fermat primality test, if $n$ is not a Carmichael number, <a href="http://en.wikipedia.org/wiki/Fermat_primality_test#Flaw" rel="nofollow">at least half of the bases $a$ are Fermat witnesses</a>. Testing for non-trivial roots in the Miller-Rabin primality test however increases the minimum number of witnesses to $\frac{3}{4}$.</p>&#xA;
habedi/stack-exchange-dataset
6,244
Rényi entropy at infinity or min-entropy
<p>I'm reading a paper that refers to the limit as n goes to infinity of Rényi entropy. It defines it as ${{H}_{n}}\left( X \right)=\dfrac{1}{1-n} \log_2 \left( \sum\limits_{i=1}^{N}{p_{i}^{n}} \right)$. It then says that the limit as $n\to \infty $ is $-\log_2 \left( p_1 \right)$. I saw another article that uses the maximum of the ${{p}_{i}}'s$ instead of ${{p}_{1}}$. I think that this works out fairly easily if all of the ${{p}_{i}}'s$ are equal (a uniform distribution). I have no idea how to prove this for anything other than a uniform distribution. Can anyone show me how it's done?</p>&#xA;
information theory entropy
1
Rényi entropy at infinity or min-entropy -- (information theory entropy) <p>I'm reading a paper that refers to the limit as n goes to infinity of Rényi entropy. It defines it as ${{H}_{n}}\left( X \right)=\dfrac{1}{1-n} \log_2 \left( \sum\limits_{i=1}^{N}{p_{i}^{n}} \right)$. It then says that the limit as $n\to \infty $ is $-\log_2 \left( p_1 \right)$. I saw another article that uses the maximum of the ${{p}_{i}}'s$ instead of ${{p}_{1}}$. I think that this works out fairly easily if all of the ${{p}_{i}}'s$ are equal (a uniform distribution). I have no idea how to prove this for anything other than a uniform distribution. Can anyone show me how it's done?</p>&#xA;
habedi/stack-exchange-dataset
6,245
Is there a data-structure for semilattices similar to a tree data-structure?
<p>If we regard a tree as a partial ordered set, it becomes a special case of a join-semilattice. For a join-semilattice, we want to be able to compute the (unique) least upper bound of two elements (more or less) efficiently. In the case of a tree, a data structure which would enable this would be to store for each element in the corresponding node a pointer to the parent and a distance measure to the root. (Actually, a labeling based on topological sort usually used for "a distance measure to the root", effectively all that is needed is a compatible partial order which can be evaluated efficiently).</p>&#xA;&#xA;<p>Each finite join-semilattice can be represented as a set of subsets of a finite set with containment as order such that the least upper bound is given by the union of the sets. Hence, representing each element by a finite number of tags, and computing the least upper bound by the union of the corresponding tags would be one possible data structure. (By looking at the complement, one sees that defining the least upper bound as the intersection of the corresponding tags would also be possible.) A much more common data-structure is to simply use a matrix to store all results of "a &lt;= b" or even all results of "join(a,b)".</p>&#xA;&#xA;<p>However, using such a data-structure to represent a tree would be sort of strange. Are there more tree-like data-structures for join-semilattices, which still allow (more or less) efficient computation of the (unique) least upper bound of two elements? (Perhaps some sort of directed acyclic graph with additional information in the nodes similar to the distance measure to the root for the tree?)</p>&#xA;
data structures lattices
1
Is there a data-structure for semilattices similar to a tree data-structure? -- (data structures lattices) <p>If we regard a tree as a partial ordered set, it becomes a special case of a join-semilattice. For a join-semilattice, we want to be able to compute the (unique) least upper bound of two elements (more or less) efficiently. In the case of a tree, a data structure which would enable this would be to store for each element in the corresponding node a pointer to the parent and a distance measure to the root. (Actually, a labeling based on topological sort usually used for "a distance measure to the root", effectively all that is needed is a compatible partial order which can be evaluated efficiently).</p>&#xA;&#xA;<p>Each finite join-semilattice can be represented as a set of subsets of a finite set with containment as order such that the least upper bound is given by the union of the sets. Hence, representing each element by a finite number of tags, and computing the least upper bound by the union of the corresponding tags would be one possible data structure. (By looking at the complement, one sees that defining the least upper bound as the intersection of the corresponding tags would also be possible.) A much more common data-structure is to simply use a matrix to store all results of "a &lt;= b" or even all results of "join(a,b)".</p>&#xA;&#xA;<p>However, using such a data-structure to represent a tree would be sort of strange. Are there more tree-like data-structures for join-semilattices, which still allow (more or less) efficient computation of the (unique) least upper bound of two elements? (Perhaps some sort of directed acyclic graph with additional information in the nodes similar to the distance measure to the root for the tree?)</p>&#xA;
habedi/stack-exchange-dataset
6,247
Do "inductively" and "recursively" have very similar meanings?
<p>Do "inductively" and "recursively" mean very similar?</p>&#xA;&#xA;<p>For example, if there is an algorithm that determines a n-dim vector by determine its first k+1 components based on its first k components having been determined, and is initialized with the first component, would you call it works recursively or inductively? I have been using "recursively", but today someone said it "inductively".</p>&#xA;
algorithms terminology recursion induction
1
Do "inductively" and "recursively" have very similar meanings? -- (algorithms terminology recursion induction) <p>Do "inductively" and "recursively" mean very similar?</p>&#xA;&#xA;<p>For example, if there is an algorithm that determines a n-dim vector by determine its first k+1 components based on its first k components having been determined, and is initialized with the first component, would you call it works recursively or inductively? I have been using "recursively", but today someone said it "inductively".</p>&#xA;
habedi/stack-exchange-dataset
6,249
Constructing a tree from disjoint graphs
<p>I will preface my question with the definition of a simple tree that applies to my question:</p>&#xA;&#xA;<blockquote>&#xA; <p>A simple tree is an undirected and connected graph with no cycles.</p>&#xA;</blockquote>&#xA;&#xA;<p>I am having difficulty coming up with a compelling argument that a tree of the above definition can be constructed by taking a set of disjoint valid graphs and adding a vertex between each of them. The practice problem states:</p>&#xA;&#xA;<blockquote>&#xA; <p>Prove that some graph $G$ is a tree if and only if it can be constructed from a set $X_1, X_2, \dots, X_i$ of disjoint valid graphs by adding a new node adjacent to one node from each of $X_1,\dots, X_i$. A single node is a valid graph.</p>&#xA;</blockquote>&#xA;&#xA;<p>I'm confused whether this question is asking me to prove that two graphs, or trees ("valid"), can be made into one tree by adding a node and adding edges from one preexisting node from each of the trees. If that is how the question should be interpreted, then is it enough to prove that the new tree (or "graph," I guess) has no cycles, and is connected?</p>&#xA;&#xA;<p>I'm new to graph theory and I'm wondering if you can help me understand it.</p>&#xA;
graphs trees
1
Constructing a tree from disjoint graphs -- (graphs trees) <p>I will preface my question with the definition of a simple tree that applies to my question:</p>&#xA;&#xA;<blockquote>&#xA; <p>A simple tree is an undirected and connected graph with no cycles.</p>&#xA;</blockquote>&#xA;&#xA;<p>I am having difficulty coming up with a compelling argument that a tree of the above definition can be constructed by taking a set of disjoint valid graphs and adding a vertex between each of them. The practice problem states:</p>&#xA;&#xA;<blockquote>&#xA; <p>Prove that some graph $G$ is a tree if and only if it can be constructed from a set $X_1, X_2, \dots, X_i$ of disjoint valid graphs by adding a new node adjacent to one node from each of $X_1,\dots, X_i$. A single node is a valid graph.</p>&#xA;</blockquote>&#xA;&#xA;<p>I'm confused whether this question is asking me to prove that two graphs, or trees ("valid"), can be made into one tree by adding a node and adding edges from one preexisting node from each of the trees. If that is how the question should be interpreted, then is it enough to prove that the new tree (or "graph," I guess) has no cycles, and is connected?</p>&#xA;&#xA;<p>I'm new to graph theory and I'm wondering if you can help me understand it.</p>&#xA;
habedi/stack-exchange-dataset
6,253
Visualizing a Non Deterministic Decider
<p>I know that we can visualize a Non deterministic TM as a TM which splits into multiple copies of itself whenever it sees a non deterministic path (Yes, I also know that this is just a visualization and is usually used by beginners like me for understanding non determistisism). </p>&#xA;&#xA;<p>Further, I also know that a Decider is a TM that halts on all possible inputs.</p>&#xA;&#xA;<p>Now, my question is how can I visualize a Non determistic Decider? Does a non-determistic decider mean a TM where</p>&#xA;&#xA;<ol>&#xA;<li>All the copies must halt, (OR)</li>&#xA;<li>At-least one copy halts.</li>&#xA;</ol>&#xA;&#xA;<p>Kindly explain in detail why so. Thanks.</p>&#xA;
turing machines undecidability nondeterminism
1
Visualizing a Non Deterministic Decider -- (turing machines undecidability nondeterminism) <p>I know that we can visualize a Non deterministic TM as a TM which splits into multiple copies of itself whenever it sees a non deterministic path (Yes, I also know that this is just a visualization and is usually used by beginners like me for understanding non determistisism). </p>&#xA;&#xA;<p>Further, I also know that a Decider is a TM that halts on all possible inputs.</p>&#xA;&#xA;<p>Now, my question is how can I visualize a Non determistic Decider? Does a non-determistic decider mean a TM where</p>&#xA;&#xA;<ol>&#xA;<li>All the copies must halt, (OR)</li>&#xA;<li>At-least one copy halts.</li>&#xA;</ol>&#xA;&#xA;<p>Kindly explain in detail why so. Thanks.</p>&#xA;
habedi/stack-exchange-dataset
6,259
Assumption on weights in threshold circuits
<p>A threshold gate implementing a linear threshold function on $n$ boolean inputs $x_1, x_2 \ldots, x_n$ is given by the equation:&#xA;$w_1 x_1 + w_2 x_2 + \ldots, w_n x_n \ge t$&#xA;where $w_1, \ldots, w_n, t \in \mathbb{R}$. The $w_i$'s are called the weights of the threshold function and $t$ is called the threshold, and naturally, the gate fires a $1$ on an input $x$ if the weighted sum given by the equation above exceeds $t$. </p>&#xA;&#xA;<p>Now, almost everywhere in the literature on threshold circuits, I encounter this fact (which I am guessing, is folklore since I couldn't find a proof anywhere): The $w_i$'s in the linear equation above can be made integers (on $n \log{n}$ bits), and a threshold circuit made up of these gates will still compute whatever was possible with real weights. I have given this some thought, and I think it must be a simple trick, but I have failed to obtain a proof of this fact. Can somebody help or provide me with a reference? (the only reference I could find was a text by Muroga, which I couldn't procure)</p>&#xA;
complexity theory circuits
1
Assumption on weights in threshold circuits -- (complexity theory circuits) <p>A threshold gate implementing a linear threshold function on $n$ boolean inputs $x_1, x_2 \ldots, x_n$ is given by the equation:&#xA;$w_1 x_1 + w_2 x_2 + \ldots, w_n x_n \ge t$&#xA;where $w_1, \ldots, w_n, t \in \mathbb{R}$. The $w_i$'s are called the weights of the threshold function and $t$ is called the threshold, and naturally, the gate fires a $1$ on an input $x$ if the weighted sum given by the equation above exceeds $t$. </p>&#xA;&#xA;<p>Now, almost everywhere in the literature on threshold circuits, I encounter this fact (which I am guessing, is folklore since I couldn't find a proof anywhere): The $w_i$'s in the linear equation above can be made integers (on $n \log{n}$ bits), and a threshold circuit made up of these gates will still compute whatever was possible with real weights. I have given this some thought, and I think it must be a simple trick, but I have failed to obtain a proof of this fact. Can somebody help or provide me with a reference? (the only reference I could find was a text by Muroga, which I couldn't procure)</p>&#xA;
habedi/stack-exchange-dataset
6,262
If a predicate is not computable, what can be said about its negation?
<p>Doing the following exercise:</p>&#xA;<blockquote>&#xA;<p>Let <span class="math-container">$\overline{HALT(x,y)}$</span> be defined as</p>&#xA;<p><span class="math-container">$\overline {HALT(x,y)} \iff \text{program number y never halts on input x}$</span></p>&#xA;<p>Show that it is not computable.</p>&#xA;</blockquote>&#xA;<p>Just want to make sure I have understood the concept correctly. We had in a theorem that HALT(x,y) is not computable which means that we cannot determine whether program number y eventually halts on input x. I realized that <span class="math-container">$\overline {HALT(x,y)}$</span> is the negation of HALT(x,y). Is it true (I cannot find it in my book or on the internet) that if a function is (not) computable, its negation is also (not) computable? A function being computable means there is a program p which computes it, we cannot say there is a program Q that computes its negation. Or can we draw such conclusion?</p>&#xA;
computability proof techniques
1
If a predicate is not computable, what can be said about its negation? -- (computability proof techniques) <p>Doing the following exercise:</p>&#xA;<blockquote>&#xA;<p>Let <span class="math-container">$\overline{HALT(x,y)}$</span> be defined as</p>&#xA;<p><span class="math-container">$\overline {HALT(x,y)} \iff \text{program number y never halts on input x}$</span></p>&#xA;<p>Show that it is not computable.</p>&#xA;</blockquote>&#xA;<p>Just want to make sure I have understood the concept correctly. We had in a theorem that HALT(x,y) is not computable which means that we cannot determine whether program number y eventually halts on input x. I realized that <span class="math-container">$\overline {HALT(x,y)}$</span> is the negation of HALT(x,y). Is it true (I cannot find it in my book or on the internet) that if a function is (not) computable, its negation is also (not) computable? A function being computable means there is a program p which computes it, we cannot say there is a program Q that computes its negation. Or can we draw such conclusion?</p>&#xA;
habedi/stack-exchange-dataset
6,263
How to prove or disprove that f is computable?
<p>If $f(x_1,\dots, x_n)$ is a total function that for some constant $K$, $f(x_1,\dots, x_n) \leq K$ for all $x_1,\dots, x_n$ then $f$ is computable. </p>&#xA;&#xA;<p>I want some hints on how to prove/disprove the above claim. This an exercise from the book <a href="http://rads.stackoverflow.com/amzn/click/0122063821" rel="nofollow">Computability, Complexity, and Languages</a>. As I didn't find the solutions to the exercises online, I want to see a formal solution of such problems, if possible. </p>&#xA;
computability proof techniques
1
How to prove or disprove that f is computable? -- (computability proof techniques) <p>If $f(x_1,\dots, x_n)$ is a total function that for some constant $K$, $f(x_1,\dots, x_n) \leq K$ for all $x_1,\dots, x_n$ then $f$ is computable. </p>&#xA;&#xA;<p>I want some hints on how to prove/disprove the above claim. This an exercise from the book <a href="http://rads.stackoverflow.com/amzn/click/0122063821" rel="nofollow">Computability, Complexity, and Languages</a>. As I didn't find the solutions to the exercises online, I want to see a formal solution of such problems, if possible. </p>&#xA;
habedi/stack-exchange-dataset
6,274
Recurrence relation for time complexity $T(n) = T(n-1) + n^2$
<p>I'm looking for a $\Theta$ approximation of&#xA;$$T(n) = T(n-1) + cn^{2}$$</p>&#xA;&#xA;<p>This is what I have so far:</p>&#xA;&#xA;<p>$$&#xA;\begin{align*}&#xA;T(n-1)&amp; = T(n-2) + c(n-1)^2\\&#xA;T(n) &amp;= T(n-2) + c(n-1) + cn^2\\[1ex]&#xA;T(n-2) &amp;= T(n-3) + c(n-2)^2\\&#xA;T(n) &amp; = T(n-3) + c(n-2)^2 + c(n-1)^2 + cn^2 \\[1ex]&#xA;T(n-3) &amp;= T(n-4) + c(n-3)^2 \\&#xA;T(n) &amp;= T(n-4) + c(n-3)^2 + c(n-2)^2 + c(n-1)^2 + cn^2&#xA;\end{align*}&#xA;$$</p>&#xA;&#xA;<p>So, at this point I was going to generalize and substitute $k$ into the equation.</p>&#xA;&#xA;<p>$$T(n)= T(n-k) + (n-(k-1))^2 + c(k-1)^2$$</p>&#xA;&#xA;<p>Now, I start to bring the base case of 1 into the picture. On a couple of previous, more simple problems, I was able to set my generalized k equation equal to 1 and then solve for $k$. Then put $k$ back into the equation to get my ultimate answer.</p>&#xA;&#xA;<p>But I am totally stuck on the $(n-k+1)^2$ part. I mean, should I actually foil all this out? I did it and got $k^2-2kn-2k+n^2 +2n +1 = 1$. At this point I'm thinking I totally must have done something wrong since I've never see this in previous problems.</p>&#xA;&#xA;<p>Could anyone offer me some help with how to solve this one? I would greatly appreciate it. I also tried another approach where I tried to set $n-k = 0$ from the last part of the equation and got that $k = n$. I plugged n back into the equation towards the end and ultimately got $n^2$ as an answer. I have no clue if this is right or not.</p>&#xA;&#xA;<p>I am in an algorithms analysis class and we started doing recurrence relations and I'm not 100% sure if I am doing this problem correct. I get to a point where I am just stuck and don't know what to do. Maybe I'm doing this wrong, who knows. The question doesn't care about upper or lower bounds, it just wants a theta.</p>&#xA;
time complexity algorithm analysis proof techniques recurrence relation
1
Recurrence relation for time complexity $T(n) = T(n-1) + n^2$ -- (time complexity algorithm analysis proof techniques recurrence relation) <p>I'm looking for a $\Theta$ approximation of&#xA;$$T(n) = T(n-1) + cn^{2}$$</p>&#xA;&#xA;<p>This is what I have so far:</p>&#xA;&#xA;<p>$$&#xA;\begin{align*}&#xA;T(n-1)&amp; = T(n-2) + c(n-1)^2\\&#xA;T(n) &amp;= T(n-2) + c(n-1) + cn^2\\[1ex]&#xA;T(n-2) &amp;= T(n-3) + c(n-2)^2\\&#xA;T(n) &amp; = T(n-3) + c(n-2)^2 + c(n-1)^2 + cn^2 \\[1ex]&#xA;T(n-3) &amp;= T(n-4) + c(n-3)^2 \\&#xA;T(n) &amp;= T(n-4) + c(n-3)^2 + c(n-2)^2 + c(n-1)^2 + cn^2&#xA;\end{align*}&#xA;$$</p>&#xA;&#xA;<p>So, at this point I was going to generalize and substitute $k$ into the equation.</p>&#xA;&#xA;<p>$$T(n)= T(n-k) + (n-(k-1))^2 + c(k-1)^2$$</p>&#xA;&#xA;<p>Now, I start to bring the base case of 1 into the picture. On a couple of previous, more simple problems, I was able to set my generalized k equation equal to 1 and then solve for $k$. Then put $k$ back into the equation to get my ultimate answer.</p>&#xA;&#xA;<p>But I am totally stuck on the $(n-k+1)^2$ part. I mean, should I actually foil all this out? I did it and got $k^2-2kn-2k+n^2 +2n +1 = 1$. At this point I'm thinking I totally must have done something wrong since I've never see this in previous problems.</p>&#xA;&#xA;<p>Could anyone offer me some help with how to solve this one? I would greatly appreciate it. I also tried another approach where I tried to set $n-k = 0$ from the last part of the equation and got that $k = n$. I plugged n back into the equation towards the end and ultimately got $n^2$ as an answer. I have no clue if this is right or not.</p>&#xA;&#xA;<p>I am in an algorithms analysis class and we started doing recurrence relations and I'm not 100% sure if I am doing this problem correct. I get to a point where I am just stuck and don't know what to do. Maybe I'm doing this wrong, who knows. The question doesn't care about upper or lower bounds, it just wants a theta.</p>&#xA;
habedi/stack-exchange-dataset
6,276
Regarding the height of a recursion tree on dynamic programming
<p>I am trying to understand dynamic programming and I am watching this mit video. If you guys could take some time out , can you refer to the slide on 41:36 . Why is the height m+n. I just don't get it why is the heigh of this recurrence tree m+n.</p>&#xA;&#xA;<p><a href="http://videolectures.net/mit6046jf05_leiserson_lec15/" rel="nofollow">http://videolectures.net/mit6046jf05_leiserson_lec15/</a></p>&#xA;&#xA;<p>Thank you. </p>&#xA;
recurrence relation dynamic programming
1
Regarding the height of a recursion tree on dynamic programming -- (recurrence relation dynamic programming) <p>I am trying to understand dynamic programming and I am watching this mit video. If you guys could take some time out , can you refer to the slide on 41:36 . Why is the height m+n. I just don't get it why is the heigh of this recurrence tree m+n.</p>&#xA;&#xA;<p><a href="http://videolectures.net/mit6046jf05_leiserson_lec15/" rel="nofollow">http://videolectures.net/mit6046jf05_leiserson_lec15/</a></p>&#xA;&#xA;<p>Thank you. </p>&#xA;
habedi/stack-exchange-dataset
6,277
Why is the minimum height of a binary tree $\log_2(n+1) - 1$?
<p>In my Java class, we are learning about complexity of different types of collections.</p>&#xA;&#xA;<p>Soon we will be discussing binary trees, which I have been reading up on. The book states that the minimum height of a binary tree is $\log_2(n+1) - 1$, but doesn't offer further explanation.</p>&#xA;&#xA;<p>Can someone explain why?</p>&#xA;
data structures binary trees discrete mathematics trees
1
Why is the minimum height of a binary tree $\log_2(n+1) - 1$? -- (data structures binary trees discrete mathematics trees) <p>In my Java class, we are learning about complexity of different types of collections.</p>&#xA;&#xA;<p>Soon we will be discussing binary trees, which I have been reading up on. The book states that the minimum height of a binary tree is $\log_2(n+1) - 1$, but doesn't offer further explanation.</p>&#xA;&#xA;<p>Can someone explain why?</p>&#xA;
habedi/stack-exchange-dataset
6,279
If $L$ is a regular language, how to prove $L_1 = \{ uv \mid u \in L, |v| =2 \}$ is also regular?
<blockquote>&#xA; <p>If $L$ is a regular language, prove that the language&#xA; $L_1 = \{ uv \mid u \in L, |v| =2 \}$&#xA; is also regular.</p>&#xA;</blockquote>&#xA;&#xA;<p>My idea: $L$ can be represented as a DFA and then you could add 2 consecutive transitions from every final state for the letters of $v$, creating a new NFA diagram. Is that correct? I'm not sure how to make this a formal proof.</p>&#xA;
regular languages automata finite automata closure properties check my answer
1
If $L$ is a regular language, how to prove $L_1 = \{ uv \mid u \in L, |v| =2 \}$ is also regular? -- (regular languages automata finite automata closure properties check my answer) <blockquote>&#xA; <p>If $L$ is a regular language, prove that the language&#xA; $L_1 = \{ uv \mid u \in L, |v| =2 \}$&#xA; is also regular.</p>&#xA;</blockquote>&#xA;&#xA;<p>My idea: $L$ can be represented as a DFA and then you could add 2 consecutive transitions from every final state for the letters of $v$, creating a new NFA diagram. Is that correct? I'm not sure how to make this a formal proof.</p>&#xA;
habedi/stack-exchange-dataset
6,284
Instruction Translation
<p>Imagine two machines of different architecture which produce output of a standard format.</p>&#xA;&#xA;<p>If you have a program for one machine and can observe it's operation and output, what techniques exist to automatically produce an equivalent program for the alternate architecture?</p>&#xA;&#xA;<p>By equivalent I mean produces equal output (by some equality relation) for equivalent input.</p>&#xA;
programming languages compilers
1
Instruction Translation -- (programming languages compilers) <p>Imagine two machines of different architecture which produce output of a standard format.</p>&#xA;&#xA;<p>If you have a program for one machine and can observe it's operation and output, what techniques exist to automatically produce an equivalent program for the alternate architecture?</p>&#xA;&#xA;<p>By equivalent I mean produces equal output (by some equality relation) for equivalent input.</p>&#xA;
habedi/stack-exchange-dataset
6,288
Are randomized algorithms constructive?
<p>From , the proofs by the probabilistic method are often said to be non-constructive.</p>&#xA;&#xA;<p>However, a proof by probabilistic method indeed designs a randomized algorithm and uses it for proving existence. Quoted from p103 of <a href="http://books.google.com/books?id=QKVY4mDivBEC&amp;pg=PR5&amp;lpg=PP1&amp;dq=randomized%20algorithms#v=onepage&amp;q&amp;f=false">Randomized Algorithms&#xA; By Rajeev Motwani, Prabhakar Raghavan</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>We could view the proof by the probabilistic method as a randomized&#xA; algorithm. This would then require a further analysis bounding the&#xA; probability that the algorithm fails to find a good partition on a&#xA; given execution. The main difference between a thought experiment in&#xA; the probabilistic method and a randomized algorithm is the end that&#xA; each yields. When we use the probabilistic method, we are only&#xA; concerned with showing that a combinatorial object exists; thus, we&#xA; are content with showing that a favorable event occurs with non-zero&#xA; probability. With a randomized algorithm, on the other hand,&#xA; efficiency is an important consideration - we cannot tolerate a&#xA; miniscule success probability.</p>&#xA;</blockquote>&#xA;&#xA;<p>So I wonder if randomized algorithms are viewed as not constructive, although they do output a solution at the end of each run, which may or may not be an ideal solution.</p>&#xA;&#xA;<p>How is an algorithm or proof being "constructive" defined?</p>&#xA;&#xA;<p>Thanks!</p>&#xA;
algorithms terminology randomized algorithms
1
Are randomized algorithms constructive? -- (algorithms terminology randomized algorithms) <p>From , the proofs by the probabilistic method are often said to be non-constructive.</p>&#xA;&#xA;<p>However, a proof by probabilistic method indeed designs a randomized algorithm and uses it for proving existence. Quoted from p103 of <a href="http://books.google.com/books?id=QKVY4mDivBEC&amp;pg=PR5&amp;lpg=PP1&amp;dq=randomized%20algorithms#v=onepage&amp;q&amp;f=false">Randomized Algorithms&#xA; By Rajeev Motwani, Prabhakar Raghavan</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>We could view the proof by the probabilistic method as a randomized&#xA; algorithm. This would then require a further analysis bounding the&#xA; probability that the algorithm fails to find a good partition on a&#xA; given execution. The main difference between a thought experiment in&#xA; the probabilistic method and a randomized algorithm is the end that&#xA; each yields. When we use the probabilistic method, we are only&#xA; concerned with showing that a combinatorial object exists; thus, we&#xA; are content with showing that a favorable event occurs with non-zero&#xA; probability. With a randomized algorithm, on the other hand,&#xA; efficiency is an important consideration - we cannot tolerate a&#xA; miniscule success probability.</p>&#xA;</blockquote>&#xA;&#xA;<p>So I wonder if randomized algorithms are viewed as not constructive, although they do output a solution at the end of each run, which may or may not be an ideal solution.</p>&#xA;&#xA;<p>How is an algorithm or proof being "constructive" defined?</p>&#xA;&#xA;<p>Thanks!</p>&#xA;
habedi/stack-exchange-dataset
6,290
Help need to learn Quantum Computation and Information
<p>I want to learn quantum computation and information. I am studying from Nielsen &amp; Chuang book for this.&#xA;Is there any online vedio (lecture series) starts from&#xA;basics of quantum computation and information up to factorization, discrete log, search etc? </p>&#xA;
reference request education quantum computing
1
Help need to learn Quantum Computation and Information -- (reference request education quantum computing) <p>I want to learn quantum computation and information. I am studying from Nielsen &amp; Chuang book for this.&#xA;Is there any online vedio (lecture series) starts from&#xA;basics of quantum computation and information up to factorization, discrete log, search etc? </p>&#xA;
habedi/stack-exchange-dataset
6,291
Polynomial time reducibility
<blockquote>&#xA; <p>$L_1$ and $L_2$ are two languages defined on the alphabet $\sum$.&#xA; $L_1$ is reducible to $L_2$ in polynomial time. Which of the following&#xA; cannot be true?</p>&#xA; &#xA; <ul>&#xA; <li>$L_1 \in P$ and $L_2$ is finite</li>&#xA; <li>$L_1 \in NP$ and $L_2 \in P$</li>&#xA; <li>$L_1$ is undecidable and $L_2$ is decidable</li>&#xA; <li>$L_1$ is recursively enumerable and $L_2$ is recursive</li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>My reasoning is as follow,</p>&#xA;&#xA;<p>If $A \le_p B$, and $B \in P$, then $A$ can be reduced to $B$ in polynomial time and solved in polynomial time making $A \in P$. Thus I initially figured the 2nd choice as false and thus the right answer.</p>&#xA;&#xA;<p>However using the same argument on mapping reducibility, the 3rd choice seems to be false as well. The fourth choice is the same as the third one.</p>&#xA;&#xA;<p>I was unsuccessful in reasoning anything about the 1st choice.</p>&#xA;&#xA;<p>To put my above arguments in context, I am learning about theory of computation and have just about skimmed the surface of computability and complexity theory. Helo me out.</p>&#xA;
complexity theory reductions complexity classes
1
Polynomial time reducibility -- (complexity theory reductions complexity classes) <blockquote>&#xA; <p>$L_1$ and $L_2$ are two languages defined on the alphabet $\sum$.&#xA; $L_1$ is reducible to $L_2$ in polynomial time. Which of the following&#xA; cannot be true?</p>&#xA; &#xA; <ul>&#xA; <li>$L_1 \in P$ and $L_2$ is finite</li>&#xA; <li>$L_1 \in NP$ and $L_2 \in P$</li>&#xA; <li>$L_1$ is undecidable and $L_2$ is decidable</li>&#xA; <li>$L_1$ is recursively enumerable and $L_2$ is recursive</li>&#xA; </ul>&#xA;</blockquote>&#xA;&#xA;<p>My reasoning is as follow,</p>&#xA;&#xA;<p>If $A \le_p B$, and $B \in P$, then $A$ can be reduced to $B$ in polynomial time and solved in polynomial time making $A \in P$. Thus I initially figured the 2nd choice as false and thus the right answer.</p>&#xA;&#xA;<p>However using the same argument on mapping reducibility, the 3rd choice seems to be false as well. The fourth choice is the same as the third one.</p>&#xA;&#xA;<p>I was unsuccessful in reasoning anything about the 1st choice.</p>&#xA;&#xA;<p>To put my above arguments in context, I am learning about theory of computation and have just about skimmed the surface of computability and complexity theory. Helo me out.</p>&#xA;
habedi/stack-exchange-dataset
6,301
Adjacent house , dynamic programming problem
<p>I have to be honest this is a homework problem, but I just need to discuss this with some one. The problem is there is a row of n houses, with different profit e.g profit1 for house 1, it can be either positive or negative value. But the aim is to maximize the profit by buying a subset of these houses. So infact, you should buy houses which are >0 value. However, you cannot buy houses that adjacent to the house you are buying, e.g i-1 and i+1 should not be bought. I am not quite sure where to start to look at this problem, I mean what exactly will be the difference of looking it from the greedy or dynamic programing way. Thanks for any suggestion. </p>&#xA;
dynamic programming knapsack problems
1
Adjacent house , dynamic programming problem -- (dynamic programming knapsack problems) <p>I have to be honest this is a homework problem, but I just need to discuss this with some one. The problem is there is a row of n houses, with different profit e.g profit1 for house 1, it can be either positive or negative value. But the aim is to maximize the profit by buying a subset of these houses. So infact, you should buy houses which are >0 value. However, you cannot buy houses that adjacent to the house you are buying, e.g i-1 and i+1 should not be bought. I am not quite sure where to start to look at this problem, I mean what exactly will be the difference of looking it from the greedy or dynamic programing way. Thanks for any suggestion. </p>&#xA;
habedi/stack-exchange-dataset
6,308
Practical applications of disjoint set datastructure
<p>I know that the disjoint set datastructure is used to keep track of the connected components of an undirected graph when the edges are added to the graph dynamically . I also know that is is used in <a href="http://en.wikipedia.org/wiki/Kruskal%27s_algorithm">Kruskal's algorithm for minimum spanning trees</a> . What are the other possible applications of this datastructure ?</p>&#xA;
algorithms graphs data structures
1
Practical applications of disjoint set datastructure -- (algorithms graphs data structures) <p>I know that the disjoint set datastructure is used to keep track of the connected components of an undirected graph when the edges are added to the graph dynamically . I also know that is is used in <a href="http://en.wikipedia.org/wiki/Kruskal%27s_algorithm">Kruskal's algorithm for minimum spanning trees</a> . What are the other possible applications of this datastructure ?</p>&#xA;
habedi/stack-exchange-dataset
6,309
Determining the classification of languages
<blockquote>&#xA; <p>$L_0 = \{ \langle M, w, 0 \rangle \mid \text{$M$ halts on $w$}\}$ <br>&#xA; $L_1 = \{ \langle M, w, 1 \rangle \mid \text{$M$ does not halt on $w$}\}$</p>&#xA; &#xA; <p>$L = L_0 \cup L_1$</p>&#xA;</blockquote>&#xA;&#xA;<p>I need to determine where in the hierarchy of languages (recursive, recursively enumerable, not recursively enumerable) $L$ and its complement $\overline L$ belong. I reasoned as follows</p>&#xA;&#xA;<p>$L = \{ \langle M, w, x\rangle \mid \text{$M$ halts on $w$ when $x=0$, $M$ doesn't halt on $w$ when $x = 1$, $x \in \{0, 1\}$}\}$</p>&#xA;&#xA;<p>$L$ is clearly not recursively enumerable as a Turing machine wouldn't be able accept in all cases. It can accept only in case the input refers to $L_0$, but can't in case the input refers to $L_1$.</p>&#xA;&#xA;<p>$\overline L = \overline L_0 \cap \overline L_1 = \emptyset$<br>&#xA;Thus $\overline L$ is recursive.</p>&#xA;&#xA;<p>Is my reasoning ok? This is a question from a previous exam paper.</p>&#xA;
formal languages turing machines undecidability halting problem
1
Determining the classification of languages -- (formal languages turing machines undecidability halting problem) <blockquote>&#xA; <p>$L_0 = \{ \langle M, w, 0 \rangle \mid \text{$M$ halts on $w$}\}$ <br>&#xA; $L_1 = \{ \langle M, w, 1 \rangle \mid \text{$M$ does not halt on $w$}\}$</p>&#xA; &#xA; <p>$L = L_0 \cup L_1$</p>&#xA;</blockquote>&#xA;&#xA;<p>I need to determine where in the hierarchy of languages (recursive, recursively enumerable, not recursively enumerable) $L$ and its complement $\overline L$ belong. I reasoned as follows</p>&#xA;&#xA;<p>$L = \{ \langle M, w, x\rangle \mid \text{$M$ halts on $w$ when $x=0$, $M$ doesn't halt on $w$ when $x = 1$, $x \in \{0, 1\}$}\}$</p>&#xA;&#xA;<p>$L$ is clearly not recursively enumerable as a Turing machine wouldn't be able accept in all cases. It can accept only in case the input refers to $L_0$, but can't in case the input refers to $L_1$.</p>&#xA;&#xA;<p>$\overline L = \overline L_0 \cap \overline L_1 = \emptyset$<br>&#xA;Thus $\overline L$ is recursive.</p>&#xA;&#xA;<p>Is my reasoning ok? This is a question from a previous exam paper.</p>&#xA;
habedi/stack-exchange-dataset
6,312
Language member explanation
<p>Given the following formal language $L$:</p>&#xA;&#xA;<p>$$ L=\{ww \mid w\in\{a,b\}^*\}$$</p>&#xA;&#xA;<p>Why is $a$ not a member of this language?</p>&#xA;&#xA;<p>So what is $\{a,b\}^*$ exactly? I thought it means $(a+b)^*$?</p>&#xA;
formal languages terminology regular expressions
1
Language member explanation -- (formal languages terminology regular expressions) <p>Given the following formal language $L$:</p>&#xA;&#xA;<p>$$ L=\{ww \mid w\in\{a,b\}^*\}$$</p>&#xA;&#xA;<p>Why is $a$ not a member of this language?</p>&#xA;&#xA;<p>So what is $\{a,b\}^*$ exactly? I thought it means $(a+b)^*$?</p>&#xA;
habedi/stack-exchange-dataset
6,319
Shifting subset sum solution by constant positive integer
<p>While reading the <a href="http://en.wikipedia.org/wiki/Subset_sum_problem" rel="nofollow">Wikipedia article about the subset sum problem</a> I came across this example: "is there a non-empty subset whose sum is zero? For example, given the set $\{ −7, −3, −2, 5, 8 \}$, the answer is yes because the subset $\{ −3, −2, 5 \}$ sums to zero". </p>&#xA;&#xA;<p>I have noticed that if we shift all the values of the set by adding a 8 to all elements we get $\{ 1, 5, 6, 13, 16 \}$ and then add the constant to the desired solution $0 + 8$, so now the question becomes is there a subset that adds up to $8$, which is not possible. My question is why does shifting the set and the solution by a positive integer "break" the solution, isn't the mathematics sound from the previous operations?</p>&#xA;
integers decision problem
1
Shifting subset sum solution by constant positive integer -- (integers decision problem) <p>While reading the <a href="http://en.wikipedia.org/wiki/Subset_sum_problem" rel="nofollow">Wikipedia article about the subset sum problem</a> I came across this example: "is there a non-empty subset whose sum is zero? For example, given the set $\{ −7, −3, −2, 5, 8 \}$, the answer is yes because the subset $\{ −3, −2, 5 \}$ sums to zero". </p>&#xA;&#xA;<p>I have noticed that if we shift all the values of the set by adding a 8 to all elements we get $\{ 1, 5, 6, 13, 16 \}$ and then add the constant to the desired solution $0 + 8$, so now the question becomes is there a subset that adds up to $8$, which is not possible. My question is why does shifting the set and the solution by a positive integer "break" the solution, isn't the mathematics sound from the previous operations?</p>&#xA;
habedi/stack-exchange-dataset
6,323
Algorithmic consequences of algebraic formula for partition function?
<p><a href="http://www.aimath.org/news/partition/brunier-ono">Bruinier and Ono</a> have found an algebraic formula for the <a href="http://en.wikipedia.org/wiki/Partition_function_%28number_theory%29#Partition_function">partition function</a>, which was widely reported to be a breakthrough. I am unable to understand the paper, but does it have any algorithmic consequences for fast computation of the partition function?</p>&#xA;
algorithms complexity theory number theory
1
Algorithmic consequences of algebraic formula for partition function? -- (algorithms complexity theory number theory) <p><a href="http://www.aimath.org/news/partition/brunier-ono">Bruinier and Ono</a> have found an algebraic formula for the <a href="http://en.wikipedia.org/wiki/Partition_function_%28number_theory%29#Partition_function">partition function</a>, which was widely reported to be a breakthrough. I am unable to understand the paper, but does it have any algorithmic consequences for fast computation of the partition function?</p>&#xA;
habedi/stack-exchange-dataset
6,325
Computing the rank of a multiset after inserting another element
<p>What is the procedure for computing the rank of a <a href="http://mathworld.wolfram.com/Multiset.html" rel="nofollow">multiset</a> after inserting an element?</p>&#xA;&#xA;<p>For instance, lets say we have a set $S = (0,1)$ containing $n = 2$ distinct elements.</p>&#xA;&#xA;<p>The multiset $M = (1,1)$ has rank $5$ because there are $4$ multisets less than it based on lexicographic ordering: $(0), (1), (0,0), (0,1)$.</p>&#xA;&#xA;<p>If we insert $0$, we get $(0,1,1)$ which has rank $8$. If $1$ were inserted instead we'd have $(1,1,1)$ with rank $9$.</p>&#xA;&#xA;<p>Is there a function $f(r,x,n)$ which takes a rank $r$, an element $x$, and $n$, and returns the new rank after inserting $x$?</p>&#xA;
algorithms combinatorics sets binary arithmetic
1
Computing the rank of a multiset after inserting another element -- (algorithms combinatorics sets binary arithmetic) <p>What is the procedure for computing the rank of a <a href="http://mathworld.wolfram.com/Multiset.html" rel="nofollow">multiset</a> after inserting an element?</p>&#xA;&#xA;<p>For instance, lets say we have a set $S = (0,1)$ containing $n = 2$ distinct elements.</p>&#xA;&#xA;<p>The multiset $M = (1,1)$ has rank $5$ because there are $4$ multisets less than it based on lexicographic ordering: $(0), (1), (0,0), (0,1)$.</p>&#xA;&#xA;<p>If we insert $0$, we get $(0,1,1)$ which has rank $8$. If $1$ were inserted instead we'd have $(1,1,1)$ with rank $9$.</p>&#xA;&#xA;<p>Is there a function $f(r,x,n)$ which takes a rank $r$, an element $x$, and $n$, and returns the new rank after inserting $x$?</p>&#xA;
habedi/stack-exchange-dataset
6,326
What are some applications of binary finite fields in CS?
<p>I was looking at details on <a href="http://en.wikipedia.org/wiki/Finite_field" rel="nofollow">finite fields</a>. Finite binary fields, e.g. $\mathbb{F_2}$, are used in CS in some places such as circuit theory [1]. </p>&#xA;&#xA;<blockquote>&#xA; <p>What are some key applications of finite fields in CS?</p>&#xA;</blockquote>&#xA;&#xA;<p>I am also looking for uses of $\mathbb{F_{2}^n}$ which <a href="http://mathworld.wolfram.com/FiniteField.html" rel="nofollow">Mathworld</a> shows can be represented as binary vectors.</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>[1] <a href="http://eccc.hpi-web.de/report/2012/133/download/" rel="nofollow">Noga Alon and Gil Cohen. On Rigid Matrices and Subspace Polynomials. Electronic Colloquium on Computational Complexity, Report No. 133 (2012)</a>.</p>&#xA;
algorithms reference request discrete mathematics applied theory
1
What are some applications of binary finite fields in CS? -- (algorithms reference request discrete mathematics applied theory) <p>I was looking at details on <a href="http://en.wikipedia.org/wiki/Finite_field" rel="nofollow">finite fields</a>. Finite binary fields, e.g. $\mathbb{F_2}$, are used in CS in some places such as circuit theory [1]. </p>&#xA;&#xA;<blockquote>&#xA; <p>What are some key applications of finite fields in CS?</p>&#xA;</blockquote>&#xA;&#xA;<p>I am also looking for uses of $\mathbb{F_{2}^n}$ which <a href="http://mathworld.wolfram.com/FiniteField.html" rel="nofollow">Mathworld</a> shows can be represented as binary vectors.</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>[1] <a href="http://eccc.hpi-web.de/report/2012/133/download/" rel="nofollow">Noga Alon and Gil Cohen. On Rigid Matrices and Subspace Polynomials. Electronic Colloquium on Computational Complexity, Report No. 133 (2012)</a>.</p>&#xA;
habedi/stack-exchange-dataset
6,327
Trigonometry in computer science
<p>What's the use of studying trigonometry in computer science? I mean, is it essential? Does it have a specific application in computer science? Because I can't seem to muster enough motivation for learning it.</p>&#xA;
education mathematical analysis applied theory
1
Trigonometry in computer science -- (education mathematical analysis applied theory) <p>What's the use of studying trigonometry in computer science? I mean, is it essential? Does it have a specific application in computer science? Because I can't seem to muster enough motivation for learning it.</p>&#xA;
habedi/stack-exchange-dataset
6,334
Tensor Product in Quantum Computation
<p>I can not understand the following equality $$\langle ij|(|0\rangle \langle 0|\otimes I)kl \rangle= \langle i|0\rangle \langle 0|k \rangle \langle j|I|l \rangle?$$</p>&#xA;&#xA;<p>Also to estimate phase $\phi$ in Nielsen &amp; Chuang book, I can not understand why &#xA;$(|0 \rangle + e^{2\pi i 2^{t-1}\phi} |1 \rangle)(|0 \rangle + e^{2\pi i2^{t-2}\phi }|1 \rangle)\cdots (|0 \rangle + e^{2\pi i 2^{0}\phi} |1 \rangle)= \displaystyle\sum_{k=0}^{2^t-1}e^{2\pi i \phi^k} |k\rangle$. </p>&#xA;&#xA;<p>Will you kindly help me? </p>&#xA;
quantum computing
1
Tensor Product in Quantum Computation -- (quantum computing) <p>I can not understand the following equality $$\langle ij|(|0\rangle \langle 0|\otimes I)kl \rangle= \langle i|0\rangle \langle 0|k \rangle \langle j|I|l \rangle?$$</p>&#xA;&#xA;<p>Also to estimate phase $\phi$ in Nielsen &amp; Chuang book, I can not understand why &#xA;$(|0 \rangle + e^{2\pi i 2^{t-1}\phi} |1 \rangle)(|0 \rangle + e^{2\pi i2^{t-2}\phi }|1 \rangle)\cdots (|0 \rangle + e^{2\pi i 2^{0}\phi} |1 \rangle)= \displaystyle\sum_{k=0}^{2^t-1}e^{2\pi i \phi^k} |k\rangle$. </p>&#xA;&#xA;<p>Will you kindly help me? </p>&#xA;
habedi/stack-exchange-dataset
6,342
Proof that a randomly built binary search tree has logarithmic height
<p>How do you prove that the expected height of a randomly built <a href="http://en.wikipedia.org/wiki/Binary_search_tree">binary search tree</a> with $n$ nodes is $O(\log n)$? There is a proof in CLRS <em>Introduction to Algorithms</em> (chapter 12.4), but I don't understand it.</p>&#xA;
data structures algorithm analysis binary trees search trees average case
1
Proof that a randomly built binary search tree has logarithmic height -- (data structures algorithm analysis binary trees search trees average case) <p>How do you prove that the expected height of a randomly built <a href="http://en.wikipedia.org/wiki/Binary_search_tree">binary search tree</a> with $n$ nodes is $O(\log n)$? There is a proof in CLRS <em>Introduction to Algorithms</em> (chapter 12.4), but I don't understand it.</p>&#xA;
habedi/stack-exchange-dataset
6,343
Can you have three consecutive black nodes in red-black search tree?
<p>Suppose I am making a red-black search tree, and in my right subtree, I have a black node, then a red node, and it has two black children, the black children further black childrens. As such a lemma has been made that red-black trees with $n$ internal nodes have height at most $2\log(n+1)$, would this proof still hold for such a black tree?</p>&#xA;
data structures binary trees search trees
1
Can you have three consecutive black nodes in red-black search tree? -- (data structures binary trees search trees) <p>Suppose I am making a red-black search tree, and in my right subtree, I have a black node, then a red node, and it has two black children, the black children further black childrens. As such a lemma has been made that red-black trees with $n$ internal nodes have height at most $2\log(n+1)$, would this proof still hold for such a black tree?</p>&#xA;
habedi/stack-exchange-dataset
6,347
How do you go about designing a vector processor architecture for the sum of matrix products?
<p>The following equation is a matrix expression where $B_i$ and $C_i^T$ are $n\times n$ matrices and k is a positive integer:</p>&#xA;&#xA;<p>$$P = \sum_{i=1}^k B_i C_i^T $$</p>&#xA;&#xA;<p>So $P = B_1 C_1^T + B_2 C_2^T + \cdots +B_k C_k^T $</p>&#xA;&#xA;<p>If $B_i $ and $C_i$ are $n\times n$ matrices themselves, we have a total of 2 $\times$ k matrices that some how need to be stored in this vector architecture. </p>&#xA;&#xA;<p>So this means P will end up being an $n\times n$ matrix after all the computation has completed. </p>&#xA;&#xA;<p>What is the simplest possible vector processor architecture that is required to perform the matrix computation above?</p>&#xA;&#xA;<p>Is there any literature or articles out there that discuss how this can be done?</p>&#xA;&#xA;<p>Would appreciate all / any advise </p>&#xA;
computer architecture parallel computing matrices
1
How do you go about designing a vector processor architecture for the sum of matrix products? -- (computer architecture parallel computing matrices) <p>The following equation is a matrix expression where $B_i$ and $C_i^T$ are $n\times n$ matrices and k is a positive integer:</p>&#xA;&#xA;<p>$$P = \sum_{i=1}^k B_i C_i^T $$</p>&#xA;&#xA;<p>So $P = B_1 C_1^T + B_2 C_2^T + \cdots +B_k C_k^T $</p>&#xA;&#xA;<p>If $B_i $ and $C_i$ are $n\times n$ matrices themselves, we have a total of 2 $\times$ k matrices that some how need to be stored in this vector architecture. </p>&#xA;&#xA;<p>So this means P will end up being an $n\times n$ matrix after all the computation has completed. </p>&#xA;&#xA;<p>What is the simplest possible vector processor architecture that is required to perform the matrix computation above?</p>&#xA;&#xA;<p>Is there any literature or articles out there that discuss how this can be done?</p>&#xA;&#xA;<p>Would appreciate all / any advise </p>&#xA;
habedi/stack-exchange-dataset
6,348
Why can't we use a hash tables for collision resolving in hash tables?
<p>To prevent collisions, hash tables with open addressing use a methodology to chain the contents. Why can't we use another hash table allocated to each slot of the primary hash table?</p>&#xA;
data structures hash tables
1
Why can't we use a hash tables for collision resolving in hash tables? -- (data structures hash tables) <p>To prevent collisions, hash tables with open addressing use a methodology to chain the contents. Why can't we use another hash table allocated to each slot of the primary hash table?</p>&#xA;
habedi/stack-exchange-dataset
6,357
What precisely is infinite ambiguity in a grammar?
<p>From what I've read, an example of infinite ambiguity is usually given in a form of a loop:</p>&#xA;&#xA;<p>$S \rightarrow aA \\&#xA;A \rightarrow B \\&#xA;B \rightarrow A \\&#xA;B \rightarrow b$</p>&#xA;&#xA;<p>But a grammar is called <em>ambiguous</em> if there's more than 1 way to derive the input string &omega;. What if I then take this well-known ambiguous grammar:</p>&#xA;&#xA;<p>$S \rightarrow SSS \\&#xA;S \rightarrow SS \\&#xA;S \rightarrow b$</p>&#xA;&#xA;<p>and extend it with $S \rightarrow \epsilon$&#xA;so that for any member of $\left\{ b^n \middle| n \geq 0\right\}$ there's infinitely many ways to derive it? Does this make the grammar <em>infinitely</em> ambiguous?</p>&#xA;
terminology formal grammars ambiguity
1
What precisely is infinite ambiguity in a grammar? -- (terminology formal grammars ambiguity) <p>From what I've read, an example of infinite ambiguity is usually given in a form of a loop:</p>&#xA;&#xA;<p>$S \rightarrow aA \\&#xA;A \rightarrow B \\&#xA;B \rightarrow A \\&#xA;B \rightarrow b$</p>&#xA;&#xA;<p>But a grammar is called <em>ambiguous</em> if there's more than 1 way to derive the input string &omega;. What if I then take this well-known ambiguous grammar:</p>&#xA;&#xA;<p>$S \rightarrow SSS \\&#xA;S \rightarrow SS \\&#xA;S \rightarrow b$</p>&#xA;&#xA;<p>and extend it with $S \rightarrow \epsilon$&#xA;so that for any member of $\left\{ b^n \middle| n \geq 0\right\}$ there's infinitely many ways to derive it? Does this make the grammar <em>infinitely</em> ambiguous?</p>&#xA;
habedi/stack-exchange-dataset