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
1,143
Finding a 5-Pointed Star in polynomial time
<p><strong>I want to establish that this is part of my homework for a course I am currently taking. I am looking for some assistance in proceeding, NOT AN ANSWER.</strong></p>&#xA;&#xA;<p>This is the question in question:</p>&#xA;&#xA;<blockquote>&#xA; <p>A 5-pointed-star in an undirected graph is a 5-clique. Show that&#xA; 5-POINTED-STAR $\in P$, where 5-POINTED-STAR = $\{ &lt;G&gt;$ $: G$ contains a&#xA; 5-pointed-star as a subgraph $\}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>Where a clique is CLIQUE = $\{(G, k) : G$ is an undirected graph $G$ with a $k$-clique $\}$.</p>&#xA;&#xA;<p>Now my problem is that this appears to be solving the CLIQUE problem, determining whether a graph contains a clique with the additional constraint of having to determine that the CLIQUE forms a 5-pointed star. This seems to involve some geometric calculation based on knowledge of a <a href="http://www.ehow.com/about_4606571_geometry-fivepoint-star.html">5-pointed star</a>. However, in Michael Sipser's <em>Theory of Computation</em>, pg 268, there is a proof showing that CLIQUE is in $NP$ and on page 270 notes that,</p>&#xA;&#xA;<blockquote>&#xA; <p><em>We have presented examples of languages, such as HAMPATH and CLIQUE,&#xA; <strong>that are members of NP but that are not known to be in $P$.</em></strong> [emphasis added]</p>&#xA;</blockquote>&#xA;&#xA;<p>If CLIQUE is not in $P$, why five pointed star be in $P$? Is there something I'm not seeing?&#xA;<strong>Remember, this is a HOMEWORK PROBLEM and A DIRECT ANSWER WOULD NOT BE APPRECIATED.</strong> Thanks!</p>&#xA;
complexity theory time complexity
1
Finding a 5-Pointed Star in polynomial time -- (complexity theory time complexity) <p><strong>I want to establish that this is part of my homework for a course I am currently taking. I am looking for some assistance in proceeding, NOT AN ANSWER.</strong></p>&#xA;&#xA;<p>This is the question in question:</p>&#xA;&#xA;<blockquote>&#xA; <p>A 5-pointed-star in an undirected graph is a 5-clique. Show that&#xA; 5-POINTED-STAR $\in P$, where 5-POINTED-STAR = $\{ &lt;G&gt;$ $: G$ contains a&#xA; 5-pointed-star as a subgraph $\}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>Where a clique is CLIQUE = $\{(G, k) : G$ is an undirected graph $G$ with a $k$-clique $\}$.</p>&#xA;&#xA;<p>Now my problem is that this appears to be solving the CLIQUE problem, determining whether a graph contains a clique with the additional constraint of having to determine that the CLIQUE forms a 5-pointed star. This seems to involve some geometric calculation based on knowledge of a <a href="http://www.ehow.com/about_4606571_geometry-fivepoint-star.html">5-pointed star</a>. However, in Michael Sipser's <em>Theory of Computation</em>, pg 268, there is a proof showing that CLIQUE is in $NP$ and on page 270 notes that,</p>&#xA;&#xA;<blockquote>&#xA; <p><em>We have presented examples of languages, such as HAMPATH and CLIQUE,&#xA; <strong>that are members of NP but that are not known to be in $P$.</em></strong> [emphasis added]</p>&#xA;</blockquote>&#xA;&#xA;<p>If CLIQUE is not in $P$, why five pointed star be in $P$? Is there something I'm not seeing?&#xA;<strong>Remember, this is a HOMEWORK PROBLEM and A DIRECT ANSWER WOULD NOT BE APPRECIATED.</strong> Thanks!</p>&#xA;
habedi/stack-exchange-dataset
1,154
How can I measure the usability of a catalogue?
<p>This question might seems vague but heres the context:</p>&#xA;&#xA;<p>When we are focusing on HCI we would most likely be interested on knowing first how the user usually deals with a certain object. We then try to see how our system could take away one of the tasks he would do himself and try to do it itself. </p>&#xA;&#xA;<ul>&#xA;<li><p>The object of my interest here is a simple paper catalogue. How would you measure its usability (paper one). </p></li>&#xA;<li><p>Then, how would you map it to a system interface? How would you measure the usability now on the system?</p></li>&#xA;<li><p>How would you compare the two usabilities measures?</p></li>&#xA;</ul>&#xA;&#xA;<p>This question narrows down this approach which is suggested on Stones book - User Interface and Evaluation. </p>&#xA;&#xA;<p>What the catalogue is about is not the point, that why I left it without a description: To avoid suggestions trying to measure what the catalogue is about. My focus here is on the particular mapping of this kind of object on the real world as a simple paper and when it is mapped to a system interface. Assume the catalogue to consist of rows and tables, where each matching row and table gives you a suggestion and you must first reason about each row and each column to see if it suits you (Perhaps you would suggest another template for the catalogue?).</p>&#xA;
empirical research modelling hci
1
How can I measure the usability of a catalogue? -- (empirical research modelling hci) <p>This question might seems vague but heres the context:</p>&#xA;&#xA;<p>When we are focusing on HCI we would most likely be interested on knowing first how the user usually deals with a certain object. We then try to see how our system could take away one of the tasks he would do himself and try to do it itself. </p>&#xA;&#xA;<ul>&#xA;<li><p>The object of my interest here is a simple paper catalogue. How would you measure its usability (paper one). </p></li>&#xA;<li><p>Then, how would you map it to a system interface? How would you measure the usability now on the system?</p></li>&#xA;<li><p>How would you compare the two usabilities measures?</p></li>&#xA;</ul>&#xA;&#xA;<p>This question narrows down this approach which is suggested on Stones book - User Interface and Evaluation. </p>&#xA;&#xA;<p>What the catalogue is about is not the point, that why I left it without a description: To avoid suggestions trying to measure what the catalogue is about. My focus here is on the particular mapping of this kind of object on the real world as a simple paper and when it is mapped to a system interface. Assume the catalogue to consist of rows and tables, where each matching row and table gives you a suggestion and you must first reason about each row and each column to see if it suits you (Perhaps you would suggest another template for the catalogue?).</p>&#xA;
habedi/stack-exchange-dataset
1,176
HALF CLIQUE - NP Complete Problem
<p>Let me start off by noting <strong>this is a homework problem, please provide only advice and related observations, NO DIRECT ANSWERS please</strong>. With that said, here is the problem I am looking at:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let HALF-CLIQUE = { $\langle G \rangle$ | $G$ is an undirected graph having a complete&#xA; subgraph with at least $n/2$ nodes, where n is the number of nodes in $G$&#xA; }. Show that HALF-CLIQUE is NP-complete.</p>&#xA;</blockquote>&#xA;&#xA;<p>Also, I know the following:</p>&#xA;&#xA;<ul>&#xA;<li>In terms of this problem a <em>clique</em>, is defined as an undirected subgraph of the input graph, wherein every two nodes are connected by an edge. A <em>$k$-clique</em> is a clique that contains $k$ nodes.</li>&#xA;<li>According to our textbook, Michael Sipser's "<em>Introduction to the Theory of Computation</em>", pg 268, that the problem CLIQUE = {$\langle G,k\rangle$ | $G$ is an undirected graph with a $k$-clique} is in NP</li>&#xA;<li>Furthermore, according to the same source (on pg 283) notes that CLIQUE is in NP-Complpete (thus also obviously in NP).</li>&#xA;</ul>&#xA;&#xA;<p>I think I have the kernel of an answer here, however I could use <em>some indication of what is wrong with it or any related points that might be relevant to an answer</em>. This is the general idea I have so far,</p>&#xA;&#xA;<blockquote>&#xA; <p>Ok, I'd first note that a certificate would simply be a HALF-QLIQUE of $\text{size} \geq n/2$. Now it appears that what I would need to do is to create a verifier that is a polynomial time reduction from CLIQUE (which we know is NP-Complete) to HALF-CLIQUE. My idea would be that this would be done by creating a Turing machine which runs the turing machine verifier in the book for CLIQUE with the additional constraint for HALF-CLIQUE.</p>&#xA;</blockquote>&#xA;&#xA;<p>This sounds correct to me, but I don't really trust myself yet in this subject. Once again, I would like to remind everyone <strong>this is a HOMEWORK PROBLEM</strong> so please try to avoid answering the question. Any guidance which falls short of this would be most welcome! </p>&#xA;
complexity theory np complete reductions
1
HALF CLIQUE - NP Complete Problem -- (complexity theory np complete reductions) <p>Let me start off by noting <strong>this is a homework problem, please provide only advice and related observations, NO DIRECT ANSWERS please</strong>. With that said, here is the problem I am looking at:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let HALF-CLIQUE = { $\langle G \rangle$ | $G$ is an undirected graph having a complete&#xA; subgraph with at least $n/2$ nodes, where n is the number of nodes in $G$&#xA; }. Show that HALF-CLIQUE is NP-complete.</p>&#xA;</blockquote>&#xA;&#xA;<p>Also, I know the following:</p>&#xA;&#xA;<ul>&#xA;<li>In terms of this problem a <em>clique</em>, is defined as an undirected subgraph of the input graph, wherein every two nodes are connected by an edge. A <em>$k$-clique</em> is a clique that contains $k$ nodes.</li>&#xA;<li>According to our textbook, Michael Sipser's "<em>Introduction to the Theory of Computation</em>", pg 268, that the problem CLIQUE = {$\langle G,k\rangle$ | $G$ is an undirected graph with a $k$-clique} is in NP</li>&#xA;<li>Furthermore, according to the same source (on pg 283) notes that CLIQUE is in NP-Complpete (thus also obviously in NP).</li>&#xA;</ul>&#xA;&#xA;<p>I think I have the kernel of an answer here, however I could use <em>some indication of what is wrong with it or any related points that might be relevant to an answer</em>. This is the general idea I have so far,</p>&#xA;&#xA;<blockquote>&#xA; <p>Ok, I'd first note that a certificate would simply be a HALF-QLIQUE of $\text{size} \geq n/2$. Now it appears that what I would need to do is to create a verifier that is a polynomial time reduction from CLIQUE (which we know is NP-Complete) to HALF-CLIQUE. My idea would be that this would be done by creating a Turing machine which runs the turing machine verifier in the book for CLIQUE with the additional constraint for HALF-CLIQUE.</p>&#xA;</blockquote>&#xA;&#xA;<p>This sounds correct to me, but I don't really trust myself yet in this subject. Once again, I would like to remind everyone <strong>this is a HOMEWORK PROBLEM</strong> so please try to avoid answering the question. Any guidance which falls short of this would be most welcome! </p>&#xA;
habedi/stack-exchange-dataset
1,200
How to deal with arrays during Hoare-style correctness proofs
<p>In the discussion around <a href="https://cs.stackexchange.com/q/1157/98">this question</a>, Gilles mentions correctly that any correctness proof of an algorithm that uses arrays has to prove that there are no out-of-bounds array accesses; depending on the runtime model, this would cause a runtime error or access to non-array elements.</p>&#xA;&#xA;<p>One common technique to perform such correctness proofs (at least in undergrad studies and probably in automated verification) is by using <a href="https://en.wikipedia.org/wiki/Hoare_logic" rel="nofollow noreferrer">Hoare logic</a>. I am not aware that the standard set of rules containes anything relating to arrays; they seem to be restricted to monadic variables.</p>&#xA;&#xA;<p>I can imagine adding axioms of the form</p>&#xA;&#xA;<p>$\qquad \displaystyle \frac{}{\{0 \leq i \lt A.\mathrm{length} \land {P[A[i]/E]} \}\ A[i] := E;\ \{P\}}$</p>&#xA;&#xA;<p>However, it is not clear to me how you would deal with an array access on the right hand side, i.e. if it is part of a complex expression $E$ in some statement $x := E$.</p>&#xA;&#xA;<blockquote>&#xA; <p>How can arrays accesses be modelled in Hoare logic so that the absence of invalid accesses can and has to be proven for program correctness?</p>&#xA;</blockquote>&#xA;&#xA;<p>Answers may assume that we disallow array elements to be used in statements other than $A[i] := E$ or as part of some $E$ in $x := E$ as this does not restrict expressiveness; we can always assign a temporary variable the desired value, i.e. write $t := A[i];\ \mathtt{if} ( t &gt; 0 ) \dots$ instead of $\mathtt{if} ( A[i] &gt; 0 )\dots$.</p>&#xA;
proof techniques semantics arrays hoare logic software verification
1
How to deal with arrays during Hoare-style correctness proofs -- (proof techniques semantics arrays hoare logic software verification) <p>In the discussion around <a href="https://cs.stackexchange.com/q/1157/98">this question</a>, Gilles mentions correctly that any correctness proof of an algorithm that uses arrays has to prove that there are no out-of-bounds array accesses; depending on the runtime model, this would cause a runtime error or access to non-array elements.</p>&#xA;&#xA;<p>One common technique to perform such correctness proofs (at least in undergrad studies and probably in automated verification) is by using <a href="https://en.wikipedia.org/wiki/Hoare_logic" rel="nofollow noreferrer">Hoare logic</a>. I am not aware that the standard set of rules containes anything relating to arrays; they seem to be restricted to monadic variables.</p>&#xA;&#xA;<p>I can imagine adding axioms of the form</p>&#xA;&#xA;<p>$\qquad \displaystyle \frac{}{\{0 \leq i \lt A.\mathrm{length} \land {P[A[i]/E]} \}\ A[i] := E;\ \{P\}}$</p>&#xA;&#xA;<p>However, it is not clear to me how you would deal with an array access on the right hand side, i.e. if it is part of a complex expression $E$ in some statement $x := E$.</p>&#xA;&#xA;<blockquote>&#xA; <p>How can arrays accesses be modelled in Hoare logic so that the absence of invalid accesses can and has to be proven for program correctness?</p>&#xA;</blockquote>&#xA;&#xA;<p>Answers may assume that we disallow array elements to be used in statements other than $A[i] := E$ or as part of some $E$ in $x := E$ as this does not restrict expressiveness; we can always assign a temporary variable the desired value, i.e. write $t := A[i];\ \mathtt{if} ( t &gt; 0 ) \dots$ instead of $\mathtt{if} ( A[i] &gt; 0 )\dots$.</p>&#xA;
habedi/stack-exchange-dataset
1,218
Lower bounds of calculating a function of a set
<p>Having a set $A$ of $n$ elements, let's say I want to calculate a function $f(A)$ that is sensitive to all parts of the input, i.e. depends on very member of $A$ (i.e. it is possible to change any member of $A$ to something else to obtain a new input $A&#39;$ s.t. value of $f$ on $A$ and $A&#39;$ are different).</p>&#xA;&#xA;<p>For example, $f$ could be the sum or the average.</p>&#xA;&#xA;<p>Is there a result that proves that, under some conditions, the time necessary to a deterministic Turing machine to compute $f$ will be $\Omega(n)$?</p>&#xA;
complexity theory
1
Lower bounds of calculating a function of a set -- (complexity theory) <p>Having a set $A$ of $n$ elements, let's say I want to calculate a function $f(A)$ that is sensitive to all parts of the input, i.e. depends on very member of $A$ (i.e. it is possible to change any member of $A$ to something else to obtain a new input $A&#39;$ s.t. value of $f$ on $A$ and $A&#39;$ are different).</p>&#xA;&#xA;<p>For example, $f$ could be the sum or the average.</p>&#xA;&#xA;<p>Is there a result that proves that, under some conditions, the time necessary to a deterministic Turing machine to compute $f$ will be $\Omega(n)$?</p>&#xA;
habedi/stack-exchange-dataset
1,223
The space complexity of recognising Watson-Crick palindromes
<p>I have the following algorithmic problem:</p>&#xA;&#xA;<blockquote>&#xA; <p>Determine the space Turing complexity of recognizing DNA strings that are Watson-Crick palindromes. </p>&#xA;</blockquote>&#xA;&#xA;<p>Watson-Crick palindromes are strings whose reversed complement is the original string. The <em>complement</em> is defined letter-wise, inspired by DNA: A is the complement of T and C is the complement of G. A simple example for a WC-palindrome is ACGT.</p>&#xA;&#xA;<p>I've come up with two ways of solving this.</p>&#xA;&#xA;<p><strong>One requires $\mathcal{O}(n)$ space.</strong></p>&#xA;&#xA;<ul>&#xA;<li>Once the machine is done reading the input. The input tape must be copied to the work tape in reverse order. </li>&#xA;<li>The machine will then read the input and work tapes from the left and compare each entry to verify the cell in the work tape is the compliment of the cell in the input. This requires $\mathcal{O}(n)$ space. </li>&#xA;</ul>&#xA;&#xA;<p><strong>The other requires $\mathcal{O}(\log n)$ space.</strong></p>&#xA;&#xA;<ul>&#xA;<li>While reading the input. Count the number of entries on the input tape.</li>&#xA;<li>When the input tape is done reading&#xA;<ul>&#xA;<li>copy the complement of the letter onto the work tape</li>&#xA;<li>copy the letter L to the end of the work tape</li>&#xA;</ul></li>&#xA;<li>(Loop point)If the counter = 0, clear the worktape and write yes, then halt</li>&#xA;<li>If the input tape reads L&#xA;<ul>&#xA;<li>Move the input head to the left by the number of times indicated by the counter (requires a second counter)</li>&#xA;</ul></li>&#xA;<li>If the input tape reads R &#xA;<ul>&#xA;<li>Move the input head to the right by the number of times indicated by the counter (requires a second counter)</li>&#xA;</ul></li>&#xA;<li>If the cell that holds the value on the worktape matches the current cell on the input tape&#xA;<ul>&#xA;<li>decrement the counter by two</li>&#xA;<li>Move one to the left or right depending if R or L is on the worktape respectively</li>&#xA;<li>copy the Complement of L or R to the worktape in place of the current L or R</li>&#xA;<li>continue the loop</li>&#xA;</ul></li>&#xA;<li>If values dont match, clear the worktape and write no, then halt</li>&#xA;</ul>&#xA;&#xA;<p>This comes out to about $2\log n+2$ space for storing both counters, the current complement, and the value L or R.</p>&#xA;&#xA;<p><strong>My issue</strong></p>&#xA;&#xA;<p>The first one requires both linear time and space. The second one requires $\frac{n^2}{2}$ time and $\log n$ space. I was given the problem from the quote and came up with these two approaches, but I don't know which one to go with. I just need to give the space complexity of the problem. </p>&#xA;&#xA;<p><strong>The reason I'm confused</strong></p>&#xA;&#xA;<p>I would tend to say the second one is the best option since it's better in terms of time, but that answer only comes from me getting lucky and coming up with an algorithm. It seems like if I want to give the space complexity of something, it wouldn't require luck in coming up with the right algorithm. Am I missing something? Should I even be coming up with a solution to the problem to answer the space complexity?</p>&#xA;
algorithms algorithm analysis turing machines space complexity
1
The space complexity of recognising Watson-Crick palindromes -- (algorithms algorithm analysis turing machines space complexity) <p>I have the following algorithmic problem:</p>&#xA;&#xA;<blockquote>&#xA; <p>Determine the space Turing complexity of recognizing DNA strings that are Watson-Crick palindromes. </p>&#xA;</blockquote>&#xA;&#xA;<p>Watson-Crick palindromes are strings whose reversed complement is the original string. The <em>complement</em> is defined letter-wise, inspired by DNA: A is the complement of T and C is the complement of G. A simple example for a WC-palindrome is ACGT.</p>&#xA;&#xA;<p>I've come up with two ways of solving this.</p>&#xA;&#xA;<p><strong>One requires $\mathcal{O}(n)$ space.</strong></p>&#xA;&#xA;<ul>&#xA;<li>Once the machine is done reading the input. The input tape must be copied to the work tape in reverse order. </li>&#xA;<li>The machine will then read the input and work tapes from the left and compare each entry to verify the cell in the work tape is the compliment of the cell in the input. This requires $\mathcal{O}(n)$ space. </li>&#xA;</ul>&#xA;&#xA;<p><strong>The other requires $\mathcal{O}(\log n)$ space.</strong></p>&#xA;&#xA;<ul>&#xA;<li>While reading the input. Count the number of entries on the input tape.</li>&#xA;<li>When the input tape is done reading&#xA;<ul>&#xA;<li>copy the complement of the letter onto the work tape</li>&#xA;<li>copy the letter L to the end of the work tape</li>&#xA;</ul></li>&#xA;<li>(Loop point)If the counter = 0, clear the worktape and write yes, then halt</li>&#xA;<li>If the input tape reads L&#xA;<ul>&#xA;<li>Move the input head to the left by the number of times indicated by the counter (requires a second counter)</li>&#xA;</ul></li>&#xA;<li>If the input tape reads R &#xA;<ul>&#xA;<li>Move the input head to the right by the number of times indicated by the counter (requires a second counter)</li>&#xA;</ul></li>&#xA;<li>If the cell that holds the value on the worktape matches the current cell on the input tape&#xA;<ul>&#xA;<li>decrement the counter by two</li>&#xA;<li>Move one to the left or right depending if R or L is on the worktape respectively</li>&#xA;<li>copy the Complement of L or R to the worktape in place of the current L or R</li>&#xA;<li>continue the loop</li>&#xA;</ul></li>&#xA;<li>If values dont match, clear the worktape and write no, then halt</li>&#xA;</ul>&#xA;&#xA;<p>This comes out to about $2\log n+2$ space for storing both counters, the current complement, and the value L or R.</p>&#xA;&#xA;<p><strong>My issue</strong></p>&#xA;&#xA;<p>The first one requires both linear time and space. The second one requires $\frac{n^2}{2}$ time and $\log n$ space. I was given the problem from the quote and came up with these two approaches, but I don't know which one to go with. I just need to give the space complexity of the problem. </p>&#xA;&#xA;<p><strong>The reason I'm confused</strong></p>&#xA;&#xA;<p>I would tend to say the second one is the best option since it's better in terms of time, but that answer only comes from me getting lucky and coming up with an algorithm. It seems like if I want to give the space complexity of something, it wouldn't require luck in coming up with the right algorithm. Am I missing something? Should I even be coming up with a solution to the problem to answer the space complexity?</p>&#xA;
habedi/stack-exchange-dataset
1,225
Attack on hash functions that do not satisfy the one-way property
<p>I am revising for a computer security course and I am stuck on one of the past questions. Here is it:</p>&#xA;&#xA;<blockquote>&#xA; <p>Alice ($A$) wants to send a short message $M$ to Bob ($B$) using a shared secret $S_{ab}$ to authenticate that the message has come from her. She proposes to send a single message with two pieces:&#xA; $$ A \to B: \quad M, h(M \mathbin\parallel S_{ab})$$&#xA; where $h$ is a hash function and $\parallel$ denotes concatenation.</p>&#xA; &#xA; <ol>&#xA; <li>Explain carefully what Bob does to check that the message has come from Alice, and why (apart from properties of $h$) he may believe this.</li>&#xA; <li>Suppose that $h$ does not satisfy the one-way property and it is possible to generate pre-images. Explain what an attacker can do and how.</li>&#xA; <li>If generating pre-images is comparatively time-consuming, suggest a simple countermeasure to improve the protocol without changing $h$.</li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<p>I think I know the first one. Bob needs to take a hash of the received message along with his shared key and compare that hash with the hash received from Alice, if they match then this should prove Alice sent it.</p>&#xA;&#xA;<p>I am not sure about the second two questions though. For the second one, would the answer be that an attacker can simply obtain the original message given a hash? I'm not sure how that would be done though.</p>&#xA;
cryptography hash one way functions
1
Attack on hash functions that do not satisfy the one-way property -- (cryptography hash one way functions) <p>I am revising for a computer security course and I am stuck on one of the past questions. Here is it:</p>&#xA;&#xA;<blockquote>&#xA; <p>Alice ($A$) wants to send a short message $M$ to Bob ($B$) using a shared secret $S_{ab}$ to authenticate that the message has come from her. She proposes to send a single message with two pieces:&#xA; $$ A \to B: \quad M, h(M \mathbin\parallel S_{ab})$$&#xA; where $h$ is a hash function and $\parallel$ denotes concatenation.</p>&#xA; &#xA; <ol>&#xA; <li>Explain carefully what Bob does to check that the message has come from Alice, and why (apart from properties of $h$) he may believe this.</li>&#xA; <li>Suppose that $h$ does not satisfy the one-way property and it is possible to generate pre-images. Explain what an attacker can do and how.</li>&#xA; <li>If generating pre-images is comparatively time-consuming, suggest a simple countermeasure to improve the protocol without changing $h$.</li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<p>I think I know the first one. Bob needs to take a hash of the received message along with his shared key and compare that hash with the hash received from Alice, if they match then this should prove Alice sent it.</p>&#xA;&#xA;<p>I am not sure about the second two questions though. For the second one, would the answer be that an attacker can simply obtain the original message given a hash? I'm not sure how that would be done though.</p>&#xA;
habedi/stack-exchange-dataset
1,229
Why does the splay tree rotation algorithm take into account both the parent and grandparent node?
<p>I don't quite understand why the rotation in the splay tree data structure is taking into account not only the parent of the rating node, but also the grandparent (zig-zag and zig-zig operation). Why would the following not work:</p>&#xA;&#xA;<p>As we insert, for instance, a new node to the tree, we check whether we insert into the left or right subtree. If we insert into the left, we rotate the result RIGHT, and vice versa for right subtree. Recursively it would be sth like this</p>&#xA;&#xA;<pre><code>Tree insert(Tree root, Key k){&#xA; if(k &lt; root.key){&#xA; root.setLeft(insert(root.getLeft(), key);&#xA; return rotateRight(root);&#xA; }&#xA; //vice versa for right subtree&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>That should avoid the whole "splay" procedure, don't you think?</p>&#xA;
algorithms data structures binary trees search trees
1
Why does the splay tree rotation algorithm take into account both the parent and grandparent node? -- (algorithms data structures binary trees search trees) <p>I don't quite understand why the rotation in the splay tree data structure is taking into account not only the parent of the rating node, but also the grandparent (zig-zag and zig-zig operation). Why would the following not work:</p>&#xA;&#xA;<p>As we insert, for instance, a new node to the tree, we check whether we insert into the left or right subtree. If we insert into the left, we rotate the result RIGHT, and vice versa for right subtree. Recursively it would be sth like this</p>&#xA;&#xA;<pre><code>Tree insert(Tree root, Key k){&#xA; if(k &lt; root.key){&#xA; root.setLeft(insert(root.getLeft(), key);&#xA; return rotateRight(root);&#xA; }&#xA; //vice versa for right subtree&#xA;}&#xA;</code></pre>&#xA;&#xA;<p>That should avoid the whole "splay" procedure, don't you think?</p>&#xA;
habedi/stack-exchange-dataset
1,231
Efficiently selecting the median and elements to its left and right
<p>Suppose we have a set $S = \{ a_1,a_2,a_3,\ldots , a_N \}$ of $N$ coders.</p>&#xA;&#xA;<p>Each Coders has rating $R_i$ and the number of gold medals $E_i$, they had won so far.</p>&#xA;&#xA;<p>A Software Company wants to hire exactly three coders to develop an application.</p>&#xA;&#xA;<p>For hiring three coders, they developed the following strategy:</p>&#xA;&#xA;<ol>&#xA;<li>They first arrange the coders in ascending order of ratings and descending order of gold medals.</li>&#xA;<li>From this arranged list, they select the three of the middle coders.&#xA;E.g., if the arranged list is $(a_5,a_2,a_3,a_1,a_4)$ they select $(a_2,a_3,a_1)$ coders.</li>&#xA;</ol>&#xA;&#xA;<p>Now we have to help company by writing a program for this task.</p>&#xA;&#xA;<p><strong>Input:</strong></p>&#xA;&#xA;<p>The first line contains $N$, i.e. the number of coders.</p>&#xA;&#xA;<p>Then the second line contains the ratings $R_i$ of $i$th coder.</p>&#xA;&#xA;<p>The third line contains the number of gold medals bagged by the $i$th coder.</p>&#xA;&#xA;<p><strong>Output:</strong></p>&#xA;&#xA;<p>Display only one line that contains the sum of gold medals earned by the three coders the company will select.</p>&#xA;
algorithms algorithm design
1
Efficiently selecting the median and elements to its left and right -- (algorithms algorithm design) <p>Suppose we have a set $S = \{ a_1,a_2,a_3,\ldots , a_N \}$ of $N$ coders.</p>&#xA;&#xA;<p>Each Coders has rating $R_i$ and the number of gold medals $E_i$, they had won so far.</p>&#xA;&#xA;<p>A Software Company wants to hire exactly three coders to develop an application.</p>&#xA;&#xA;<p>For hiring three coders, they developed the following strategy:</p>&#xA;&#xA;<ol>&#xA;<li>They first arrange the coders in ascending order of ratings and descending order of gold medals.</li>&#xA;<li>From this arranged list, they select the three of the middle coders.&#xA;E.g., if the arranged list is $(a_5,a_2,a_3,a_1,a_4)$ they select $(a_2,a_3,a_1)$ coders.</li>&#xA;</ol>&#xA;&#xA;<p>Now we have to help company by writing a program for this task.</p>&#xA;&#xA;<p><strong>Input:</strong></p>&#xA;&#xA;<p>The first line contains $N$, i.e. the number of coders.</p>&#xA;&#xA;<p>Then the second line contains the ratings $R_i$ of $i$th coder.</p>&#xA;&#xA;<p>The third line contains the number of gold medals bagged by the $i$th coder.</p>&#xA;&#xA;<p><strong>Output:</strong></p>&#xA;&#xA;<p>Display only one line that contains the sum of gold medals earned by the three coders the company will select.</p>&#xA;
habedi/stack-exchange-dataset
1,234
Classification of intractable/tractable satisfiability problem variants
<p>Recently I found in a paper [1] a special symmetric version of SAT called the <strong>2/2/4-SAT</strong>. But there are many $\text{NP}$-complete variants out there, for example: <strong>MONOTONE NAE-3SAT</strong>, <strong>MONOTONE 1-IN-3-SAT</strong>, ...</p>&#xA;&#xA;<p>Some other variants are tractable: $2$-$\text{SAT}$, Planar-NAE-$\text{SAT}$, ...</p>&#xA;&#xA;<p>Are there survey papers (or web pages) that classify all the (weird) $\text{SAT}$ variants that have been proved to be $\text{NP}$-complete (or in $\text{P}$) ?</p>&#xA;&#xA;<hr>&#xA;&#xA;<ol>&#xA;<li><a href="https://www.aaai.org/Papers/AAAI/1986/AAAI86-027.pdf">Finding a shortest solution for the $N$x$N$ extension of the 15-Puzzle is intractable</a> by D. Ratner and M. Warmuth (1986)</li>&#xA;</ol>&#xA;
complexity theory reference request satisfiability
1
Classification of intractable/tractable satisfiability problem variants -- (complexity theory reference request satisfiability) <p>Recently I found in a paper [1] a special symmetric version of SAT called the <strong>2/2/4-SAT</strong>. But there are many $\text{NP}$-complete variants out there, for example: <strong>MONOTONE NAE-3SAT</strong>, <strong>MONOTONE 1-IN-3-SAT</strong>, ...</p>&#xA;&#xA;<p>Some other variants are tractable: $2$-$\text{SAT}$, Planar-NAE-$\text{SAT}$, ...</p>&#xA;&#xA;<p>Are there survey papers (or web pages) that classify all the (weird) $\text{SAT}$ variants that have been proved to be $\text{NP}$-complete (or in $\text{P}$) ?</p>&#xA;&#xA;<hr>&#xA;&#xA;<ol>&#xA;<li><a href="https://www.aaai.org/Papers/AAAI/1986/AAAI86-027.pdf">Finding a shortest solution for the $N$x$N$ extension of the 15-Puzzle is intractable</a> by D. Ratner and M. Warmuth (1986)</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
1,236
How does variance in task completion time affect makespan?
<p>Let's say that we have a large collection of tasks $\tau_1, \tau_2, ..., \tau_n$ and a collection of identical (in terms of performance) processors $\rho_1, \rho_2, ..., \rho_m$ which operate completely in parallel. For scenarios of interest, we may assume $m \leq n$. Each $\tau_i$ takes some amount of time/cycles to complete once it is assigned to a processor $\rho_j$, and once it is assigned, it cannot be reassigned until completed (processors always eventually complete assigned tasks). Let's assume that each $\tau_i$ takes an amount of time/cycles $X_i$, not known in advance, taken from some discrete random distribution. For this question, we can even assume a simple distribution: $P(X_i = 1) = P(X_i = 5) = 1/2$, and all $X_i$ are pairwise independent. Therefore $\mu_i = 3$ and $\sigma^2 = 4$.</p>&#xA;&#xA;<p>Suppose that, statically, at time/cycle 0, all tasks are assigned as evenly as possible to all processors, uniformly at random; so each processor $\rho_j$ is assigned $n/m$ tasks (we can just as well assume $m | n$ for the purposes of the question). We call the makespan the time/cycle at which the last processor $\rho^*$ to finish its assigned work, finishes the work it was assigned. First question:</p>&#xA;&#xA;<blockquote>&#xA; <p>As a function of $m$, $n$, and the $X_i$'s, what is the makespan $M$? Specifically, what is $E[M]$? $Var[M]$?</p>&#xA;</blockquote>&#xA;&#xA;<p>Second question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Suppose $P(X_i = 2) = P(X_i = 4) = 1/2$, and all $X_i$ are pairwise independent, so $\mu_i = 3$ and $\sigma^2 = 1$. As a function of $m$, $n$, and these new $X_i$'s, what is the makespan? More interestingly, how does it compare to the answer from the first part?</p>&#xA;</blockquote>&#xA;&#xA;<p>Some simple thought experiments demonstrate the answer to the latter is that the makespan is longer. But how can this be quantified? I will be happy to post an example if this is either (a) controversial or (b) unclear. Depending on the success with this one, I will post a follow-up question about a dynamic assignment scheme under these same assumptions. Thanks in advance!</p>&#xA;&#xA;<p><strong>Analysis of an easy case: $m = 1$</strong></p>&#xA;&#xA;<p>If $m = 1$, then all $n$ tasks are scheduled to the same processor. The makespan $M$ is just the time to complete $n$ tasks in a complete sequential fashion. Therefore,&#xA;$$\begin{align*}&#xD;&#xA; E[M]&#xD;&#xA; &amp;= E[X_1 + X_2 + ... + X_n] \\&#xD;&#xA; &amp;= E[X_1] + E[X_2] + ... + E[X_n] \\&#xD;&#xA; &amp;= \mu + \mu + ... + \mu \\&#xD;&#xA; &amp;= n\mu&#xD;&#xA;\end{align*}$$&#xA;and&#xA;$$\begin{align*}&#xD;&#xA; Var[M]&#xD;&#xA; &amp;= Var[X_1 + X_2 + ... + X_n] \\&#xD;&#xA; &amp;= Var[X_1] + Var[X_2] + ... + Var[X_n] \\&#xD;&#xA; &amp;= \sigma^2 + \sigma^2 + ... + \sigma^2 \\&#xD;&#xA; &amp;= n\sigma^2 \\&#xD;&#xA;\end{align*}$$</p>&#xA;&#xA;<p>It seems like it might be possible to use this result to answer the question for $m &gt; 1$; we simply need to find an expression (or close approximation) for $\max(Y_1, Y_2, ..., Y_m)$ where $Y_i = X_{i\frac{n}{m} + 1} + X_{i\frac{n}{m} + 2} + ... + X_{i\frac{n}{m} + \frac{n}{m}}$, a random variable with $\mu_Y = \frac{n}{m}\mu_X$ and $\sigma_Y^2 = \frac{n}{m}\sigma_X^2$. Is this heading in the right direction?</p>&#xA;
probability theory scheduling parallel computing
1
How does variance in task completion time affect makespan? -- (probability theory scheduling parallel computing) <p>Let's say that we have a large collection of tasks $\tau_1, \tau_2, ..., \tau_n$ and a collection of identical (in terms of performance) processors $\rho_1, \rho_2, ..., \rho_m$ which operate completely in parallel. For scenarios of interest, we may assume $m \leq n$. Each $\tau_i$ takes some amount of time/cycles to complete once it is assigned to a processor $\rho_j$, and once it is assigned, it cannot be reassigned until completed (processors always eventually complete assigned tasks). Let's assume that each $\tau_i$ takes an amount of time/cycles $X_i$, not known in advance, taken from some discrete random distribution. For this question, we can even assume a simple distribution: $P(X_i = 1) = P(X_i = 5) = 1/2$, and all $X_i$ are pairwise independent. Therefore $\mu_i = 3$ and $\sigma^2 = 4$.</p>&#xA;&#xA;<p>Suppose that, statically, at time/cycle 0, all tasks are assigned as evenly as possible to all processors, uniformly at random; so each processor $\rho_j$ is assigned $n/m$ tasks (we can just as well assume $m | n$ for the purposes of the question). We call the makespan the time/cycle at which the last processor $\rho^*$ to finish its assigned work, finishes the work it was assigned. First question:</p>&#xA;&#xA;<blockquote>&#xA; <p>As a function of $m$, $n$, and the $X_i$'s, what is the makespan $M$? Specifically, what is $E[M]$? $Var[M]$?</p>&#xA;</blockquote>&#xA;&#xA;<p>Second question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Suppose $P(X_i = 2) = P(X_i = 4) = 1/2$, and all $X_i$ are pairwise independent, so $\mu_i = 3$ and $\sigma^2 = 1$. As a function of $m$, $n$, and these new $X_i$'s, what is the makespan? More interestingly, how does it compare to the answer from the first part?</p>&#xA;</blockquote>&#xA;&#xA;<p>Some simple thought experiments demonstrate the answer to the latter is that the makespan is longer. But how can this be quantified? I will be happy to post an example if this is either (a) controversial or (b) unclear. Depending on the success with this one, I will post a follow-up question about a dynamic assignment scheme under these same assumptions. Thanks in advance!</p>&#xA;&#xA;<p><strong>Analysis of an easy case: $m = 1$</strong></p>&#xA;&#xA;<p>If $m = 1$, then all $n$ tasks are scheduled to the same processor. The makespan $M$ is just the time to complete $n$ tasks in a complete sequential fashion. Therefore,&#xA;$$\begin{align*}&#xD;&#xA; E[M]&#xD;&#xA; &amp;= E[X_1 + X_2 + ... + X_n] \\&#xD;&#xA; &amp;= E[X_1] + E[X_2] + ... + E[X_n] \\&#xD;&#xA; &amp;= \mu + \mu + ... + \mu \\&#xD;&#xA; &amp;= n\mu&#xD;&#xA;\end{align*}$$&#xA;and&#xA;$$\begin{align*}&#xD;&#xA; Var[M]&#xD;&#xA; &amp;= Var[X_1 + X_2 + ... + X_n] \\&#xD;&#xA; &amp;= Var[X_1] + Var[X_2] + ... + Var[X_n] \\&#xD;&#xA; &amp;= \sigma^2 + \sigma^2 + ... + \sigma^2 \\&#xD;&#xA; &amp;= n\sigma^2 \\&#xD;&#xA;\end{align*}$$</p>&#xA;&#xA;<p>It seems like it might be possible to use this result to answer the question for $m &gt; 1$; we simply need to find an expression (or close approximation) for $\max(Y_1, Y_2, ..., Y_m)$ where $Y_i = X_{i\frac{n}{m} + 1} + X_{i\frac{n}{m} + 2} + ... + X_{i\frac{n}{m} + \frac{n}{m}}$, a random variable with $\mu_Y = \frac{n}{m}\mu_X$ and $\sigma_Y^2 = \frac{n}{m}\sigma_X^2$. Is this heading in the right direction?</p>&#xA;
habedi/stack-exchange-dataset
1,243
What is meant by "solvable by non deterministic algorithm in polynomial time"
<p>In many textbooks NP problems are defined as:</p>&#xA;&#xA;<blockquote>&#xA; <p>Set of all decision problems solvable by non deterministic algorithms in polynomial time</p>&#xA;</blockquote>&#xA;&#xA;<p>I couldn't understand the part "solvable by non deterministic algorithms". Could anyone please explain that?</p>&#xA;
complexity theory terminology nondeterminism
1
What is meant by "solvable by non deterministic algorithm in polynomial time" -- (complexity theory terminology nondeterminism) <p>In many textbooks NP problems are defined as:</p>&#xA;&#xA;<blockquote>&#xA; <p>Set of all decision problems solvable by non deterministic algorithms in polynomial time</p>&#xA;</blockquote>&#xA;&#xA;<p>I couldn't understand the part "solvable by non deterministic algorithms". Could anyone please explain that?</p>&#xA;
habedi/stack-exchange-dataset
1,246
Where can I find good study material on Role Mining?
<p>I need to cover these topics in Role Mining. If anyone knows good site which well summarizes the topics and concepts are well explained please help out.</p>&#xA;&#xA;<p>Basic role mining problem<br>&#xA;β€’ Delta-approx RMP<br>&#xA;β€’ Min-noise RMP<br>&#xA;β€’ Nature of the RMP problems<br>&#xA;β€’ Mapping RMP to database tiling problem<br>&#xA;β€’ Minimum tiling problem<br>&#xA;β€’ Mapping min-noise RMP to database tiling problem<br>&#xA;β€’ Mapping RMP to minimum biclique cover problem<br></p>&#xA;
education reference request security access control
1
Where can I find good study material on Role Mining? -- (education reference request security access control) <p>I need to cover these topics in Role Mining. If anyone knows good site which well summarizes the topics and concepts are well explained please help out.</p>&#xA;&#xA;<p>Basic role mining problem<br>&#xA;β€’ Delta-approx RMP<br>&#xA;β€’ Min-noise RMP<br>&#xA;β€’ Nature of the RMP problems<br>&#xA;β€’ Mapping RMP to database tiling problem<br>&#xA;β€’ Minimum tiling problem<br>&#xA;β€’ Mapping min-noise RMP to database tiling problem<br>&#xA;β€’ Mapping RMP to minimum biclique cover problem<br></p>&#xA;
habedi/stack-exchange-dataset
1,255
Ordering elements so that some elements don't come between others
<p>Given an integer $n$ and set of triplets of distinct integers&#xA;$$S \subseteq \{(i, j, k) \mid 1\le i,j,k \le n, i \neq j, j \neq k, i \neq k\},$$&#xA;find an algorithm which either finds a permutation $\pi$ of the set $\{1, 2, \dots, n\}$ such that&#xA;$$(i,j,k) \in S \implies (\pi(j)&lt;\pi(i)&lt;\pi(k)) ~\lor~ (\pi(i)&lt;\pi(k)&lt;\pi(j))$$&#xA;or correctly determines that no such permutation exists. Less formally, we want to reorder the numbers 1 through $n$; each triple $(i,j,k)$ in $S$ indicates that $i$ must appear before $k$ in the new order, but $j$ must not appear between $i$ and $k$.</p>&#xA;&#xA;<p><strong>Example 1</strong></p>&#xA;&#xA;<p>Suppose $n=5$ and $S = \{(1,2,3), (2,3,4)\}$. Then</p>&#xA;&#xA;<ul>&#xA;<li><p>$\pi = (5, 4, 3, 2, 1)$ is <em>not</em> a valid permutation, because $(1, 2, 3)\in S$, but $\pi(1) &gt; \pi(3)$.</p></li>&#xA;<li><p>$\pi = (1, 2, 4, 5, 3)$ is <em>not</em> a valid permutation, because $(1, 2, 3) \in S$ but $\pi(1) &lt; \pi(3) &lt; \pi(5)$.</p></li>&#xA;<li><p>$(2, 4, 1, 3, 5)$ is a valid permutation.</p></li>&#xA;</ul>&#xA;&#xA;<p><strong>Example 2</strong></p>&#xA;&#xA;<p>If $n=5$ and $S = \{(1, 2, 3), (2, 1, 3)\}$, there is no valid permutation. Similarly, there is no valid permutation if $n=5$ and $S = \{(1,2,3), (3,4,5), (2,5,3), (2,1,4)\}$ (I think; may have made a mistake here).</p>&#xA;&#xA;<p><em>Bonus: What properties of $S$ determine whether a feasible solution exists?</em></p>&#xA;
algorithms optimization scheduling
1
Ordering elements so that some elements don't come between others -- (algorithms optimization scheduling) <p>Given an integer $n$ and set of triplets of distinct integers&#xA;$$S \subseteq \{(i, j, k) \mid 1\le i,j,k \le n, i \neq j, j \neq k, i \neq k\},$$&#xA;find an algorithm which either finds a permutation $\pi$ of the set $\{1, 2, \dots, n\}$ such that&#xA;$$(i,j,k) \in S \implies (\pi(j)&lt;\pi(i)&lt;\pi(k)) ~\lor~ (\pi(i)&lt;\pi(k)&lt;\pi(j))$$&#xA;or correctly determines that no such permutation exists. Less formally, we want to reorder the numbers 1 through $n$; each triple $(i,j,k)$ in $S$ indicates that $i$ must appear before $k$ in the new order, but $j$ must not appear between $i$ and $k$.</p>&#xA;&#xA;<p><strong>Example 1</strong></p>&#xA;&#xA;<p>Suppose $n=5$ and $S = \{(1,2,3), (2,3,4)\}$. Then</p>&#xA;&#xA;<ul>&#xA;<li><p>$\pi = (5, 4, 3, 2, 1)$ is <em>not</em> a valid permutation, because $(1, 2, 3)\in S$, but $\pi(1) &gt; \pi(3)$.</p></li>&#xA;<li><p>$\pi = (1, 2, 4, 5, 3)$ is <em>not</em> a valid permutation, because $(1, 2, 3) \in S$ but $\pi(1) &lt; \pi(3) &lt; \pi(5)$.</p></li>&#xA;<li><p>$(2, 4, 1, 3, 5)$ is a valid permutation.</p></li>&#xA;</ul>&#xA;&#xA;<p><strong>Example 2</strong></p>&#xA;&#xA;<p>If $n=5$ and $S = \{(1, 2, 3), (2, 1, 3)\}$, there is no valid permutation. Similarly, there is no valid permutation if $n=5$ and $S = \{(1,2,3), (3,4,5), (2,5,3), (2,1,4)\}$ (I think; may have made a mistake here).</p>&#xA;&#xA;<p><em>Bonus: What properties of $S$ determine whether a feasible solution exists?</em></p>&#xA;
habedi/stack-exchange-dataset
1,259
A lambda calculus evaluation involving Church numerals
<p>I understand that a <a href="http://en.wikipedia.org/wiki/Church_encoding">Church numeral</a> $c_n$ looks like $\lambda s. \lambda z. s$ (... n times ...) $s\;z$. This means nothing more than "the function $s$ applied $n$ times to the function $z$".</p>&#xA;&#xA;<p>A possible definition of the $\mathtt{times}$ function is the following: $\mathtt{times} = \lambda m. \lambda n. \lambda s. m \; (n\; s)$. Looking at the body, I understand the logic behind the function. However, when I start evaluating, I get stuck. I will illustrate it with an example:</p>&#xA;&#xA;<p>$$\begin{align*}&#xD;&#xA; (\lambda m. \lambda n. \lambda s. m \; (n\; s))(\lambda s.\lambda z.s\;s\;z)(\lambda s.\lambda z.s\;s\;s\;z) \mspace{-4em} \\&#xD;&#xA; \to^*&amp; \lambda s. (\lambda s.\lambda z.s\;s\;z) \; ((\lambda s.\lambda z.s\;s\;s\;z)\; s)) \\&#xD;&#xA; \to^*&amp; \lambda s. (\lambda s.\lambda z.s\;s\;z) \; (\lambda z.s\;s\;s\;z) \\&#xD;&#xA; \to^*&amp; \lambda s. \lambda z.(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)\;z&#xD;&#xA;\end{align*}$$</p>&#xA;&#xA;<p>Now in this situation, if I first apply $(\lambda z.s\;s\;s\;z)\;z$, I get to the desired result. However, if I apply $(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)$ first, as I should because application is associative from the left, I get a wrong result:</p>&#xA;&#xA;<p>$\lambda s. \lambda z.(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)\;z \to \lambda s. \lambda z.(s\;s\;s\;(\lambda z.s\;s\;s\;z))\;\;z$</p>&#xA;&#xA;<p>I can no longer reduce this. What am I doing wrong? The result should be $\lambda s. \lambda z.s\;s\;s\;s\;s\;s\;z$</p>&#xA;
lambda calculus church numerals
1
A lambda calculus evaluation involving Church numerals -- (lambda calculus church numerals) <p>I understand that a <a href="http://en.wikipedia.org/wiki/Church_encoding">Church numeral</a> $c_n$ looks like $\lambda s. \lambda z. s$ (... n times ...) $s\;z$. This means nothing more than "the function $s$ applied $n$ times to the function $z$".</p>&#xA;&#xA;<p>A possible definition of the $\mathtt{times}$ function is the following: $\mathtt{times} = \lambda m. \lambda n. \lambda s. m \; (n\; s)$. Looking at the body, I understand the logic behind the function. However, when I start evaluating, I get stuck. I will illustrate it with an example:</p>&#xA;&#xA;<p>$$\begin{align*}&#xD;&#xA; (\lambda m. \lambda n. \lambda s. m \; (n\; s))(\lambda s.\lambda z.s\;s\;z)(\lambda s.\lambda z.s\;s\;s\;z) \mspace{-4em} \\&#xD;&#xA; \to^*&amp; \lambda s. (\lambda s.\lambda z.s\;s\;z) \; ((\lambda s.\lambda z.s\;s\;s\;z)\; s)) \\&#xD;&#xA; \to^*&amp; \lambda s. (\lambda s.\lambda z.s\;s\;z) \; (\lambda z.s\;s\;s\;z) \\&#xD;&#xA; \to^*&amp; \lambda s. \lambda z.(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)\;z&#xD;&#xA;\end{align*}$$</p>&#xA;&#xA;<p>Now in this situation, if I first apply $(\lambda z.s\;s\;s\;z)\;z$, I get to the desired result. However, if I apply $(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)$ first, as I should because application is associative from the left, I get a wrong result:</p>&#xA;&#xA;<p>$\lambda s. \lambda z.(\lambda z.s\;s\;s\;z)\;(\lambda z.s\;s\;s\;z)\;z \to \lambda s. \lambda z.(s\;s\;s\;(\lambda z.s\;s\;s\;z))\;\;z$</p>&#xA;&#xA;<p>I can no longer reduce this. What am I doing wrong? The result should be $\lambda s. \lambda z.s\;s\;s\;s\;s\;s\;z$</p>&#xA;
habedi/stack-exchange-dataset
1,270
What is the average turnaround time?
<p>For the following jobs: </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/rwOBN.png" alt="job table"></p>&#xA;&#xA;<p>The <strong>average wait time</strong> would be using a FCFS algorithm:</p>&#xA;&#xA;<p>(6-6)+(7-2)+(11-5)+(17-5)+(14-1) -> 0+5+6+10+13 -> 34/5 = 7 (6.8)</p>&#xA;&#xA;<p>What would the <strong>average turnaround time</strong> be? </p>&#xA;
algorithms operating systems process scheduling scheduling
1
What is the average turnaround time? -- (algorithms operating systems process scheduling scheduling) <p>For the following jobs: </p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/rwOBN.png" alt="job table"></p>&#xA;&#xA;<p>The <strong>average wait time</strong> would be using a FCFS algorithm:</p>&#xA;&#xA;<p>(6-6)+(7-2)+(11-5)+(17-5)+(14-1) -> 0+5+6+10+13 -> 34/5 = 7 (6.8)</p>&#xA;&#xA;<p>What would the <strong>average turnaround time</strong> be? </p>&#xA;
habedi/stack-exchange-dataset
1,271
Why is Relativization a barrier?
<p>When I was explaining the Baker-Gill-Solovay proof that there exists an oracle with which we can have, $\mathsf{P} = \mathsf{NP}$, and an oracle with which we can have $\mathsf{P} \neq \mathsf{NP}$ to a friend, a question came up as to why such techniques are ill-suited for proving the $\mathsf{P} \neq \mathsf{NP}$ problem, and I couldn't give a satisfactory answer.</p>&#xA;&#xA;<p>To put it more concretely, if I have an approach to prove $\mathsf{P} \neq \mathsf{NP}$ and if I could construct oracles to make a situation like above happen, why does it make my method invalid? </p>&#xA;&#xA;<p>Any exposition/thoughts on this topic?</p>&#xA;
complexity theory proof techniques p vs np relativization
1
Why is Relativization a barrier? -- (complexity theory proof techniques p vs np relativization) <p>When I was explaining the Baker-Gill-Solovay proof that there exists an oracle with which we can have, $\mathsf{P} = \mathsf{NP}$, and an oracle with which we can have $\mathsf{P} \neq \mathsf{NP}$ to a friend, a question came up as to why such techniques are ill-suited for proving the $\mathsf{P} \neq \mathsf{NP}$ problem, and I couldn't give a satisfactory answer.</p>&#xA;&#xA;<p>To put it more concretely, if I have an approach to prove $\mathsf{P} \neq \mathsf{NP}$ and if I could construct oracles to make a situation like above happen, why does it make my method invalid? </p>&#xA;&#xA;<p>Any exposition/thoughts on this topic?</p>&#xA;
habedi/stack-exchange-dataset
1,280
What are examples of inconsistency and incompleteness in Unix/C?
<p>In Richard Gabriel's famous essay <a href="http://dreamsongs.com/RiseOfWorseIsBetter.html">The Rise of Worse is Better</a>, he contrasts caricatured versions of the MIT/Stanford (Lisp) and New Jersey (C/Unix) design philosophies along the axes of simplicity, correctness, consistency, and completeness. He gives the example of the "PC loser-ing problem" (<a href="http://blog.reverberate.org/2011/04/18/eintr-and-pc-loser-ing-the-worse-is-better-case-study/">discussed elsewhere by Josh Haberman</a>) to argue that Unix prioritizes simplicity of implementation over simplicity of interface.</p>&#xA;&#xA;<p>One other example I've come up with is the different approaches to numbers. Lisp can represent arbitrarily large numbers (up to the size of memory), while C limits numbers to a fixed number of bits (typically 32-64). I think this illustrates the correctness axis.</p>&#xA;&#xA;<p>What are some examples for consistency and completeness? Here are all of Gabriel's descriptions (which he admits are caricatures):</p>&#xA;&#xA;<p><strong>The MIT/Stanford approach</strong></p>&#xA;&#xA;<ul>&#xA;<li>Simplicity -- the design must be simple, both in implementation and interface. It is more important for the interface to be simple than the implementation.</li>&#xA;<li>Correctness -- the design must be correct in all observable aspects. Incorrectness is simply not allowed.</li>&#xA;<li>Consistency -- the design must not be inconsistent. A design is allowed to be slightly less simple and less complete to avoid inconsistency. Consistency is as important as correctness.</li>&#xA;<li>Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases must be covered. Simplicity is not allowed to overly reduce completeness.</li>&#xA;</ul>&#xA;&#xA;<p><strong>The New Jersey Approach</strong></p>&#xA;&#xA;<ul>&#xA;<li>Simplicity -- the design must be simple, both in implementation and interface. It is more important for the implementation to be simple than the interface. Simplicity is the most important consideration in a design.</li>&#xA;<li>Correctness -- the design must be correct in all observable aspects. It is slightly better to be simple than correct.</li>&#xA;<li>Consistency -- the design must not be overly inconsistent. Consistency can be sacrificed for simplicity in some cases, but it is better to drop those parts of the design that deal with less common circumstances than to introduce either implementational complexity or inconsistency.</li>&#xA;<li>Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases should be covered. Completeness can be sacrificed in favor of any other quality. In fact, completeness must be sacrificed whenever implementation simplicity is jeopardized. Consistency can be sacrificed to achieve completeness if simplicity is retained; especially worthless is consistency of interface.</li>&#xA;</ul>&#xA;&#xA;<p>Please note I am not asking whether Gabriel is right (which is a question not appropriate for StackExchange) but for examples of what he might have been referring to.</p>&#xA;
programming languages operating systems
1
What are examples of inconsistency and incompleteness in Unix/C? -- (programming languages operating systems) <p>In Richard Gabriel's famous essay <a href="http://dreamsongs.com/RiseOfWorseIsBetter.html">The Rise of Worse is Better</a>, he contrasts caricatured versions of the MIT/Stanford (Lisp) and New Jersey (C/Unix) design philosophies along the axes of simplicity, correctness, consistency, and completeness. He gives the example of the "PC loser-ing problem" (<a href="http://blog.reverberate.org/2011/04/18/eintr-and-pc-loser-ing-the-worse-is-better-case-study/">discussed elsewhere by Josh Haberman</a>) to argue that Unix prioritizes simplicity of implementation over simplicity of interface.</p>&#xA;&#xA;<p>One other example I've come up with is the different approaches to numbers. Lisp can represent arbitrarily large numbers (up to the size of memory), while C limits numbers to a fixed number of bits (typically 32-64). I think this illustrates the correctness axis.</p>&#xA;&#xA;<p>What are some examples for consistency and completeness? Here are all of Gabriel's descriptions (which he admits are caricatures):</p>&#xA;&#xA;<p><strong>The MIT/Stanford approach</strong></p>&#xA;&#xA;<ul>&#xA;<li>Simplicity -- the design must be simple, both in implementation and interface. It is more important for the interface to be simple than the implementation.</li>&#xA;<li>Correctness -- the design must be correct in all observable aspects. Incorrectness is simply not allowed.</li>&#xA;<li>Consistency -- the design must not be inconsistent. A design is allowed to be slightly less simple and less complete to avoid inconsistency. Consistency is as important as correctness.</li>&#xA;<li>Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases must be covered. Simplicity is not allowed to overly reduce completeness.</li>&#xA;</ul>&#xA;&#xA;<p><strong>The New Jersey Approach</strong></p>&#xA;&#xA;<ul>&#xA;<li>Simplicity -- the design must be simple, both in implementation and interface. It is more important for the implementation to be simple than the interface. Simplicity is the most important consideration in a design.</li>&#xA;<li>Correctness -- the design must be correct in all observable aspects. It is slightly better to be simple than correct.</li>&#xA;<li>Consistency -- the design must not be overly inconsistent. Consistency can be sacrificed for simplicity in some cases, but it is better to drop those parts of the design that deal with less common circumstances than to introduce either implementational complexity or inconsistency.</li>&#xA;<li>Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases should be covered. Completeness can be sacrificed in favor of any other quality. In fact, completeness must be sacrificed whenever implementation simplicity is jeopardized. Consistency can be sacrificed to achieve completeness if simplicity is retained; especially worthless is consistency of interface.</li>&#xA;</ul>&#xA;&#xA;<p>Please note I am not asking whether Gabriel is right (which is a question not appropriate for StackExchange) but for examples of what he might have been referring to.</p>&#xA;
habedi/stack-exchange-dataset
1,287
Find subsequence of maximal length simultaneously satisfying two ordering constraints
<p>We are given a set $F=\{f_1, f_2, f_3, …, f_N\}$ of $N$ Fruits. Each Fruit has price $P_i$ and vitamin content $V_i$; we associated fruit $f_i$ with the ordered pair $(P_i, V_i)$. Now we have to arrange these fruits in such a way that the sorted list contains prices in ascending order and vitamin contents in descending order.</p>&#xA;&#xA;<p><strong>Example 1</strong>: $N = 4$ and $F = \{(2, 8), (5, 11), (7, 9), (10, 2)\}$.</p>&#xA;&#xA;<p>If we arrange the list such that all price are in ascending order and vitamin contents in descending order, then the valid lists are the following:</p>&#xA;&#xA;<ul>&#xA;<li>$[(2, 8)]$</li>&#xA;<li>$[(5, 11)]$</li>&#xA;<li>$[(7, 9)]$</li>&#xA;<li>$[(10, 2)]$</li>&#xA;<li>$[(2, 8), (10, 2)]$</li>&#xA;<li>$[(5, 11), (7, 9)]$</li>&#xA;<li>$[(5, 11), (10, 2)]$</li>&#xA;<li>$[(7, 9), (10, 2)]$</li>&#xA;<li>$[(5, 11), (7, 9), (10, 2)]$</li>&#xA;</ul>&#xA;&#xA;<p>From the above lists, I want to choose the list of maximal size. If more than one list has maximal size, we should choose the list of maximal size whose sum of prices is least. The list which should be chosen in the above example is $\{(5, 11), (7, 9), (10, 2)\}$.</p>&#xA;&#xA;<p><strong>Example 2</strong>: $N = 10$ and $$F = \{(99,10),(12,23),(34,4),(10,5),(87,11),(19,10), \\(90,18), (43,90),(13,100),(78,65)\}$$</p>&#xA;&#xA;<p>The answer to this example instance is $[(13,100),(43,90),(78,65),(87,11),(99,10)]$.</p>&#xA;&#xA;<p>Until now, this is what I have been doing:</p>&#xA;&#xA;<ol>&#xA;<li>Sort the original list in ascending order of price;</li>&#xA;<li>Find all subsequences of the sorted list;</li>&#xA;<li>Check whether the subsequence is valid, and compare all valid subsequences.</li>&#xA;</ol>&#xA;&#xA;<p>However, this takes exponential time; how can I solve this problem more efficiently?</p>&#xA;
algorithms arrays constraint programming subsequences
1
Find subsequence of maximal length simultaneously satisfying two ordering constraints -- (algorithms arrays constraint programming subsequences) <p>We are given a set $F=\{f_1, f_2, f_3, …, f_N\}$ of $N$ Fruits. Each Fruit has price $P_i$ and vitamin content $V_i$; we associated fruit $f_i$ with the ordered pair $(P_i, V_i)$. Now we have to arrange these fruits in such a way that the sorted list contains prices in ascending order and vitamin contents in descending order.</p>&#xA;&#xA;<p><strong>Example 1</strong>: $N = 4$ and $F = \{(2, 8), (5, 11), (7, 9), (10, 2)\}$.</p>&#xA;&#xA;<p>If we arrange the list such that all price are in ascending order and vitamin contents in descending order, then the valid lists are the following:</p>&#xA;&#xA;<ul>&#xA;<li>$[(2, 8)]$</li>&#xA;<li>$[(5, 11)]$</li>&#xA;<li>$[(7, 9)]$</li>&#xA;<li>$[(10, 2)]$</li>&#xA;<li>$[(2, 8), (10, 2)]$</li>&#xA;<li>$[(5, 11), (7, 9)]$</li>&#xA;<li>$[(5, 11), (10, 2)]$</li>&#xA;<li>$[(7, 9), (10, 2)]$</li>&#xA;<li>$[(5, 11), (7, 9), (10, 2)]$</li>&#xA;</ul>&#xA;&#xA;<p>From the above lists, I want to choose the list of maximal size. If more than one list has maximal size, we should choose the list of maximal size whose sum of prices is least. The list which should be chosen in the above example is $\{(5, 11), (7, 9), (10, 2)\}$.</p>&#xA;&#xA;<p><strong>Example 2</strong>: $N = 10$ and $$F = \{(99,10),(12,23),(34,4),(10,5),(87,11),(19,10), \\(90,18), (43,90),(13,100),(78,65)\}$$</p>&#xA;&#xA;<p>The answer to this example instance is $[(13,100),(43,90),(78,65),(87,11),(99,10)]$.</p>&#xA;&#xA;<p>Until now, this is what I have been doing:</p>&#xA;&#xA;<ol>&#xA;<li>Sort the original list in ascending order of price;</li>&#xA;<li>Find all subsequences of the sorted list;</li>&#xA;<li>Check whether the subsequence is valid, and compare all valid subsequences.</li>&#xA;</ol>&#xA;&#xA;<p>However, this takes exponential time; how can I solve this problem more efficiently?</p>&#xA;
habedi/stack-exchange-dataset
1,288
Security Lattice Construction
<p>I am having a problem trying to solve a question on a past paper asking to design a security lattice. Here is the question:</p>&#xA;&#xA;<blockquote>&#xA; <p>The AB model (Almost Biba) is a model for expressing integrity policies rather&#xA; than confidentiality. It has the same setup as Bell-LaPadula, except that $L$ is now a set of&#xA; integrity levels which express the degree of confidence we have in the integrity of&#xA; subjects and objects. Subjects and data at higher integrity levels are considered&#xA; to be more accurate or safe. The set of subjects and objects may also be different,&#xA; for example, programs are naturally considered as subjects.</p>&#xA; &#xA; <p>Often, the set $L$ is actually a lattice of levels, with two operations: least&#xA; upper bound $l_1 \vee l_2$ and greatest lower bound $l_1 \wedge l_2$, where $l_1, l_2 \in L$.</p>&#xA; &#xA; <p>i. Design an example integrity lattice for AB, by combining two degrees of&#xA; data integrity <strong>dirty</strong> and <strong>clean</strong> and two means by which a piece of input&#xA; may be received, <strong>website</strong> (external user input from a web site form) and&#xA; <strong>dataentry</strong> (internal user input by trusted staff).</p>&#xA;</blockquote>&#xA;&#xA;<p>I have been looking for an explanation on how to build lattices but can't seem to find one on the internet or in textbooks. Can anyone point me in the right direction?</p>&#xA;
security lattices integrity
1
Security Lattice Construction -- (security lattices integrity) <p>I am having a problem trying to solve a question on a past paper asking to design a security lattice. Here is the question:</p>&#xA;&#xA;<blockquote>&#xA; <p>The AB model (Almost Biba) is a model for expressing integrity policies rather&#xA; than confidentiality. It has the same setup as Bell-LaPadula, except that $L$ is now a set of&#xA; integrity levels which express the degree of confidence we have in the integrity of&#xA; subjects and objects. Subjects and data at higher integrity levels are considered&#xA; to be more accurate or safe. The set of subjects and objects may also be different,&#xA; for example, programs are naturally considered as subjects.</p>&#xA; &#xA; <p>Often, the set $L$ is actually a lattice of levels, with two operations: least&#xA; upper bound $l_1 \vee l_2$ and greatest lower bound $l_1 \wedge l_2$, where $l_1, l_2 \in L$.</p>&#xA; &#xA; <p>i. Design an example integrity lattice for AB, by combining two degrees of&#xA; data integrity <strong>dirty</strong> and <strong>clean</strong> and two means by which a piece of input&#xA; may be received, <strong>website</strong> (external user input from a web site form) and&#xA; <strong>dataentry</strong> (internal user input by trusted staff).</p>&#xA;</blockquote>&#xA;&#xA;<p>I have been looking for an explanation on how to build lattices but can't seem to find one on the internet or in textbooks. Can anyone point me in the right direction?</p>&#xA;
habedi/stack-exchange-dataset
1,290
How to output all longest decreasing sequences
<p>Suppose I have an array of integers having length $N$. How can I output all longest decreasing sequences? (A subsequence consists of elements of the array that do not have to be consecustive, for example $(3,2,1)$ is a decreasing subsequence of $(7,3,5,2,0,1)$.) I know how to calculate the length of longest decreasing sequences, but don't know how to report all longest decreasing sequences.</p>&#xA;&#xA;<p>Pseudocode will be helpful.</p>&#xA;
algorithms arrays subsequences
1
How to output all longest decreasing sequences -- (algorithms arrays subsequences) <p>Suppose I have an array of integers having length $N$. How can I output all longest decreasing sequences? (A subsequence consists of elements of the array that do not have to be consecustive, for example $(3,2,1)$ is a decreasing subsequence of $(7,3,5,2,0,1)$.) I know how to calculate the length of longest decreasing sequences, but don't know how to report all longest decreasing sequences.</p>&#xA;&#xA;<p>Pseudocode will be helpful.</p>&#xA;
habedi/stack-exchange-dataset
1,292
What is required for universal analogue computation?
<p>What operations need to be performed in order to do any arbitrary <a href="http://en.wikipedia.org/wiki/Analog_computer">analogue computation</a>? Would addition, subtraction, multiplication and division be sufficient?</p>&#xA;&#xA;<p>Also, does anyone know exactly what problems are tractable using analogue computation, but not with digital?</p>&#xA;
computability computation models turing completeness
1
What is required for universal analogue computation? -- (computability computation models turing completeness) <p>What operations need to be performed in order to do any arbitrary <a href="http://en.wikipedia.org/wiki/Analog_computer">analogue computation</a>? Would addition, subtraction, multiplication and division be sufficient?</p>&#xA;&#xA;<p>Also, does anyone know exactly what problems are tractable using analogue computation, but not with digital?</p>&#xA;
habedi/stack-exchange-dataset
1,296
Solve a recurrence using the master theorem
<p>This is the recursive formula for which I'm trying to find an asymptotic closed form by the <a href="http://en.wikipedia.org/wiki/Master_theorem" rel="nofollow">master theorem</a>:&#xA;$$T(n)=9T(n/27)+(n \cdot \lg(n))^{1/2}$$</p>&#xA;&#xA;<p>I started with $a=9,b=27$ and $f(n)=(n\cdot \lg n)^{1/2}$ for using the master theorem by $n^{\log_b(a)}$, and if so $n^{\log_{27}(9)}=n^{2/3}$ but I don't understand how to play with the $(n\cdot \lg n)^{1/2}$. </p>&#xA;&#xA;<p>I think that the $(n\cdot \lg n)^{1/2}$ is bigger than $n^{2/3}$ but I'm sure I skip here on something. </p>&#xA;&#xA;<p>I think it fits to the third case of the master theorem.</p>&#xA;
algorithm analysis asymptotics recurrence relation master theorem
1
Solve a recurrence using the master theorem -- (algorithm analysis asymptotics recurrence relation master theorem) <p>This is the recursive formula for which I'm trying to find an asymptotic closed form by the <a href="http://en.wikipedia.org/wiki/Master_theorem" rel="nofollow">master theorem</a>:&#xA;$$T(n)=9T(n/27)+(n \cdot \lg(n))^{1/2}$$</p>&#xA;&#xA;<p>I started with $a=9,b=27$ and $f(n)=(n\cdot \lg n)^{1/2}$ for using the master theorem by $n^{\log_b(a)}$, and if so $n^{\log_{27}(9)}=n^{2/3}$ but I don't understand how to play with the $(n\cdot \lg n)^{1/2}$. </p>&#xA;&#xA;<p>I think that the $(n\cdot \lg n)^{1/2}$ is bigger than $n^{2/3}$ but I'm sure I skip here on something. </p>&#xA;&#xA;<p>I think it fits to the third case of the master theorem.</p>&#xA;
habedi/stack-exchange-dataset
1,299
NP-completeness of a spanning tree problem
<p>I was reviewing some NP-complete problems on this site, and I meet one interesting problem from </p>&#xA;&#xA;<p><a href="https://cs.stackexchange.com/questions/808/np-completeness-proof-of-a-spanning-tree-problem">NP completeness proof of a spanning tree problem</a></p>&#xA;&#xA;<p>In this problem, I am interested in the original problem, which the leaf set is precisely $S$. The author said that he can prove this by reducing it to the Hamiltonian path. However, I still cannot figure it out. Could anybody help me with this in details?</p>&#xA;
complexity theory np complete graphs spanning trees
1
NP-completeness of a spanning tree problem -- (complexity theory np complete graphs spanning trees) <p>I was reviewing some NP-complete problems on this site, and I meet one interesting problem from </p>&#xA;&#xA;<p><a href="https://cs.stackexchange.com/questions/808/np-completeness-proof-of-a-spanning-tree-problem">NP completeness proof of a spanning tree problem</a></p>&#xA;&#xA;<p>In this problem, I am interested in the original problem, which the leaf set is precisely $S$. The author said that he can prove this by reducing it to the Hamiltonian path. However, I still cannot figure it out. Could anybody help me with this in details?</p>&#xA;
habedi/stack-exchange-dataset
1,301
Find minimum number 1's so the matrix consist of 1 connected region of 1's
<p>Let $M$ be a $(0, 1)$ matrix. We say two entries are neighbors if they are adjacent horizontal or vertically, and both entries are $1$'s. One wants to find minimum number of $1$'s to add, so every $1$ can reach another one through a sequence of neighbors. </p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<pre><code>100&#xA;000&#xA;001&#xA;</code></pre>&#xA;&#xA;<p>Here we need 3 $1$'s:</p>&#xA;&#xA;<pre><code>100&#xA;100&#xA;111&#xA;</code></pre>&#xA;&#xA;<p>How can we efficiently find the minimum number of $1$'s to add, and where?</p>&#xA;
algorithms graphs matrices
1
Find minimum number 1's so the matrix consist of 1 connected region of 1's -- (algorithms graphs matrices) <p>Let $M$ be a $(0, 1)$ matrix. We say two entries are neighbors if they are adjacent horizontal or vertically, and both entries are $1$'s. One wants to find minimum number of $1$'s to add, so every $1$ can reach another one through a sequence of neighbors. </p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<pre><code>100&#xA;000&#xA;001&#xA;</code></pre>&#xA;&#xA;<p>Here we need 3 $1$'s:</p>&#xA;&#xA;<pre><code>100&#xA;100&#xA;111&#xA;</code></pre>&#xA;&#xA;<p>How can we efficiently find the minimum number of $1$'s to add, and where?</p>&#xA;
habedi/stack-exchange-dataset
1,319
Solving problems related to Marginal Contribution Nets
<p>So, I encoutered this problem in examination:</p>&#xA;&#xA;<blockquote>&#xA; <p>Consider the following marginal contribution net:</p>&#xA; &#xA; <p>$\{a \wedge b\} \to 5$</p>&#xA; &#xA; <p>$\{b\} \to 2$</p>&#xA; &#xA; <p>$\{c\} \to 4$</p>&#xA; &#xA; <p>$\{b \wedge \neg c\} \to βˆ’2$</p>&#xA; &#xA; <p>Let $v$ be the characteristic function defined by these rules. Give the values of the &#xA; following:</p>&#xA; &#xA; <p>i) $v(\emptyset)$</p>&#xA; &#xA; <p>ii) $v(\{a\})$</p>&#xA; &#xA; <p>iii) $v(\{b\})$</p>&#xA; &#xA; <p>iv) $v(\{a, b\})$</p>&#xA; &#xA; <p>v) $v(\{a, b, c\})$</p>&#xA;</blockquote>&#xA;&#xA;<p>My answer is below, but I am not sure.</p>&#xA;&#xA;<blockquote>&#xA; <p>i) $v(\emptyset) = -2$</p>&#xA; &#xA; <p>ii) $v(\{a\}) = 0 - 2$</p>&#xA; &#xA; <p>iii) $v(\{b\}) = 2 - 2$</p>&#xA; &#xA; <p>iv) $v(\{a, b\}) = 5 + 2 - 2$</p>&#xA; &#xA; <p>v) $v(\{a, b, c\}) = 5 + 4 + 2 - 2$</p>&#xA;</blockquote>&#xA;&#xA;<p>If anybody knows how to solve this kind of problem, could you confirm?</p>&#xA;&#xA;<p>Exact same problem is shown on page 4 of following paper: &#xA;<a href="http://research.microsoft.com/pubs/73752/ieong05mcnet.pdf">Marginal Contribution Nets: A Compact Representation Scheme for Coalitional Games (by Samuel Ieong and Yoav Shoham)</a></p>&#xA;
artificial intelligence
1
Solving problems related to Marginal Contribution Nets -- (artificial intelligence) <p>So, I encoutered this problem in examination:</p>&#xA;&#xA;<blockquote>&#xA; <p>Consider the following marginal contribution net:</p>&#xA; &#xA; <p>$\{a \wedge b\} \to 5$</p>&#xA; &#xA; <p>$\{b\} \to 2$</p>&#xA; &#xA; <p>$\{c\} \to 4$</p>&#xA; &#xA; <p>$\{b \wedge \neg c\} \to βˆ’2$</p>&#xA; &#xA; <p>Let $v$ be the characteristic function defined by these rules. Give the values of the &#xA; following:</p>&#xA; &#xA; <p>i) $v(\emptyset)$</p>&#xA; &#xA; <p>ii) $v(\{a\})$</p>&#xA; &#xA; <p>iii) $v(\{b\})$</p>&#xA; &#xA; <p>iv) $v(\{a, b\})$</p>&#xA; &#xA; <p>v) $v(\{a, b, c\})$</p>&#xA;</blockquote>&#xA;&#xA;<p>My answer is below, but I am not sure.</p>&#xA;&#xA;<blockquote>&#xA; <p>i) $v(\emptyset) = -2$</p>&#xA; &#xA; <p>ii) $v(\{a\}) = 0 - 2$</p>&#xA; &#xA; <p>iii) $v(\{b\}) = 2 - 2$</p>&#xA; &#xA; <p>iv) $v(\{a, b\}) = 5 + 2 - 2$</p>&#xA; &#xA; <p>v) $v(\{a, b, c\}) = 5 + 4 + 2 - 2$</p>&#xA;</blockquote>&#xA;&#xA;<p>If anybody knows how to solve this kind of problem, could you confirm?</p>&#xA;&#xA;<p>Exact same problem is shown on page 4 of following paper: &#xA;<a href="http://research.microsoft.com/pubs/73752/ieong05mcnet.pdf">Marginal Contribution Nets: A Compact Representation Scheme for Coalitional Games (by Samuel Ieong and Yoav Shoham)</a></p>&#xA;
habedi/stack-exchange-dataset
1,326
How to prove regular languages are closed under left quotient?
<p>$L$ is a regular language over the alphabet $\Sigma = \{a,b\}$. The left quotient of $L$ regarding $w \in \Sigma^*$ is the language &#xA;$$w^{-1} L := \{v \mid wv \in L\}$$</p>&#xA;&#xA;<p>How can I prove that $w^{-1}L$ is regular?</p>&#xA;
formal languages regular languages closure properties
1
How to prove regular languages are closed under left quotient? -- (formal languages regular languages closure properties) <p>$L$ is a regular language over the alphabet $\Sigma = \{a,b\}$. The left quotient of $L$ regarding $w \in \Sigma^*$ is the language &#xA;$$w^{-1} L := \{v \mid wv \in L\}$$</p>&#xA;&#xA;<p>How can I prove that $w^{-1}L$ is regular?</p>&#xA;
habedi/stack-exchange-dataset
1,329
Shortest Path on an Undirected Graph?
<p>So I thought this (though somewhat basic) question belonged here:</p>&#xA;&#xA;<p>Say I have a graph of size 100 nodes arrayed in a 10x10 pattern (think chessboard). The graph is undirected, and unweighted. Moving through the graph involves moving three spaces forward and one space to either right or left (similar to how a chess knight moves across a board).</p>&#xA;&#xA;<p>Given a fixed beginning node, how would one find the shortest path to any other node on the board?</p>&#xA;&#xA;<p>I imagined that there would only be an edge between nodes that are viable moves. So, given this information, I would want to find the shortest path from a starting node to an ending node.</p>&#xA;&#xA;<p>My initial thought was that each edge is weighted with weight 1. However, the graph is undirected, so Djikstras would not be an ideal fit. Therefore, I decided to do it using an altered form of a depth first search.</p>&#xA;&#xA;<p>However, I couldn't for the life of me visualize how to get the shortest path using the search.</p>&#xA;&#xA;<p>Another thing I tried was putting the graph in tree form with the starting node as the root, and then selecting the shallowest (lowest row number) result that gave me the desired end node... this worked, but was incredibly inefficient, and thus would not work for a larger graph.</p>&#xA;&#xA;<p>Does anyone have any ideas that might point me in the right direction on this one?</p>&#xA;&#xA;<p>Thank you very much.</p>&#xA;&#xA;<p>(I tried to put in a visualization of the graph, but was unable to due to my low reputation)</p>&#xA;
algorithms graphs search algorithms shortest path
1
Shortest Path on an Undirected Graph? -- (algorithms graphs search algorithms shortest path) <p>So I thought this (though somewhat basic) question belonged here:</p>&#xA;&#xA;<p>Say I have a graph of size 100 nodes arrayed in a 10x10 pattern (think chessboard). The graph is undirected, and unweighted. Moving through the graph involves moving three spaces forward and one space to either right or left (similar to how a chess knight moves across a board).</p>&#xA;&#xA;<p>Given a fixed beginning node, how would one find the shortest path to any other node on the board?</p>&#xA;&#xA;<p>I imagined that there would only be an edge between nodes that are viable moves. So, given this information, I would want to find the shortest path from a starting node to an ending node.</p>&#xA;&#xA;<p>My initial thought was that each edge is weighted with weight 1. However, the graph is undirected, so Djikstras would not be an ideal fit. Therefore, I decided to do it using an altered form of a depth first search.</p>&#xA;&#xA;<p>However, I couldn't for the life of me visualize how to get the shortest path using the search.</p>&#xA;&#xA;<p>Another thing I tried was putting the graph in tree form with the starting node as the root, and then selecting the shallowest (lowest row number) result that gave me the desired end node... this worked, but was incredibly inefficient, and thus would not work for a larger graph.</p>&#xA;&#xA;<p>Does anyone have any ideas that might point me in the right direction on this one?</p>&#xA;&#xA;<p>Thank you very much.</p>&#xA;&#xA;<p>(I tried to put in a visualization of the graph, but was unable to due to my low reputation)</p>&#xA;
habedi/stack-exchange-dataset
1,331
How to prove a language is regular?
<p>There are many methods to prove that <a href="https://cs.stackexchange.com/q/1031/157">a language is not regular</a>, but what do I need to do to prove that some language <em>is</em> regular?</p>&#xA;&#xA;<p>For instance, if I am given that $L$ is regular, &#xA;how can I prove that the following $L'$ is regular, too?</p>&#xA;&#xA;<p>$\qquad \displaystyle L' := \{w \in L: uv = w \text{ for } u \in \Sigma^* \setminus L \text{ and } v \in \Sigma^+ \}$</p>&#xA;&#xA;<p>Can I draw a nondeterministic finite automaton to prove this?</p>&#xA;
formal languages regular languages automata proof techniques reference question
1
How to prove a language is regular? -- (formal languages regular languages automata proof techniques reference question) <p>There are many methods to prove that <a href="https://cs.stackexchange.com/q/1031/157">a language is not regular</a>, but what do I need to do to prove that some language <em>is</em> regular?</p>&#xA;&#xA;<p>For instance, if I am given that $L$ is regular, &#xA;how can I prove that the following $L'$ is regular, too?</p>&#xA;&#xA;<p>$\qquad \displaystyle L' := \{w \in L: uv = w \text{ for } u \in \Sigma^* \setminus L \text{ and } v \in \Sigma^+ \}$</p>&#xA;&#xA;<p>Can I draw a nondeterministic finite automaton to prove this?</p>&#xA;
habedi/stack-exchange-dataset
1,332
Modified Djikstra's algorithm
<p>So, I'm trying to conceptualize something:</p>&#xA;&#xA;<p>Say we have a weighed graph of size N. A and B are nodes on the graph. You want to find the shortest path from A to B, given a few caveats:</p>&#xA;&#xA;<ol>&#xA;<li><p>movements on the graph are regulated by a circular cycle of length 48, in such a manner that:</p>&#xA;&#xA;<blockquote>&#xA; <p>cycle{</p>&#xA;&#xA;<pre><code> 0 &lt;= L &lt;= 24 movement IS possible&#xA;&#xA; 25 &lt;= L &lt;= 48 movement IS NOT possible&#xA;</code></pre>&#xA; &#xA; <p>}</p>&#xA;</blockquote>&#xA;&#xA;<p>For simplicity's sake, we will call this cycle 'time'.</p></li>&#xA;<li><p>The distance between nodes A and B is equal to:</p>&#xA;&#xA;<blockquote>&#xA; <p>shortest_distance(A to B) - 1 OR shortest_distance(A to B) + 1</p>&#xA;</blockquote>&#xA;&#xA;<p>Depending on their orientation</p></li>&#xA;<li><p>the weight of the edges represents the 'time' it takes to travel between nodes.</p></li>&#xA;</ol>&#xA;&#xA;<p>I'd like to create an algorithm that will give me the shortest path with these constraints in mind, assuming one is leaving from node A at time(cycle) = 12, traveling towards node B. The shortest path would be defined as the path which takes the least 'time'.</p>&#xA;&#xA;<p>Step one would obviously be to take into account the orientation affecting the shortest distance (i.e. which way are they oriented by above), which would be a simple addition or substraction to the result of djikstra's algorithm</p>&#xA;&#xA;<p>What I'm having trouble figuring out is how to account for the cycle in the algorithm... could it be as simple as just an if statement checking to see if the current cycle time is within the constraints that allow movement?</p>&#xA;&#xA;<p>Would my idea be viable? If not, does anyone h ave any suggestions at different ways I should look at this problem?</p>&#xA;&#xA;<p>I know this question seems really basic, but I just can't wrap my head around it.</p>&#xA;
algorithms graphs shortest path
1
Modified Djikstra's algorithm -- (algorithms graphs shortest path) <p>So, I'm trying to conceptualize something:</p>&#xA;&#xA;<p>Say we have a weighed graph of size N. A and B are nodes on the graph. You want to find the shortest path from A to B, given a few caveats:</p>&#xA;&#xA;<ol>&#xA;<li><p>movements on the graph are regulated by a circular cycle of length 48, in such a manner that:</p>&#xA;&#xA;<blockquote>&#xA; <p>cycle{</p>&#xA;&#xA;<pre><code> 0 &lt;= L &lt;= 24 movement IS possible&#xA;&#xA; 25 &lt;= L &lt;= 48 movement IS NOT possible&#xA;</code></pre>&#xA; &#xA; <p>}</p>&#xA;</blockquote>&#xA;&#xA;<p>For simplicity's sake, we will call this cycle 'time'.</p></li>&#xA;<li><p>The distance between nodes A and B is equal to:</p>&#xA;&#xA;<blockquote>&#xA; <p>shortest_distance(A to B) - 1 OR shortest_distance(A to B) + 1</p>&#xA;</blockquote>&#xA;&#xA;<p>Depending on their orientation</p></li>&#xA;<li><p>the weight of the edges represents the 'time' it takes to travel between nodes.</p></li>&#xA;</ol>&#xA;&#xA;<p>I'd like to create an algorithm that will give me the shortest path with these constraints in mind, assuming one is leaving from node A at time(cycle) = 12, traveling towards node B. The shortest path would be defined as the path which takes the least 'time'.</p>&#xA;&#xA;<p>Step one would obviously be to take into account the orientation affecting the shortest distance (i.e. which way are they oriented by above), which would be a simple addition or substraction to the result of djikstra's algorithm</p>&#xA;&#xA;<p>What I'm having trouble figuring out is how to account for the cycle in the algorithm... could it be as simple as just an if statement checking to see if the current cycle time is within the constraints that allow movement?</p>&#xA;&#xA;<p>Would my idea be viable? If not, does anyone h ave any suggestions at different ways I should look at this problem?</p>&#xA;&#xA;<p>I know this question seems really basic, but I just can't wrap my head around it.</p>&#xA;
habedi/stack-exchange-dataset
1,334
Randomized Selection
<p>The randomized selection algorithm is the following:</p>&#xA;&#xA;<p>Input: An array $A$ of $n$ (distinct, for simplicity) numbers and a number $k\in [n]$</p>&#xA;&#xA;<p>Output: The the "rank $k$ element" of $A$ (i.e., the one in position $k$ if $A$ was sorted)</p>&#xA;&#xA;<p>Method:</p>&#xA;&#xA;<ul>&#xA;<li>If there is one element in $A$, return it</li>&#xA;<li>Select an element $p$ (the "pivot") uniformly at random</li>&#xA;<li>Compute the sets $L = \{a\in A : a &lt; p\}$ and $R = \{a\in A : a &gt; p\}$</li>&#xA;<li>If $|L| \ge k$, return the rank $k$ element of $L$.</li>&#xA;<li>Otherwise, return the rank $k - |L|$ element of $R$</li>&#xA;</ul>&#xA;&#xA;<p>I was asked the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Suppose that $k=n/2$, so you are looking for the median, and let $\alpha\in (1/2,1)$&#xA; be a constant. What is the probability that, at the first recursive call, the &#xA; set containing the median has size at most $\alpha n$?</p>&#xA;</blockquote>&#xA;&#xA;<p>I was told that the answer is $2\alpha - 1$, with the justification "The pivot selected should lie between $1βˆ’\alpha$ and $\alpha$ times the original array"</p>&#xA;&#xA;<p>Why? As $\alpha \in (0.5, 1)$, whatever element is chosen as pivot is either larger or smaller than more than half the original elements. The median always lies in the larger subarray, because the elements in the partitioned subarray are always less than the pivot. </p>&#xA;&#xA;<p>If the pivot lies in the first half of the original array (less than half of them), the median will surely be in the second larger half, because once the median is found, it must be in the middle position of the array, and everything before the pivot is smaller as stated above. </p>&#xA;&#xA;<p>If the pivot lies in the second half of the original array (more than half of the elements), the median will surely first larger half, for the same reason, everything before the pivot is considered smaller. </p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<p>3 4 5 8 7 9 2 1 6 10</p>&#xA;&#xA;<p>The median is 5.</p>&#xA;&#xA;<p>Supposed the chosen pivot is 2. So after the first iteration, it becomes:</p>&#xA;&#xA;<p>1 2 ....bigger part....</p>&#xA;&#xA;<p>Only <code>1</code> and <code>2</code> are swapped after the first iteration. Number 5 (the median) is still in the first greater half (accroding to the pivot 2). The point is, median always lies on greater half, how can it have a chance to stay in a smaller subarray?</p>&#xA;
algorithms algorithm analysis probability theory randomized algorithms
1
Randomized Selection -- (algorithms algorithm analysis probability theory randomized algorithms) <p>The randomized selection algorithm is the following:</p>&#xA;&#xA;<p>Input: An array $A$ of $n$ (distinct, for simplicity) numbers and a number $k\in [n]$</p>&#xA;&#xA;<p>Output: The the "rank $k$ element" of $A$ (i.e., the one in position $k$ if $A$ was sorted)</p>&#xA;&#xA;<p>Method:</p>&#xA;&#xA;<ul>&#xA;<li>If there is one element in $A$, return it</li>&#xA;<li>Select an element $p$ (the "pivot") uniformly at random</li>&#xA;<li>Compute the sets $L = \{a\in A : a &lt; p\}$ and $R = \{a\in A : a &gt; p\}$</li>&#xA;<li>If $|L| \ge k$, return the rank $k$ element of $L$.</li>&#xA;<li>Otherwise, return the rank $k - |L|$ element of $R$</li>&#xA;</ul>&#xA;&#xA;<p>I was asked the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Suppose that $k=n/2$, so you are looking for the median, and let $\alpha\in (1/2,1)$&#xA; be a constant. What is the probability that, at the first recursive call, the &#xA; set containing the median has size at most $\alpha n$?</p>&#xA;</blockquote>&#xA;&#xA;<p>I was told that the answer is $2\alpha - 1$, with the justification "The pivot selected should lie between $1βˆ’\alpha$ and $\alpha$ times the original array"</p>&#xA;&#xA;<p>Why? As $\alpha \in (0.5, 1)$, whatever element is chosen as pivot is either larger or smaller than more than half the original elements. The median always lies in the larger subarray, because the elements in the partitioned subarray are always less than the pivot. </p>&#xA;&#xA;<p>If the pivot lies in the first half of the original array (less than half of them), the median will surely be in the second larger half, because once the median is found, it must be in the middle position of the array, and everything before the pivot is smaller as stated above. </p>&#xA;&#xA;<p>If the pivot lies in the second half of the original array (more than half of the elements), the median will surely first larger half, for the same reason, everything before the pivot is considered smaller. </p>&#xA;&#xA;<p>Example:</p>&#xA;&#xA;<p>3 4 5 8 7 9 2 1 6 10</p>&#xA;&#xA;<p>The median is 5.</p>&#xA;&#xA;<p>Supposed the chosen pivot is 2. So after the first iteration, it becomes:</p>&#xA;&#xA;<p>1 2 ....bigger part....</p>&#xA;&#xA;<p>Only <code>1</code> and <code>2</code> are swapped after the first iteration. Number 5 (the median) is still in the first greater half (accroding to the pivot 2). The point is, median always lies on greater half, how can it have a chance to stay in a smaller subarray?</p>&#xA;
habedi/stack-exchange-dataset
1,335
What is a good reference to learn about state transition systems?
<p>I am studying different approaches for the definition of computation with continuous dynamical systems. I have been trying to find a nice introduction to the theory of <a href="http://en.wikipedia.org/wiki/State_transition_system">"State transition systems"</a> but failed to do so.</p>&#xA;&#xA;<p>Does anybody know a modern introduction to the topic? &#xA;Of particular interest would be something dealing with computability.</p>&#xA;
computability automata reference request computation models
1
What is a good reference to learn about state transition systems? -- (computability automata reference request computation models) <p>I am studying different approaches for the definition of computation with continuous dynamical systems. I have been trying to find a nice introduction to the theory of <a href="http://en.wikipedia.org/wiki/State_transition_system">"State transition systems"</a> but failed to do so.</p>&#xA;&#xA;<p>Does anybody know a modern introduction to the topic? &#xA;Of particular interest would be something dealing with computability.</p>&#xA;
habedi/stack-exchange-dataset
1,336
Extending the implementation of a Queue using a circular array
<p>I'm doing some exam (Java-based algorithmics) revision and have been given the question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Describe how you might extend your implementation [of a queue using a circular array] to support the expansion of the Queue to allow it to store more data items.</p>&#xA;</blockquote>&#xA;&#xA;<p>The Queue started off implemented as an array with a fixed maximum size. I've got two current answers to this, but I'm not sure either are correct:</p>&#xA;&#xA;<ol>&#xA;<li><p>Implement the Queue using the Java Vector class as the underlying array structure. The Vector class is similar to arrays, but a Vector can be resized at any time whereas an array's size is fixed when the array is created.</p></li>&#xA;<li><p>Copy all entries into a larger array.</p></li>&#xA;</ol>&#xA;&#xA;<p>Is there anything obvious I'm missing?</p>&#xA;
algorithms data structures
1
Extending the implementation of a Queue using a circular array -- (algorithms data structures) <p>I'm doing some exam (Java-based algorithmics) revision and have been given the question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Describe how you might extend your implementation [of a queue using a circular array] to support the expansion of the Queue to allow it to store more data items.</p>&#xA;</blockquote>&#xA;&#xA;<p>The Queue started off implemented as an array with a fixed maximum size. I've got two current answers to this, but I'm not sure either are correct:</p>&#xA;&#xA;<ol>&#xA;<li><p>Implement the Queue using the Java Vector class as the underlying array structure. The Vector class is similar to arrays, but a Vector can be resized at any time whereas an array's size is fixed when the array is created.</p></li>&#xA;<li><p>Copy all entries into a larger array.</p></li>&#xA;</ol>&#xA;&#xA;<p>Is there anything obvious I'm missing?</p>&#xA;
habedi/stack-exchange-dataset
1,339
$\log^*(n)$ runtime analysis
<p>So I know that $\log^*$ means iterated logarithm, so $\log^*(3)$ = $(\log\log\log\log...)$ until $n \leq 1$.</p>&#xA;&#xA;<p>I'm trying to solve the following:</p>&#xA;&#xA;<p>is </p>&#xA;&#xA;<blockquote>&#xA; <p>$\log^*(2^{2^n})$</p>&#xA;</blockquote>&#xA;&#xA;<p>little $o$, little $\omega$, or $\Theta$ of</p>&#xA;&#xA;<blockquote>&#xA; <p>${\log^*(n)}^2$</p>&#xA;</blockquote>&#xA;&#xA;<p>In terms of the interior functions, $\log^*(2^{2^n})$ is much bigger than $\log^*(n)$, but squaring the $\log^*(n)$ is throwing me off. </p>&#xA;&#xA;<p>I know that $\log(n)^2$ is $O(n)$, but I don't think that property holds for the iterative logarithm.</p>&#xA;&#xA;<p>I tried applying the master method, but I'm having trouble with the properties of a $\log^*(n)$ function. I tried setting n to be max (i.e. $n = 5$), but this didn't really simplify the problem.</p>&#xA;&#xA;<p>Does anyone have any tips as to how I should approach this?</p>&#xA;
asymptotics landau notation mathematical analysis
1
$\log^*(n)$ runtime analysis -- (asymptotics landau notation mathematical analysis) <p>So I know that $\log^*$ means iterated logarithm, so $\log^*(3)$ = $(\log\log\log\log...)$ until $n \leq 1$.</p>&#xA;&#xA;<p>I'm trying to solve the following:</p>&#xA;&#xA;<p>is </p>&#xA;&#xA;<blockquote>&#xA; <p>$\log^*(2^{2^n})$</p>&#xA;</blockquote>&#xA;&#xA;<p>little $o$, little $\omega$, or $\Theta$ of</p>&#xA;&#xA;<blockquote>&#xA; <p>${\log^*(n)}^2$</p>&#xA;</blockquote>&#xA;&#xA;<p>In terms of the interior functions, $\log^*(2^{2^n})$ is much bigger than $\log^*(n)$, but squaring the $\log^*(n)$ is throwing me off. </p>&#xA;&#xA;<p>I know that $\log(n)^2$ is $O(n)$, but I don't think that property holds for the iterative logarithm.</p>&#xA;&#xA;<p>I tried applying the master method, but I'm having trouble with the properties of a $\log^*(n)$ function. I tried setting n to be max (i.e. $n = 5$), but this didn't really simplify the problem.</p>&#xA;&#xA;<p>Does anyone have any tips as to how I should approach this?</p>&#xA;
habedi/stack-exchange-dataset
1,346
Sharp concentration for selection via random partitioning?
<p>The usual simple algorithm for finding the median element in an array $A$ of $n$ numbers is:</p>&#xA;&#xA;<ul>&#xA;<li>Sample $n^{3/4}$ elements from $A$ with replacement into $B$</li>&#xA;<li>Sort $B$ and find the rank $|B|\pm \sqrt{n}$ elements $l$ and $r$ of $B$</li>&#xA;<li>Check that $l$ and $r$ are on opposite sides of the median of $A$ and that there are at most $C\sqrt{n}$ elements in $A$ between $l$ and $r$ for some appropriate constant $C &gt; 0$. Fail if this doesn't happen.</li>&#xA;<li>Otherwise, find the median by sorting the elements of $A$ between $l$ and $r$</li>&#xA;</ul>&#xA;&#xA;<p>It's not hard to see that this runs in linear time and that it succeeds with high probability. (All the bad events are large deviations away from the expectation of a binomial.)</p>&#xA;&#xA;<p>An alternate algorithm for the same problem, which is more natural to teach to students who have seen quick sort is the one described here: <a href="https://cs.stackexchange.com/questions/1334/randomized-selection/1343">Randomized Selection</a></p>&#xA;&#xA;<p>It is also easy to see that this one has linear expected running time: say that a "round" is a sequence of recursive calls that ends when one gives a 1/4-3/4 split, and then observe that the expected length of a round is at most 2. (In the first draw of a round, the probability of getting a good split is 1/2 and then after actually increases, as the algorithm was described so round length is dominated by a geometric random variable.)</p>&#xA;&#xA;<p>So now the question: </p>&#xA;&#xA;<blockquote>&#xA; <p>Is it possible to show that randomized selection runs in linear time with high probability?</p>&#xA;</blockquote>&#xA;&#xA;<p>We have $O(\log n)$ rounds, and each round has length at least $k$ with probability at most $2^{-k+1}$, so a union bound gives that the running time is $O(n\log\log n)$ with probability $1-1/O(\log n)$.</p>&#xA;&#xA;<p>This is kind of unsatisfying, but is it actually the truth?</p>&#xA;
algorithms algorithm analysis randomized algorithms
1
Sharp concentration for selection via random partitioning? -- (algorithms algorithm analysis randomized algorithms) <p>The usual simple algorithm for finding the median element in an array $A$ of $n$ numbers is:</p>&#xA;&#xA;<ul>&#xA;<li>Sample $n^{3/4}$ elements from $A$ with replacement into $B$</li>&#xA;<li>Sort $B$ and find the rank $|B|\pm \sqrt{n}$ elements $l$ and $r$ of $B$</li>&#xA;<li>Check that $l$ and $r$ are on opposite sides of the median of $A$ and that there are at most $C\sqrt{n}$ elements in $A$ between $l$ and $r$ for some appropriate constant $C &gt; 0$. Fail if this doesn't happen.</li>&#xA;<li>Otherwise, find the median by sorting the elements of $A$ between $l$ and $r$</li>&#xA;</ul>&#xA;&#xA;<p>It's not hard to see that this runs in linear time and that it succeeds with high probability. (All the bad events are large deviations away from the expectation of a binomial.)</p>&#xA;&#xA;<p>An alternate algorithm for the same problem, which is more natural to teach to students who have seen quick sort is the one described here: <a href="https://cs.stackexchange.com/questions/1334/randomized-selection/1343">Randomized Selection</a></p>&#xA;&#xA;<p>It is also easy to see that this one has linear expected running time: say that a "round" is a sequence of recursive calls that ends when one gives a 1/4-3/4 split, and then observe that the expected length of a round is at most 2. (In the first draw of a round, the probability of getting a good split is 1/2 and then after actually increases, as the algorithm was described so round length is dominated by a geometric random variable.)</p>&#xA;&#xA;<p>So now the question: </p>&#xA;&#xA;<blockquote>&#xA; <p>Is it possible to show that randomized selection runs in linear time with high probability?</p>&#xA;</blockquote>&#xA;&#xA;<p>We have $O(\log n)$ rounds, and each round has length at least $k$ with probability at most $2^{-k+1}$, so a union bound gives that the running time is $O(n\log\log n)$ with probability $1-1/O(\log n)$.</p>&#xA;&#xA;<p>This is kind of unsatisfying, but is it actually the truth?</p>&#xA;
habedi/stack-exchange-dataset
1,347
Complexity of 3SAT variants
<p>This question is motivated by my <a href="https://cs.stackexchange.com/a/1328/96">answer</a> to another question in which I stated the fact that both Betweeness and Non-Betweeness problems are $NP$-complete. In the former problem there is a total order such that the betweeness constraint of each triple is enforced while in the later problem there is a total order such that the betweeness constraint of each triple is violated.</p>&#xA;&#xA;<p>What is the complexity of the following 3SAT variants?:</p>&#xA;&#xA;<p>3SAT_1={($\phi$): $\phi$ has an assignment that makes every clause false}</p>&#xA;&#xA;<p>3SAT_2={($\phi$): $\phi$ has an assignment such that exactly half of the clauses are true and the other half is false}</p>&#xA;
complexity theory satisfiability
1
Complexity of 3SAT variants -- (complexity theory satisfiability) <p>This question is motivated by my <a href="https://cs.stackexchange.com/a/1328/96">answer</a> to another question in which I stated the fact that both Betweeness and Non-Betweeness problems are $NP$-complete. In the former problem there is a total order such that the betweeness constraint of each triple is enforced while in the later problem there is a total order such that the betweeness constraint of each triple is violated.</p>&#xA;&#xA;<p>What is the complexity of the following 3SAT variants?:</p>&#xA;&#xA;<p>3SAT_1={($\phi$): $\phi$ has an assignment that makes every clause false}</p>&#xA;&#xA;<p>3SAT_2={($\phi$): $\phi$ has an assignment such that exactly half of the clauses are true and the other half is false}</p>&#xA;
habedi/stack-exchange-dataset
1,353
Optimizing a strictly monotone function
<p>I am looking for algorithms to optimize a strictly monotonic function $f$ such that $f(x) &lt; y$ </p>&#xA;&#xA;<p>$f : [a,b] \longrightarrow [c,d]&#xD;&#xA;\qquad \text{where } [a,b] \subset {\mathbb N}, [c,d] \subset {\mathbb N}$<br>&#xA;such that $\arg\max{_x} f(x) &lt; y$</p>&#xA;&#xA;<p>My first idea was to use a variant of binary search, pick a point $x$ in $[a,b]$ at random; if $f(x) &gt; y$ then we eliminate $[x, b]$, and if $f(x) &lt; y$ we eliminate $[a, x]$. We repeat this procedure until the solution is found.</p>&#xA;&#xA;<p>Do you have any other ideas to maximize the function $f$ ?</p>&#xA;
algorithms optimization
1
Optimizing a strictly monotone function -- (algorithms optimization) <p>I am looking for algorithms to optimize a strictly monotonic function $f$ such that $f(x) &lt; y$ </p>&#xA;&#xA;<p>$f : [a,b] \longrightarrow [c,d]&#xD;&#xA;\qquad \text{where } [a,b] \subset {\mathbb N}, [c,d] \subset {\mathbb N}$<br>&#xA;such that $\arg\max{_x} f(x) &lt; y$</p>&#xA;&#xA;<p>My first idea was to use a variant of binary search, pick a point $x$ in $[a,b]$ at random; if $f(x) &gt; y$ then we eliminate $[x, b]$, and if $f(x) &lt; y$ we eliminate $[a, x]$. We repeat this procedure until the solution is found.</p>&#xA;&#xA;<p>Do you have any other ideas to maximize the function $f$ ?</p>&#xA;
habedi/stack-exchange-dataset
1,354
Quicksort vs. insertion sort on linked list: performance
<p>I have written a program to sort Linked Lists and I noticed that my insertion sort works much better than my quicksort algorithm. &#xA;Does anyone have any idea why this is?&#xA;Insertion sort has a complexity of $\Theta(n^2)$ and quicksort $O(n\log n)$ so therefore quicksort should be faster. I tried for random input size and it shows me the contrary. Strange...</p>&#xA;&#xA;<p>Here the code in Java:</p>&#xA;&#xA;&#xA;&#xA;<pre><code>public static LinkedList qSort(LinkedList list) {&#xA;&#xA; LinkedList x, y;&#xA; Node currentNode;&#xA; int size = list.getSize();&#xA;&#xA; //Create new lists x smaller equal and y greater&#xA; x = new LinkedList();&#xA; y = new LinkedList();&#xA;&#xA; if (size &lt;= 1)&#xA; return list;&#xA; else {&#xA;&#xA; Node pivot = getPivot(list);&#xA; // System.out.println("Pivot: " + pivot.value); &#xA; //We start from the head&#xA; currentNode = list.head;&#xA;&#xA; for (int i = 0; i &lt;= size - 1; i++) {&#xA; //Check that the currentNode is not our pivot&#xA; if (currentNode != pivot) {&#xA; //Nodes with values smaller equal than the pivot goes in x&#xA; if (currentNode.value &lt;= pivot.value) {&#xA; {&#xA; x.addNode(currentNode.value);&#xA; // System.out.print("Elements in x:");&#xA; // x.printList();&#xA; }&#xA;&#xA; } &#xA; //Nodes with values greater than the pivot goes in y&#xA; else if (currentNode.value &gt; pivot.value) {&#xA; if (currentNode != pivot) {&#xA; y.addNode(currentNode.value);&#xA; // System.out.print("Elements in y:");&#xA; // y.printList();&#xA; }&#xA; }&#xA; }&#xA; //Set the pointer to the next node&#xA; currentNode = currentNode.next;&#xA; }&#xA;&#xA; //Recursive calls and concatenation of the Lists and pivot&#xA; return concatenateList(qSort(x), pivot, qSort(y));&#xA;&#xA; }&#xA;}&#xA;</code></pre>&#xA;
algorithms algorithm analysis sorting lists
1
Quicksort vs. insertion sort on linked list: performance -- (algorithms algorithm analysis sorting lists) <p>I have written a program to sort Linked Lists and I noticed that my insertion sort works much better than my quicksort algorithm. &#xA;Does anyone have any idea why this is?&#xA;Insertion sort has a complexity of $\Theta(n^2)$ and quicksort $O(n\log n)$ so therefore quicksort should be faster. I tried for random input size and it shows me the contrary. Strange...</p>&#xA;&#xA;<p>Here the code in Java:</p>&#xA;&#xA;&#xA;&#xA;<pre><code>public static LinkedList qSort(LinkedList list) {&#xA;&#xA; LinkedList x, y;&#xA; Node currentNode;&#xA; int size = list.getSize();&#xA;&#xA; //Create new lists x smaller equal and y greater&#xA; x = new LinkedList();&#xA; y = new LinkedList();&#xA;&#xA; if (size &lt;= 1)&#xA; return list;&#xA; else {&#xA;&#xA; Node pivot = getPivot(list);&#xA; // System.out.println("Pivot: " + pivot.value); &#xA; //We start from the head&#xA; currentNode = list.head;&#xA;&#xA; for (int i = 0; i &lt;= size - 1; i++) {&#xA; //Check that the currentNode is not our pivot&#xA; if (currentNode != pivot) {&#xA; //Nodes with values smaller equal than the pivot goes in x&#xA; if (currentNode.value &lt;= pivot.value) {&#xA; {&#xA; x.addNode(currentNode.value);&#xA; // System.out.print("Elements in x:");&#xA; // x.printList();&#xA; }&#xA;&#xA; } &#xA; //Nodes with values greater than the pivot goes in y&#xA; else if (currentNode.value &gt; pivot.value) {&#xA; if (currentNode != pivot) {&#xA; y.addNode(currentNode.value);&#xA; // System.out.print("Elements in y:");&#xA; // y.printList();&#xA; }&#xA; }&#xA; }&#xA; //Set the pointer to the next node&#xA; currentNode = currentNode.next;&#xA; }&#xA;&#xA; //Recursive calls and concatenation of the Lists and pivot&#xA; return concatenateList(qSort(x), pivot, qSort(y));&#xA;&#xA; }&#xA;}&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
1,367
Quicksort explained to kids
<p>Last year, I was reading a fantastic <a href="http://arxiv.org/abs/quant-ph/0510032">paper on β€œQuantum Mechanics for Kindergarden”</a>. It was not easy paper.</p>&#xA;&#xA;<p>Now, I wonder how to explain quicksort in the simplest words possible. How can I prove (or at least handwave) that the average complexity is $O(n \log n)$, and what the best and the worst cases are, to a kindergarden class? Or at least in primary school?</p>&#xA;
algorithms education algorithm analysis didactics sorting
1
Quicksort explained to kids -- (algorithms education algorithm analysis didactics sorting) <p>Last year, I was reading a fantastic <a href="http://arxiv.org/abs/quant-ph/0510032">paper on β€œQuantum Mechanics for Kindergarden”</a>. It was not easy paper.</p>&#xA;&#xA;<p>Now, I wonder how to explain quicksort in the simplest words possible. How can I prove (or at least handwave) that the average complexity is $O(n \log n)$, and what the best and the worst cases are, to a kindergarden class? Or at least in primary school?</p>&#xA;
habedi/stack-exchange-dataset
1,370
What is co-something?
<p>What does the notation <code>co-</code> mean when prefixing <code>co-NP</code>, <code>co-RE</code> (recursively enumerable), or <code>co-CE</code> (computably enumerable) ?</p>&#xA;
complexity theory computability terminology
1
What is co-something? -- (complexity theory computability terminology) <p>What does the notation <code>co-</code> mean when prefixing <code>co-NP</code>, <code>co-RE</code> (recursively enumerable), or <code>co-CE</code> (computably enumerable) ?</p>&#xA;
habedi/stack-exchange-dataset
1,377
Lower bound for finding kth smallest element using adversary arguments
<p>In many texts a lower bound for finding $k$th smallest element is derived making use of arguments using medians. How can I find one using an adversary argument?</p>&#xA;&#xA;<p><a href="http://en.wikipedia.org/wiki/Selection_algorithm">Wikipedia</a> says that tournament algorithm runs in $O(n+k\log n)$, and $n - k + \sum_{j = n+2-k}^{n} \lceil{\operatorname{lg}\, j}\rceil$ is <a href="http://en.wikipedia.org/wiki/Selection_algorithm#Lower_bounds">given</a> as lower bound.</p>&#xA;
algorithms algorithm analysis
1
Lower bound for finding kth smallest element using adversary arguments -- (algorithms algorithm analysis) <p>In many texts a lower bound for finding $k$th smallest element is derived making use of arguments using medians. How can I find one using an adversary argument?</p>&#xA;&#xA;<p><a href="http://en.wikipedia.org/wiki/Selection_algorithm">Wikipedia</a> says that tournament algorithm runs in $O(n+k\log n)$, and $n - k + \sum_{j = n+2-k}^{n} \lceil{\operatorname{lg}\, j}\rceil$ is <a href="http://en.wikipedia.org/wiki/Selection_algorithm#Lower_bounds">given</a> as lower bound.</p>&#xA;
habedi/stack-exchange-dataset
1,392
Algorithm to chase a moving target
<p>Suppose that we have a black-box $f$ which we can query and reset. When we reset $f$, the state $f_S$ of $f$ is set to an element chosen uniformly at random from the set $$\{0, 1, ..., n - 1\}$$ where $n$ is fixed and known for given $f$. To query $f$, an element $x$ (the guess) from $$\{0, 1, ..., n - 1\}$$ is provided, and the value returned is $(f_S - x) \mod n$. Additionally, the state $f_S$ of$f$ is set to a value $f_S&#39; = f_S \pm k$, where $k$ is selected uniformly at random from $$\{0, 1, 2, ..., \lfloor n/2 \rfloor - ((f_S - x) \mod n)\} $$</p>&#xA;&#xA;<p>By making uniformly random guesses with each query, one would expect to have to make $n$ guesses before getting $f_S = x$, with variance $n^2 - n$ (stated without proof).</p>&#xA;&#xA;<p>Can an algorithm be designed to do better (i.e., make fewer guesses, possibly with less variance in the number of guesses)? How much better could it do (i.e., what's an optimal algorithm, and what is its performance)?</p>&#xA;&#xA;<p>An efficient solution to this problem could have important cost-saving implications for shooting at a rabbit (confined to hopping on a circular track) in a dark room.</p>&#xA;
algorithms probability theory randomized algorithms
1
Algorithm to chase a moving target -- (algorithms probability theory randomized algorithms) <p>Suppose that we have a black-box $f$ which we can query and reset. When we reset $f$, the state $f_S$ of $f$ is set to an element chosen uniformly at random from the set $$\{0, 1, ..., n - 1\}$$ where $n$ is fixed and known for given $f$. To query $f$, an element $x$ (the guess) from $$\{0, 1, ..., n - 1\}$$ is provided, and the value returned is $(f_S - x) \mod n$. Additionally, the state $f_S$ of$f$ is set to a value $f_S&#39; = f_S \pm k$, where $k$ is selected uniformly at random from $$\{0, 1, 2, ..., \lfloor n/2 \rfloor - ((f_S - x) \mod n)\} $$</p>&#xA;&#xA;<p>By making uniformly random guesses with each query, one would expect to have to make $n$ guesses before getting $f_S = x$, with variance $n^2 - n$ (stated without proof).</p>&#xA;&#xA;<p>Can an algorithm be designed to do better (i.e., make fewer guesses, possibly with less variance in the number of guesses)? How much better could it do (i.e., what's an optimal algorithm, and what is its performance)?</p>&#xA;&#xA;<p>An efficient solution to this problem could have important cost-saving implications for shooting at a rabbit (confined to hopping on a circular track) in a dark room.</p>&#xA;
habedi/stack-exchange-dataset
1,393
Rectangle Coverage by Sweep Line
<p>I am given an exercise unfortunately I didn't succeed by myself.</p>&#xA;&#xA;<blockquote>&#xA; <p>There is a set of rectangles $R_{1}..R_{n}$ and a rectangle $R_{0}$. Using plane sweeping algorithm determine if $R_{0}$ is completely covered by the set of $R_{1}..R_{n}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>For more details about the principle of sweep line algorithms see <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm" rel="nofollow">here</a>.</p>&#xA;&#xA;<p>Let's start from the beginning. Initially we know sweep line algorithm as the algorithm for finding <a href="http://en.wikipedia.org/wiki/Line_segment_intersection" rel="nofollow">line segment intersections</a>which requires two data structures:</p>&#xA;&#xA;<ul>&#xA;<li>a set $Q$ of event points (it stores endpoints of segments and intersections points)</li>&#xA;<li>a status $T$ (dynamic structure for the set of segments the sweep line intersecting)</li>&#xA;</ul>&#xA;&#xA;<p><strong>The General Idea:</strong> assume that sweep line $l$ is a vertical line that starts approaching the set of rectangles from the left. Sort all $x$ coordinates of rectangles and store them in $Q$ in increasing order - should take $O(n\log n)$. Start from the first event point, for every point determine the set of rectangles that intersect at given $x$ coordinate, identify continuous segments of intersection rectangles and check if they cover $R_{0}$ completely at current $x$ coordinate. With $T$ as a binary tree it's gonna take $O(\log n)$. If any part of $R_{0}$ remains uncovered that $R_{0}$ is not completely covered.</p>&#xA;&#xA;<p><strong>Details:</strong> The idea of segment intersection algorithm was that only adjacent segments intersect. Based on this fact we built status $T$ and maintained it throughout the algorithm. I tried to find a similar idea in this case and so far with no success, the only thing I can say is two rectangles intersect if their corresponding $x$ and $y$ coordinates overlap. </p>&#xA;&#xA;<p>The problem is how to build and maintain $T$, and what the complexity of building and maintain $T$ is. I assume that <a href="http://en.wikipedia.org/wiki/R_Trees" rel="nofollow">R trees</a> can be very useful in this case, but as I found it's very difficult to determine the minimum bounding rectangle using R trees. </p>&#xA;&#xA;<p>Do you have any idea about how to solve this problem, and particularly how to build $T$?</p>&#xA;
algorithms computational geometry
1
Rectangle Coverage by Sweep Line -- (algorithms computational geometry) <p>I am given an exercise unfortunately I didn't succeed by myself.</p>&#xA;&#xA;<blockquote>&#xA; <p>There is a set of rectangles $R_{1}..R_{n}$ and a rectangle $R_{0}$. Using plane sweeping algorithm determine if $R_{0}$ is completely covered by the set of $R_{1}..R_{n}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>For more details about the principle of sweep line algorithms see <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm" rel="nofollow">here</a>.</p>&#xA;&#xA;<p>Let's start from the beginning. Initially we know sweep line algorithm as the algorithm for finding <a href="http://en.wikipedia.org/wiki/Line_segment_intersection" rel="nofollow">line segment intersections</a>which requires two data structures:</p>&#xA;&#xA;<ul>&#xA;<li>a set $Q$ of event points (it stores endpoints of segments and intersections points)</li>&#xA;<li>a status $T$ (dynamic structure for the set of segments the sweep line intersecting)</li>&#xA;</ul>&#xA;&#xA;<p><strong>The General Idea:</strong> assume that sweep line $l$ is a vertical line that starts approaching the set of rectangles from the left. Sort all $x$ coordinates of rectangles and store them in $Q$ in increasing order - should take $O(n\log n)$. Start from the first event point, for every point determine the set of rectangles that intersect at given $x$ coordinate, identify continuous segments of intersection rectangles and check if they cover $R_{0}$ completely at current $x$ coordinate. With $T$ as a binary tree it's gonna take $O(\log n)$. If any part of $R_{0}$ remains uncovered that $R_{0}$ is not completely covered.</p>&#xA;&#xA;<p><strong>Details:</strong> The idea of segment intersection algorithm was that only adjacent segments intersect. Based on this fact we built status $T$ and maintained it throughout the algorithm. I tried to find a similar idea in this case and so far with no success, the only thing I can say is two rectangles intersect if their corresponding $x$ and $y$ coordinates overlap. </p>&#xA;&#xA;<p>The problem is how to build and maintain $T$, and what the complexity of building and maintain $T$ is. I assume that <a href="http://en.wikipedia.org/wiki/R_Trees" rel="nofollow">R trees</a> can be very useful in this case, but as I found it's very difficult to determine the minimum bounding rectangle using R trees. </p>&#xA;&#xA;<p>Do you have any idea about how to solve this problem, and particularly how to build $T$?</p>&#xA;
habedi/stack-exchange-dataset
1,394
How to represent the interests of a Facebook user
<p>I'm trying to figure out a way I could represent a Facebook user as a vector. I decided to go with stacking the different attributes/parameters of the user into one big vector (i.e. age is a vector of size 100, where 100 is the maximum age you can have, if you are lets say 50, the first 50 values of the vector would be 1 just like a thermometer).</p>&#xA;&#xA;<p>Now I want to represent the Facebook interests as a vector too, and I just can't figure out a way. They are a collection of words and the space that represents all the words is huge, I can't go for a model like a bag of words or something similar. How should I proceed? I'm still new to this, any reference would be highly appreciated.</p>&#xA;
machine learning modelling social networks knowledge representation
1
How to represent the interests of a Facebook user -- (machine learning modelling social networks knowledge representation) <p>I'm trying to figure out a way I could represent a Facebook user as a vector. I decided to go with stacking the different attributes/parameters of the user into one big vector (i.e. age is a vector of size 100, where 100 is the maximum age you can have, if you are lets say 50, the first 50 values of the vector would be 1 just like a thermometer).</p>&#xA;&#xA;<p>Now I want to represent the Facebook interests as a vector too, and I just can't figure out a way. They are a collection of words and the space that represents all the words is huge, I can't go for a model like a bag of words or something similar. How should I proceed? I'm still new to this, any reference would be highly appreciated.</p>&#xA;
habedi/stack-exchange-dataset
1,399
Distribute objects in a cube so that they have maximum distance between each other
<p>I'm trying to use a color camera to track multiple objects in space. Each object will have a different color and in order to be able to distinguish well between each objects I'm trying to make sure that each color assigned to an object is as different from any color on any other object as possible.</p>&#xA;&#xA;<p>In RGB space, we have three planes, all with values between 0 and 255. In this cube $(0,0,0) / (255,255,255)$, I would like to distribute the $n$ colors so that there is as much distance between themselves and others as possible. An additional restriction is that $(0, 0, 0)$ and $(255, 255, 255)$ (or as close to them as possible) should be included in the $n$ colors, because I want to make sure that none of my $(n-2)$ objects takes either color because the background will probably be one of these colors.</p>&#xA;&#xA;<p>Probably, $n$ (including black and while) will not be more than around 14.</p>&#xA;&#xA;<p>Thanks in advance for any pointers on how to get these colors. </p>&#xA;
algorithms optimization computational geometry
1
Distribute objects in a cube so that they have maximum distance between each other -- (algorithms optimization computational geometry) <p>I'm trying to use a color camera to track multiple objects in space. Each object will have a different color and in order to be able to distinguish well between each objects I'm trying to make sure that each color assigned to an object is as different from any color on any other object as possible.</p>&#xA;&#xA;<p>In RGB space, we have three planes, all with values between 0 and 255. In this cube $(0,0,0) / (255,255,255)$, I would like to distribute the $n$ colors so that there is as much distance between themselves and others as possible. An additional restriction is that $(0, 0, 0)$ and $(255, 255, 255)$ (or as close to them as possible) should be included in the $n$ colors, because I want to make sure that none of my $(n-2)$ objects takes either color because the background will probably be one of these colors.</p>&#xA;&#xA;<p>Probably, $n$ (including black and while) will not be more than around 14.</p>&#xA;&#xA;<p>Thanks in advance for any pointers on how to get these colors. </p>&#xA;
habedi/stack-exchange-dataset
1,407
How to interpret "Windows - Virtual Memory minimum too low" from a CS student point of view?
<p>On my old 256MB RAM, pc I get this message. (I guess it is quite common)</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Windows - Virtual Memory minimum too low</strong><br>&#xA; Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. ...</p>&#xA;</blockquote>&#xA;&#xA;<p>Please explain from a CS student point of view-</p>&#xA;&#xA;<ol>&#xA;<li>"Windows is increasing the size of your virtual memory paging file." and</li>&#xA;<li>"during this process...". what is this process called?</li>&#xA;</ol>&#xA;&#xA;<p>Thanks, I am currently studying virtual memory management in OS.</p>&#xA;
operating systems virtual memory paging
1
How to interpret "Windows - Virtual Memory minimum too low" from a CS student point of view? -- (operating systems virtual memory paging) <p>On my old 256MB RAM, pc I get this message. (I guess it is quite common)</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Windows - Virtual Memory minimum too low</strong><br>&#xA; Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. ...</p>&#xA;</blockquote>&#xA;&#xA;<p>Please explain from a CS student point of view-</p>&#xA;&#xA;<ol>&#xA;<li>"Windows is increasing the size of your virtual memory paging file." and</li>&#xA;<li>"during this process...". what is this process called?</li>&#xA;</ol>&#xA;&#xA;<p>Thanks, I am currently studying virtual memory management in OS.</p>&#xA;
habedi/stack-exchange-dataset
1,413
Why are blocking artifacts serious when there is fast motion in MPEG?
<p>Why are blocking artifacts serious when there is fast motion in MPEG?</p>&#xA;&#xA;<p>Here is the guess I made:</p>&#xA;&#xA;<p>In MPEG, each block in an encoding frame is matched with a block in the reference frame.&#xA;If the difference of two blocks is small, only the difference is encoded using DCT. Is the reason blocking artifacts are serious that the difference of two blocks is too large and DCT cut the AC component?</p>&#xA;
information theory data compression video
1
Why are blocking artifacts serious when there is fast motion in MPEG? -- (information theory data compression video) <p>Why are blocking artifacts serious when there is fast motion in MPEG?</p>&#xA;&#xA;<p>Here is the guess I made:</p>&#xA;&#xA;<p>In MPEG, each block in an encoding frame is matched with a block in the reference frame.&#xA;If the difference of two blocks is small, only the difference is encoded using DCT. Is the reason blocking artifacts are serious that the difference of two blocks is too large and DCT cut the AC component?</p>&#xA;
habedi/stack-exchange-dataset
1,414
Proving a specific language is regular
<p>In my computability class we were given a practice final to go over and I'm really struggling with one of the questions on it.</p>&#xA;<blockquote>&#xA;<p>Prove the following statement:</p>&#xA;<p>If <span class="math-container">$L_1$</span> is a regular language, then so is</p>&#xA;<p><span class="math-container">$L_2 = \{ uv |$</span> <span class="math-container">$u$</span> is in <span class="math-container">$L_1$</span> or <span class="math-container">$v$</span> is in <span class="math-container">$L_1 \}$</span>.</p>&#xA;</blockquote>&#xA;<p>You can't use the pumping lemma for regular languages (I think), so how would you go about this? I'm inclined to believe that it's false because if <span class="math-container">$u$</span> is in <span class="math-container">$L_1$</span>, what if <span class="math-container">$v$</span> is non-regular? Then it would be impossible to write a regular expression for it. The question is out of 5 marks though and that doesn't seem like enough of an answer for it.</p>&#xA;
formal languages regular languages
1
Proving a specific language is regular -- (formal languages regular languages) <p>In my computability class we were given a practice final to go over and I'm really struggling with one of the questions on it.</p>&#xA;<blockquote>&#xA;<p>Prove the following statement:</p>&#xA;<p>If <span class="math-container">$L_1$</span> is a regular language, then so is</p>&#xA;<p><span class="math-container">$L_2 = \{ uv |$</span> <span class="math-container">$u$</span> is in <span class="math-container">$L_1$</span> or <span class="math-container">$v$</span> is in <span class="math-container">$L_1 \}$</span>.</p>&#xA;</blockquote>&#xA;<p>You can't use the pumping lemma for regular languages (I think), so how would you go about this? I'm inclined to believe that it's false because if <span class="math-container">$u$</span> is in <span class="math-container">$L_1$</span>, what if <span class="math-container">$v$</span> is non-regular? Then it would be impossible to write a regular expression for it. The question is out of 5 marks though and that doesn't seem like enough of an answer for it.</p>&#xA;
habedi/stack-exchange-dataset
1,415
P-Completeness and Parallel Computation
<p>I was recently reading about algorithms for checking bisimilarity and read that the problem is <a href="http://en.wikipedia.org/wiki/P-complete">P-complete</a>. Furthermore, a consequence of this is that this problem, or any P-complete problem, is unlikely to have an efficient parallel algorithms.</p>&#xA;&#xA;<blockquote>&#xA; <p>What is the intuition behind this last statement?</p>&#xA;</blockquote>&#xA;
complexity theory parallel computing
1
P-Completeness and Parallel Computation -- (complexity theory parallel computing) <p>I was recently reading about algorithms for checking bisimilarity and read that the problem is <a href="http://en.wikipedia.org/wiki/P-complete">P-complete</a>. Furthermore, a consequence of this is that this problem, or any P-complete problem, is unlikely to have an efficient parallel algorithms.</p>&#xA;&#xA;<blockquote>&#xA; <p>What is the intuition behind this last statement?</p>&#xA;</blockquote>&#xA;
habedi/stack-exchange-dataset
1,418
When to use recursion?
<p>When are some (relatively) basic (think first year college level CS student) instances when one would use recursion instead of just a loop? </p>&#xA;
algorithms recursion
1
When to use recursion? -- (algorithms recursion) <p>When are some (relatively) basic (think first year college level CS student) instances when one would use recursion instead of just a loop? </p>&#xA;
habedi/stack-exchange-dataset
1,424
Overflow safe summation
<p>Suppose I am given $n$ fixed width integers (i.e. they fit in a register of width $w$), $a_1, a_2, \dots a_n$ such that their sum $a_1 + a_2 + \dots + a_n = S$ also fits in a register of width $w$.</p>&#xA;&#xA;<p>It seems to me that we can always permute the numbers to $b_1, b_2, \dots b_n$ such that each prefix sum $S_i = b_1 + b_2 + \dots + b_i$ also fits in a register of width $w$.</p>&#xA;&#xA;<p>Basically, the motivation is to compute the sum $S = S_n$ on fixed width register machines without having to worry about integer overflows at any intermediate stage.</p>&#xA;&#xA;<p>Is there a fast (preferably linear time) algorithm to find such a permutation (assuming the $a_i$ are given as an input array)? (or say if such a permutation does not exist).</p>&#xA;
algorithms arrays integers numerical analysis
1
Overflow safe summation -- (algorithms arrays integers numerical analysis) <p>Suppose I am given $n$ fixed width integers (i.e. they fit in a register of width $w$), $a_1, a_2, \dots a_n$ such that their sum $a_1 + a_2 + \dots + a_n = S$ also fits in a register of width $w$.</p>&#xA;&#xA;<p>It seems to me that we can always permute the numbers to $b_1, b_2, \dots b_n$ such that each prefix sum $S_i = b_1 + b_2 + \dots + b_i$ also fits in a register of width $w$.</p>&#xA;&#xA;<p>Basically, the motivation is to compute the sum $S = S_n$ on fixed width register machines without having to worry about integer overflows at any intermediate stage.</p>&#xA;&#xA;<p>Is there a fast (preferably linear time) algorithm to find such a permutation (assuming the $a_i$ are given as an input array)? (or say if such a permutation does not exist).</p>&#xA;
habedi/stack-exchange-dataset
1,426
Detecting overflow in summation
<p>Suppose I am given an array of $n$ fixed width integers (i.e. they fit in a register of width $w$), $a_1, a_2, \dots a_n$. I want to compute the sum $S = a_1 + \ldots + a_n$ on a machine with 2's complement arithmetic, which performs additions modulo $2^w$ with wraparound semantics. That's easy β€” but the sum may overflow the register size, and if it does, the result will be wrong.</p>&#xA;&#xA;<p>If the sum doesn't overflow, I want to compute it, and to verify that there is no overflow, as fast as possible. If the sum overflows, I only want to know that it does, I don't care about any value.</p>&#xA;&#xA;<p>Naively adding numbers in order doesn't work, because a partial sum may overflow. For example, with 8-bit registers, $(120, 120, -115)$ is valid and has a sum of $125$, even though the partial sum $120+120$ overflows the register range $[-128,127]$.</p>&#xA;&#xA;<p>Obviously I could use a bigger register as an accumulator, but let's assume the interesting case where I'm already using the biggest possible register size.</p>&#xA;&#xA;<p>There is a well-known technique to <a href="https://cs.stackexchange.com/a/1425">add numbers with the opposite sign as the current partial sum</a>. This technique avoids overflows at every step, at the cost of not being cache-friendly and not taking much advantage of branch prediction and speculative execution.</p>&#xA;&#xA;<p>Is there a faster technique that perhaps takes advantage of the permission to overflow partial sums, and is faster on a typical machine with an overflow flag, a cache, a branch predictor and speculative execution and loads?</p>&#xA;&#xA;<p>(This is a follow-up to <a href="https://cs.stackexchange.com/questions/1424/overflow-safe-summation">Overflow safe summation</a>)</p>&#xA;
algorithms arrays integers numerical analysis
1
Detecting overflow in summation -- (algorithms arrays integers numerical analysis) <p>Suppose I am given an array of $n$ fixed width integers (i.e. they fit in a register of width $w$), $a_1, a_2, \dots a_n$. I want to compute the sum $S = a_1 + \ldots + a_n$ on a machine with 2's complement arithmetic, which performs additions modulo $2^w$ with wraparound semantics. That's easy β€” but the sum may overflow the register size, and if it does, the result will be wrong.</p>&#xA;&#xA;<p>If the sum doesn't overflow, I want to compute it, and to verify that there is no overflow, as fast as possible. If the sum overflows, I only want to know that it does, I don't care about any value.</p>&#xA;&#xA;<p>Naively adding numbers in order doesn't work, because a partial sum may overflow. For example, with 8-bit registers, $(120, 120, -115)$ is valid and has a sum of $125$, even though the partial sum $120+120$ overflows the register range $[-128,127]$.</p>&#xA;&#xA;<p>Obviously I could use a bigger register as an accumulator, but let's assume the interesting case where I'm already using the biggest possible register size.</p>&#xA;&#xA;<p>There is a well-known technique to <a href="https://cs.stackexchange.com/a/1425">add numbers with the opposite sign as the current partial sum</a>. This technique avoids overflows at every step, at the cost of not being cache-friendly and not taking much advantage of branch prediction and speculative execution.</p>&#xA;&#xA;<p>Is there a faster technique that perhaps takes advantage of the permission to overflow partial sums, and is faster on a typical machine with an overflow flag, a cache, a branch predictor and speculative execution and loads?</p>&#xA;&#xA;<p>(This is a follow-up to <a href="https://cs.stackexchange.com/questions/1424/overflow-safe-summation">Overflow safe summation</a>)</p>&#xA;
habedi/stack-exchange-dataset
1,427
Sub language is not Turing-recognizable, or could it be?
<p>Let A and B be languages with A βŠ† B, and B is Turing-recognizable. Can A be not Turing-recognizable? If so, is there any example?</p>&#xA;
computability
1
Sub language is not Turing-recognizable, or could it be? -- (computability) <p>Let A and B be languages with A βŠ† B, and B is Turing-recognizable. Can A be not Turing-recognizable? If so, is there any example?</p>&#xA;
habedi/stack-exchange-dataset
1,440
What is the name of this logistic variant of TSP?
<p>I have a logistic problem that can be seen as a variant of $\text{TSP}$. It is so natural, I'm sure it has been studied in Operations research or something similar. Here's one way of looking at the problem.</p>&#xA;&#xA;<p>I have $P$ warehouses on the Cartesian plane. There's a path from a warehouse to every other warehouse and the distance metric used is the Euclidean distance. In addition, there are $n$ different items. Each item $1 \leq i \leq n$ can be present in any number of warehouses. We have a collector and we are given a starting point $s$ for it, say the origin $(0,0)$. The collector is given an order, so a list of items. Here, we can assume that the list only contains distinct items and only one of each. We must determine the shortest tour starting at $s$ visiting some number of warehouses so that the we pick up every item on the order.</p>&#xA;&#xA;<p>Here's a visualization of a randomly generated instance with $P = 35$. Warehouses are represented with circles. Red ones contain item $1$, blue ones item $2$ and green ones item $3$. Given some starting point $s$ and the order ($1,2,3$), we must pick one red, one blue and one green warehouse so the order can be completed. By accident, there are no multi-colored warehouses in this example so they all contain exactly one item. This particular instance is a case of <a href="http://en.wikipedia.org/wiki/Set_TSP_problem" rel="nofollow noreferrer">set-TSP</a>.</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/5kKsj.png" alt="An instance of the problem."></p>&#xA;&#xA;<p>I can show that the problem is indeed $\mathcal{NP}$-hard. Consider an instance where each item $i$ is located in a different warehouse $P_i$. The order is such that it contains every item. Now we must visit every warehouse $P_i$ and find the shortest tour doing so. This is equivalent of solving an instance of $\text{TSP}$.</p>&#xA;&#xA;<p>Being so obviously useful at least in the context of logistic, routing and planning, I'm sure this has been studied before. I have two questions:</p>&#xA;&#xA;<ol>&#xA;<li>What is the name of the problem?</li>&#xA;<li>How well can one hope to approximate the problem (assuming $\mathcal{P} \neq \mathcal{NP}$)? </li>&#xA;</ol>&#xA;&#xA;<p>I'm quite happy with the name and/or reference(s) to the problem. Maybe the answer to the second point follows easily or I can find out that myself.</p>&#xA;
algorithms optimization reference request approximation
1
What is the name of this logistic variant of TSP? -- (algorithms optimization reference request approximation) <p>I have a logistic problem that can be seen as a variant of $\text{TSP}$. It is so natural, I'm sure it has been studied in Operations research or something similar. Here's one way of looking at the problem.</p>&#xA;&#xA;<p>I have $P$ warehouses on the Cartesian plane. There's a path from a warehouse to every other warehouse and the distance metric used is the Euclidean distance. In addition, there are $n$ different items. Each item $1 \leq i \leq n$ can be present in any number of warehouses. We have a collector and we are given a starting point $s$ for it, say the origin $(0,0)$. The collector is given an order, so a list of items. Here, we can assume that the list only contains distinct items and only one of each. We must determine the shortest tour starting at $s$ visiting some number of warehouses so that the we pick up every item on the order.</p>&#xA;&#xA;<p>Here's a visualization of a randomly generated instance with $P = 35$. Warehouses are represented with circles. Red ones contain item $1$, blue ones item $2$ and green ones item $3$. Given some starting point $s$ and the order ($1,2,3$), we must pick one red, one blue and one green warehouse so the order can be completed. By accident, there are no multi-colored warehouses in this example so they all contain exactly one item. This particular instance is a case of <a href="http://en.wikipedia.org/wiki/Set_TSP_problem" rel="nofollow noreferrer">set-TSP</a>.</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/5kKsj.png" alt="An instance of the problem."></p>&#xA;&#xA;<p>I can show that the problem is indeed $\mathcal{NP}$-hard. Consider an instance where each item $i$ is located in a different warehouse $P_i$. The order is such that it contains every item. Now we must visit every warehouse $P_i$ and find the shortest tour doing so. This is equivalent of solving an instance of $\text{TSP}$.</p>&#xA;&#xA;<p>Being so obviously useful at least in the context of logistic, routing and planning, I'm sure this has been studied before. I have two questions:</p>&#xA;&#xA;<ol>&#xA;<li>What is the name of the problem?</li>&#xA;<li>How well can one hope to approximate the problem (assuming $\mathcal{P} \neq \mathcal{NP}$)? </li>&#xA;</ol>&#xA;&#xA;<p>I'm quite happy with the name and/or reference(s) to the problem. Maybe the answer to the second point follows easily or I can find out that myself.</p>&#xA;
habedi/stack-exchange-dataset
1,444
How many possible ways are there?
<p>Suppose I have the given data set of length 11 of scores:</p>&#xA;&#xA;<pre><code>p=[2, 5, 1 ,2 ,4 ,1 ,6, 5, 2, 2, 1]&#xA;</code></pre>&#xA;&#xA;<p>I want to select scores 6, 5, 5, 4, 2, 2 from the data set. How many ways are there?</p>&#xA;&#xA;<p>For the above example answer is: 6 ways</p>&#xA;&#xA;<pre><code>{p[1], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[10], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[1], p[2], p[10], p[5], p[7], p[8]}&#xA;{p[9], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[1], p[2], p[9], p[5], p[7], p[8]}&#xA;{p[10], p[2], p[9], p[5], p[7], p[8]}&#xA;</code></pre>&#xA;&#xA;<p>How can I count the ways in general?</p>&#xA;
combinatorics
1
How many possible ways are there? -- (combinatorics) <p>Suppose I have the given data set of length 11 of scores:</p>&#xA;&#xA;<pre><code>p=[2, 5, 1 ,2 ,4 ,1 ,6, 5, 2, 2, 1]&#xA;</code></pre>&#xA;&#xA;<p>I want to select scores 6, 5, 5, 4, 2, 2 from the data set. How many ways are there?</p>&#xA;&#xA;<p>For the above example answer is: 6 ways</p>&#xA;&#xA;<pre><code>{p[1], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[10], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[1], p[2], p[10], p[5], p[7], p[8]}&#xA;{p[9], p[2], p[4], p[5], p[7], p[8]}&#xA;{p[1], p[2], p[9], p[5], p[7], p[8]}&#xA;{p[10], p[2], p[9], p[5], p[7], p[8]}&#xA;</code></pre>&#xA;&#xA;<p>How can I count the ways in general?</p>&#xA;
habedi/stack-exchange-dataset
1,447
What is most efficient for GCD?
<p>I know that Euclid’s algorithm is the best algorithm for getting the GCD (great common divisor) of a list of positive integers.&#xA;But in practice you can code this algorithm in various ways. (In my case, I decided to use Java, but C/C++ may be another option).</p>&#xA;&#xA;<p>I need to use the most efficient code possible in my program.</p>&#xA;&#xA;<p>In recursive mode, you can write:</p>&#xA;&#xA;<pre><code>static long gcd (long a, long b){&#xA; a = Math.abs(a); b = Math.abs(b);&#xA; return (b==0) ? a : gcd(b, a%b);&#xA; }&#xA;</code></pre>&#xA;&#xA;<p>And in iterative mode, it looks like this:</p>&#xA;&#xA;<pre><code>static long gcd (long a, long b) {&#xA; long r, i;&#xA; while(b!=0){&#xA; r = a % b;&#xA; a = b;&#xA; b = r;&#xA; }&#xA; return a;&#xA;}&#xA;</code></pre>&#xA;&#xA;<hr>&#xA;&#xA;<p>There is also the Binary algorithm for the GCD, which may be coded simply like this:</p>&#xA;&#xA;<pre><code>int gcd (int a, int b)&#xA;{&#xA; while(b) b ^= a ^= b ^= a %= b;&#xA; return a;&#xA;}&#xA;</code></pre>&#xA;
algorithms recursion arithmetic
1
What is most efficient for GCD? -- (algorithms recursion arithmetic) <p>I know that Euclid’s algorithm is the best algorithm for getting the GCD (great common divisor) of a list of positive integers.&#xA;But in practice you can code this algorithm in various ways. (In my case, I decided to use Java, but C/C++ may be another option).</p>&#xA;&#xA;<p>I need to use the most efficient code possible in my program.</p>&#xA;&#xA;<p>In recursive mode, you can write:</p>&#xA;&#xA;<pre><code>static long gcd (long a, long b){&#xA; a = Math.abs(a); b = Math.abs(b);&#xA; return (b==0) ? a : gcd(b, a%b);&#xA; }&#xA;</code></pre>&#xA;&#xA;<p>And in iterative mode, it looks like this:</p>&#xA;&#xA;<pre><code>static long gcd (long a, long b) {&#xA; long r, i;&#xA; while(b!=0){&#xA; r = a % b;&#xA; a = b;&#xA; b = r;&#xA; }&#xA; return a;&#xA;}&#xA;</code></pre>&#xA;&#xA;<hr>&#xA;&#xA;<p>There is also the Binary algorithm for the GCD, which may be coded simply like this:</p>&#xA;&#xA;<pre><code>int gcd (int a, int b)&#xA;{&#xA; while(b) b ^= a ^= b ^= a %= b;&#xA; return a;&#xA;}&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
1,455
How to use adversary arguments for selection and insertion sort?
<p>I was asked to find the adversary arguments necessary for finding the lower bounds for selection and insertion sort. I could not find a reference to it anywhere.</p>&#xA;&#xA;<p>I have some doubts regarding this. I understand that adversary arguments are usually used for finding lower bounds for certain "problems" rather than "algorithms".</p>&#xA;&#xA;<p>I understand the merging problem. But how could I write one for selection and insertion sort?</p>&#xA;
algorithms algorithm analysis proof techniques lower bounds
1
How to use adversary arguments for selection and insertion sort? -- (algorithms algorithm analysis proof techniques lower bounds) <p>I was asked to find the adversary arguments necessary for finding the lower bounds for selection and insertion sort. I could not find a reference to it anywhere.</p>&#xA;&#xA;<p>I have some doubts regarding this. I understand that adversary arguments are usually used for finding lower bounds for certain "problems" rather than "algorithms".</p>&#xA;&#xA;<p>I understand the merging problem. But how could I write one for selection and insertion sort?</p>&#xA;
habedi/stack-exchange-dataset
1,458
Encoding the sequence 0110 and determining parity, data bit and value
<p>I've been struggling with several Hamming code/error detection questions because the logic behind it doesn't seem to make sense.</p>&#xA;<p>eg.1</p>&#xA;<p><img src="https://i.stack.imgur.com/v9F4w.png" alt="enter image description here" /></p>&#xA;<p>eg.2</p>&#xA;<p><img src="https://i.stack.imgur.com/tGxIZ.png" alt="enter image description here" /></p>&#xA;<p>I don't really understand the above two examples and the calculations taking place.</p>&#xA;<p>How were the conclusions reached concerning the categories of <strong>bin position (dec/bin), parity/data bit and value</strong> in <strong>e.g 1</strong>?</p>&#xA;<p>Secondly I don't understand the process taking place in <strong>e.g. 2</strong> at all. Does it follow that:</p>&#xA;<blockquote>&#xA;<p>General rule: For any code C,</p>&#xA;<ul>&#xA;<li>errors of less than <span class="math-container">$d(C)$</span> bits can be detected,</li>&#xA;<li>errors of less than <span class="math-container">$d(C)/2$</span> bits can be corrected.</li>&#xA;</ul>&#xA;<p>Definition: A code C with <span class="math-container">$d(C) \geq 3$</span> is called error-correcting.</p>&#xA;</blockquote>&#xA;<p>If this is correct then how would I put it into practice. Would really appreciate some assistance!</p>&#xA;
coding theory
1
Encoding the sequence 0110 and determining parity, data bit and value -- (coding theory) <p>I've been struggling with several Hamming code/error detection questions because the logic behind it doesn't seem to make sense.</p>&#xA;<p>eg.1</p>&#xA;<p><img src="https://i.stack.imgur.com/v9F4w.png" alt="enter image description here" /></p>&#xA;<p>eg.2</p>&#xA;<p><img src="https://i.stack.imgur.com/tGxIZ.png" alt="enter image description here" /></p>&#xA;<p>I don't really understand the above two examples and the calculations taking place.</p>&#xA;<p>How were the conclusions reached concerning the categories of <strong>bin position (dec/bin), parity/data bit and value</strong> in <strong>e.g 1</strong>?</p>&#xA;<p>Secondly I don't understand the process taking place in <strong>e.g. 2</strong> at all. Does it follow that:</p>&#xA;<blockquote>&#xA;<p>General rule: For any code C,</p>&#xA;<ul>&#xA;<li>errors of less than <span class="math-container">$d(C)$</span> bits can be detected,</li>&#xA;<li>errors of less than <span class="math-container">$d(C)/2$</span> bits can be corrected.</li>&#xA;</ul>&#xA;<p>Definition: A code C with <span class="math-container">$d(C) \geq 3$</span> is called error-correcting.</p>&#xA;</blockquote>&#xA;<p>If this is correct then how would I put it into practice. Would really appreciate some assistance!</p>&#xA;
habedi/stack-exchange-dataset
1,466
Circle Intersection with Sweep Line Algorithm
<p>Unfortunately I am still not so strong in understanding <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm">Sweep Line Algorithm</a>. All papers and textbooks on the topic are already read, however understanding is still far away. Just in order to make it clearer I try to solve as many exercises as I can. But, really interesting and important tasks are still a challenge for me.</p>&#xA;&#xA;<p>The following exercise I found in lecture notes of <a href="http://theory.cs.uiuc.edu/~jeffe/teaching/algorithms/notes/xo-sweepline.pdf">Line Segment Intersection</a> by omnipotent Jeff Erickson.</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Exercise 2.</strong> Describe and analyze a sweepline algorithm to determine, given $n$ circles in the plane, whether any two intersect, in $O(n \log n)$ time. Each circle is specified by its center and its radius, so the input consists of three arrays $X[1.. n], Y [1.. n]$, and $R[1.. n]$. Be careful to correctly implement the low-level primitives.</p>&#xA;</blockquote>&#xA;&#xA;<p>Let's try to make a complex thing easier. What do we know about intersection of circles? What analogue can be found with intersection of lines. Two lines might intersect if they adjacent, which property two circle should have in order to intersect? Let $d$ be the distance between the center of the circles, $r_{0}$ and $r_{1}$ centers of the circles. Consider few cases:</p>&#xA;&#xA;<ul>&#xA;<li><p>Case 1: If $d &gt; r_{0} + r_{1}$ then there are no solutions, the circles are separate.</p></li>&#xA;<li><p>Case 2: If $d &lt; |r_{0} - r_{1}|$ then there are no solutions because one circle is contained within the other.</p></li>&#xA;<li><p>Case 3: If $d = 0$ and $r_{0} = r_{1}$ then the circles are coincident and there are an infinite number of solutions.</p></li>&#xA;</ul>&#xA;&#xA;<p>So, it looks like conditions of intersection are ready, of course it may be wrong conditions. Please correct if it's so.</p>&#xA;&#xA;<p><strong>Algorithm.</strong> Now we need to find something in common between two intersecting circles. With analogue to line intersection, we need to have insert condition and delete condition to event queue. Let's say event point are x coordinate of the first and the last points which vertical sweep line touches. On the first point we insert circle to <em>status</em>&#xA; and check for intersection (3 cases for checking are mentioned above) with nearest circles, on the last point we delete circle from <em>status</em>.</p>&#xA;&#xA;<p>It looks like is enough for sweep line algorithm. If there is something wrong, or may be there is something what should be done different, feel free to share your thoughts with us.</p>&#xA;&#xA;<p><strong>Addendum</strong>:</p>&#xA;&#xA;<p>I insert a circle when vertical sweep line touches the circle for the first time, and remove a circle from the status when sweep line touches it for the last time. The check for intersection should be done for the nearest previous circle. If we added a circle to <em>status</em> and there was already another circle which we added before and it was still there, therefore the pervious circle was not "closed", so there might be an intersection.</p>&#xA;
algorithms computational geometry
1
Circle Intersection with Sweep Line Algorithm -- (algorithms computational geometry) <p>Unfortunately I am still not so strong in understanding <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm">Sweep Line Algorithm</a>. All papers and textbooks on the topic are already read, however understanding is still far away. Just in order to make it clearer I try to solve as many exercises as I can. But, really interesting and important tasks are still a challenge for me.</p>&#xA;&#xA;<p>The following exercise I found in lecture notes of <a href="http://theory.cs.uiuc.edu/~jeffe/teaching/algorithms/notes/xo-sweepline.pdf">Line Segment Intersection</a> by omnipotent Jeff Erickson.</p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Exercise 2.</strong> Describe and analyze a sweepline algorithm to determine, given $n$ circles in the plane, whether any two intersect, in $O(n \log n)$ time. Each circle is specified by its center and its radius, so the input consists of three arrays $X[1.. n], Y [1.. n]$, and $R[1.. n]$. Be careful to correctly implement the low-level primitives.</p>&#xA;</blockquote>&#xA;&#xA;<p>Let's try to make a complex thing easier. What do we know about intersection of circles? What analogue can be found with intersection of lines. Two lines might intersect if they adjacent, which property two circle should have in order to intersect? Let $d$ be the distance between the center of the circles, $r_{0}$ and $r_{1}$ centers of the circles. Consider few cases:</p>&#xA;&#xA;<ul>&#xA;<li><p>Case 1: If $d &gt; r_{0} + r_{1}$ then there are no solutions, the circles are separate.</p></li>&#xA;<li><p>Case 2: If $d &lt; |r_{0} - r_{1}|$ then there are no solutions because one circle is contained within the other.</p></li>&#xA;<li><p>Case 3: If $d = 0$ and $r_{0} = r_{1}$ then the circles are coincident and there are an infinite number of solutions.</p></li>&#xA;</ul>&#xA;&#xA;<p>So, it looks like conditions of intersection are ready, of course it may be wrong conditions. Please correct if it's so.</p>&#xA;&#xA;<p><strong>Algorithm.</strong> Now we need to find something in common between two intersecting circles. With analogue to line intersection, we need to have insert condition and delete condition to event queue. Let's say event point are x coordinate of the first and the last points which vertical sweep line touches. On the first point we insert circle to <em>status</em>&#xA; and check for intersection (3 cases for checking are mentioned above) with nearest circles, on the last point we delete circle from <em>status</em>.</p>&#xA;&#xA;<p>It looks like is enough for sweep line algorithm. If there is something wrong, or may be there is something what should be done different, feel free to share your thoughts with us.</p>&#xA;&#xA;<p><strong>Addendum</strong>:</p>&#xA;&#xA;<p>I insert a circle when vertical sweep line touches the circle for the first time, and remove a circle from the status when sweep line touches it for the last time. The check for intersection should be done for the nearest previous circle. If we added a circle to <em>status</em> and there was already another circle which we added before and it was still there, therefore the pervious circle was not "closed", so there might be an intersection.</p>&#xA;
habedi/stack-exchange-dataset
1,467
Words that have the same right- and left-associative product
<p>I have started to study non deterministic automata using the book of <a href="https://en.wikipedia.org/wiki/Introduction_to_Automata_Theory,_Languages,_and_Computation" rel="nofollow">Hopcroft and Ullman</a>. I'm stuck in a problem that I found very interesting:</p>&#xA;&#xA;<blockquote>&#xA; <p>Give a non deterministic finite automaton accepting all the strings that&#xA; have the same value when evaluated left to right as right to left by&#xA; multiplying according to the following table:</p>&#xA; &#xA; <p>$\qquad \displaystyle\begin{array}{c|ccc} &#xD;&#xA; \times &amp; a &amp; b &amp; c \\&#xD;&#xA; \hline &#xD;&#xA; a &amp; a &amp; a &amp; c \\&#xD;&#xA; b &amp; c &amp; a &amp; b \\&#xD;&#xA; c &amp; b &amp; c &amp;a&#xD;&#xA; \end{array}$</p>&#xA;</blockquote>&#xA;&#xA;<p>So if we have the string $abc$,<br>&#xA;the product from left to right is $(a \times b) \times c=a \times c=c$ and<br>&#xA;the product from right to left is $a \times (b \times c)=a \times b=a$</p>&#xA;&#xA;<p>So $abc$ should not be acceptable for the automata. To me its obvious that any string $aa^*$ or $bb^*$ or $cc^*$ is an aceptable string (their right and left evaluation work on the same partial strings). It is easy to give an NFA that describes the left to right evaluation but the problem is that if the machine try to compute the <em>right to left</em> evaluation I think it needs to know the length of the string (so infinite memory is necessary).</p>&#xA;&#xA;<p>So how can a non deterministic automata evaluate from right to left in order to compare with the left to right evaluation?</p>&#xA;
formal languages automata regular languages finite automata nondeterminism
1
Words that have the same right- and left-associative product -- (formal languages automata regular languages finite automata nondeterminism) <p>I have started to study non deterministic automata using the book of <a href="https://en.wikipedia.org/wiki/Introduction_to_Automata_Theory,_Languages,_and_Computation" rel="nofollow">Hopcroft and Ullman</a>. I'm stuck in a problem that I found very interesting:</p>&#xA;&#xA;<blockquote>&#xA; <p>Give a non deterministic finite automaton accepting all the strings that&#xA; have the same value when evaluated left to right as right to left by&#xA; multiplying according to the following table:</p>&#xA; &#xA; <p>$\qquad \displaystyle\begin{array}{c|ccc} &#xD;&#xA; \times &amp; a &amp; b &amp; c \\&#xD;&#xA; \hline &#xD;&#xA; a &amp; a &amp; a &amp; c \\&#xD;&#xA; b &amp; c &amp; a &amp; b \\&#xD;&#xA; c &amp; b &amp; c &amp;a&#xD;&#xA; \end{array}$</p>&#xA;</blockquote>&#xA;&#xA;<p>So if we have the string $abc$,<br>&#xA;the product from left to right is $(a \times b) \times c=a \times c=c$ and<br>&#xA;the product from right to left is $a \times (b \times c)=a \times b=a$</p>&#xA;&#xA;<p>So $abc$ should not be acceptable for the automata. To me its obvious that any string $aa^*$ or $bb^*$ or $cc^*$ is an aceptable string (their right and left evaluation work on the same partial strings). It is easy to give an NFA that describes the left to right evaluation but the problem is that if the machine try to compute the <em>right to left</em> evaluation I think it needs to know the length of the string (so infinite memory is necessary).</p>&#xA;&#xA;<p>So how can a non deterministic automata evaluate from right to left in order to compare with the left to right evaluation?</p>&#xA;
habedi/stack-exchange-dataset
1,469
Null Characters and Splitting the String in the Pumping Lemma
<p>So I'm really struggling with the pumping lemma. I think most of my problems come from not understanding how you can and can't split the string in a pumping lemma question. Here is an example, take the problem prove that $L = \{w | w$ contains more $0$'s than $1$'s over the language $\{0,1\} \}$ is not regular via the pumping lemma.</p>&#xA;&#xA;<p>So I choose the string $01^{p}0^{p}$. Since this is a regular language pumping lemma problem I know that: </p>&#xA;&#xA;<ol>&#xA;<li>for each $i &gt; 0, xy^{i}z \in A$,</li>&#xA;<li>$|y^{i}| &gt; 0$, and</li>&#xA;<li>$|xy| &lt; p$</li>&#xA;</ol>&#xA;&#xA;<p>I am little uncertain about other possibilites though, such as if $x$, or $z$ can be null (obviously $y$ can't by condition 2). I assume that this isn't possible since I don't think the preceding or trailing whitespace is considered part of the string, but I'm not sure. <strong>Is it possible for $x$ or $z$ to be null?</strong></p>&#xA;
formal languages regular languages proof techniques pumping lemma
1
Null Characters and Splitting the String in the Pumping Lemma -- (formal languages regular languages proof techniques pumping lemma) <p>So I'm really struggling with the pumping lemma. I think most of my problems come from not understanding how you can and can't split the string in a pumping lemma question. Here is an example, take the problem prove that $L = \{w | w$ contains more $0$'s than $1$'s over the language $\{0,1\} \}$ is not regular via the pumping lemma.</p>&#xA;&#xA;<p>So I choose the string $01^{p}0^{p}$. Since this is a regular language pumping lemma problem I know that: </p>&#xA;&#xA;<ol>&#xA;<li>for each $i &gt; 0, xy^{i}z \in A$,</li>&#xA;<li>$|y^{i}| &gt; 0$, and</li>&#xA;<li>$|xy| &lt; p$</li>&#xA;</ol>&#xA;&#xA;<p>I am little uncertain about other possibilites though, such as if $x$, or $z$ can be null (obviously $y$ can't by condition 2). I assume that this isn't possible since I don't think the preceding or trailing whitespace is considered part of the string, but I'm not sure. <strong>Is it possible for $x$ or $z$ to be null?</strong></p>&#xA;
habedi/stack-exchange-dataset
1,471
Looking for a ranking algorithm that favors newer entries
<p>I'm working on a ranking system that will rank entries based on votes that have been cast over a period of time. I'm looking for an algorithm that will calculate a score which is kinda like an average, however I would like it to favor newer scores over older ones. I was thinking of something along the line of: </p>&#xA;&#xA;<p>$$\frac{\mathrm{score}_1 +\ 2\cdot \mathrm{score}_2\ +\ \dots +\ n\cdot \mathrm{score}_n}{1 + 2 + \dots + n}$$</p>&#xA;&#xA;<p>I was wondering if there were other algorithms which are usually used for situations like this and if so, could you please explain them?</p>&#xA;
algorithms data mining
1
Looking for a ranking algorithm that favors newer entries -- (algorithms data mining) <p>I'm working on a ranking system that will rank entries based on votes that have been cast over a period of time. I'm looking for an algorithm that will calculate a score which is kinda like an average, however I would like it to favor newer scores over older ones. I was thinking of something along the line of: </p>&#xA;&#xA;<p>$$\frac{\mathrm{score}_1 +\ 2\cdot \mathrm{score}_2\ +\ \dots +\ n\cdot \mathrm{score}_n}{1 + 2 + \dots + n}$$</p>&#xA;&#xA;<p>I was wondering if there were other algorithms which are usually used for situations like this and if so, could you please explain them?</p>&#xA;
habedi/stack-exchange-dataset
1,477
Dealing with intractability: NP-complete problems
<p>Assume that I am a programmer and I have an NP-complete problem that I need to solve it. What methods are available to deal with NPC problems? Is there a survey or something similar on this topic?</p>&#xA;
algorithms reference request np complete efficiency reference question
1
Dealing with intractability: NP-complete problems -- (algorithms reference request np complete efficiency reference question) <p>Assume that I am a programmer and I have an NP-complete problem that I need to solve it. What methods are available to deal with NPC problems? Is there a survey or something similar on this topic?</p>&#xA;
habedi/stack-exchange-dataset
1,485
Complexity of finding the largest $m$ numbers in an array of size $n$
<p>What follows is my algorithm for doing this in what I believe to be $O(n)$ time, and my proof for that. My professor disagrees that it runs in $O(n)$ and instead thinks that it runs in $\Omega(n^2)$ time. Any comments regarding the proof itself, or the style (i.e. my ideas may be clear but the presentation not).</p>&#xA;&#xA;<p>The original question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Given $n$ numbers, find the largest $m \leq n$ among them in time $o(n \log n)$. You may not assume anything else about $m$.</p>&#xA;</blockquote>&#xA;&#xA;<p>My answer:</p>&#xA;&#xA;<ol>&#xA;<li>Sort the first $m$ elements of the array. This takes $O(1)$ time, as this is totally dependent on $m$, not $n$.</li>&#xA;<li>Store them in a linked list (maintaining the sorted order). This also takes $O(1)$ time, for the same reason as above.</li>&#xA;<li>For every other element in the array, test if it is greater than the least element of the linked list. This takes $O(n)$ time as $n$ comparisons must be done.</li>&#xA;<li>If the number is in fact greater, then delete the first element of the linked list (the lowest one) and insert the new number in the location that would keep the list in sorted order. This takes $O(1)$ time because it is bounded by a constant ($m$) above as the list does not grow.</li>&#xA;<li>Therefore, the total complexity for the algorithm is $O(n)$.</li>&#xA;</ol>&#xA;&#xA;<p>I am aware that using a red-black tree as opposed to linked list is more efficient in constant terms (as the constant upper bound is $O(m\cdot \log_2(m))$ as opposed to $m$ and the problem of keeping a pointer to the lowest element of the tree (to facilitate the comparisons) is eminently doable, it just didn't occur to me at the time.</p>&#xA;&#xA;<p>What is my proof missing? Is there a more standard way of presenting it (even if it is incorrect)?</p>&#xA;
algorithms time complexity runtime analysis
1
Complexity of finding the largest $m$ numbers in an array of size $n$ -- (algorithms time complexity runtime analysis) <p>What follows is my algorithm for doing this in what I believe to be $O(n)$ time, and my proof for that. My professor disagrees that it runs in $O(n)$ and instead thinks that it runs in $\Omega(n^2)$ time. Any comments regarding the proof itself, or the style (i.e. my ideas may be clear but the presentation not).</p>&#xA;&#xA;<p>The original question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Given $n$ numbers, find the largest $m \leq n$ among them in time $o(n \log n)$. You may not assume anything else about $m$.</p>&#xA;</blockquote>&#xA;&#xA;<p>My answer:</p>&#xA;&#xA;<ol>&#xA;<li>Sort the first $m$ elements of the array. This takes $O(1)$ time, as this is totally dependent on $m$, not $n$.</li>&#xA;<li>Store them in a linked list (maintaining the sorted order). This also takes $O(1)$ time, for the same reason as above.</li>&#xA;<li>For every other element in the array, test if it is greater than the least element of the linked list. This takes $O(n)$ time as $n$ comparisons must be done.</li>&#xA;<li>If the number is in fact greater, then delete the first element of the linked list (the lowest one) and insert the new number in the location that would keep the list in sorted order. This takes $O(1)$ time because it is bounded by a constant ($m$) above as the list does not grow.</li>&#xA;<li>Therefore, the total complexity for the algorithm is $O(n)$.</li>&#xA;</ol>&#xA;&#xA;<p>I am aware that using a red-black tree as opposed to linked list is more efficient in constant terms (as the constant upper bound is $O(m\cdot \log_2(m))$ as opposed to $m$ and the problem of keeping a pointer to the lowest element of the tree (to facilitate the comparisons) is eminently doable, it just didn't occur to me at the time.</p>&#xA;&#xA;<p>What is my proof missing? Is there a more standard way of presenting it (even if it is incorrect)?</p>&#xA;
habedi/stack-exchange-dataset
1,493
Requirements for emulation
<p>What are the complete specifications that must be documented in order to ensure the correct execution of a particular program written in Java? For instance, if one were archiving a program for long-term preservation, and no testing or porting would be done.</p>&#xA;&#xA;<p>I need to be able to compile and execute the Java program. Thus preserving the byte code or capturing the whole thing as a VMware image are excluded. The JVM could be saved as a VMware image though, and compiled libraries that are linked to the compiled code are OK, too. However, if there are dependencies on the OS, the architecture of the machine executing the JVM, the networking environment, external libraries, specification of the Java version used, etc. etc. these must all be listed. Some tech leaders in Dig Pres claim that any program written in Java will be executable "forever". How to do it?</p>&#xA;
operating systems computer architecture digital preservation
1
Requirements for emulation -- (operating systems computer architecture digital preservation) <p>What are the complete specifications that must be documented in order to ensure the correct execution of a particular program written in Java? For instance, if one were archiving a program for long-term preservation, and no testing or porting would be done.</p>&#xA;&#xA;<p>I need to be able to compile and execute the Java program. Thus preserving the byte code or capturing the whole thing as a VMware image are excluded. The JVM could be saved as a VMware image though, and compiled libraries that are linked to the compiled code are OK, too. However, if there are dependencies on the OS, the architecture of the machine executing the JVM, the networking environment, external libraries, specification of the Java version used, etc. etc. these must all be listed. Some tech leaders in Dig Pres claim that any program written in Java will be executable "forever". How to do it?</p>&#xA;
habedi/stack-exchange-dataset
1,494
Find the longest path from root to leaf in a tree
<p>I have a <a href="https://www.iis.se/docs/DNS-bok-sid-14.jpg" rel="noreferrer">tree</a> (in the graph theory sense), such as the following example:</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/sK90D.jpg" alt="enter image description here"></p>&#xA;&#xA;<p>This is a directed tree with one starting node (the root) and many ending nodes (the leaves). Each of the edge has a length assigned to it.</p>&#xA;&#xA;<p>My question is, how to find the longest path starting at the root and ending at any of the leaves? The brute-force approach is to check all the root-leaf paths and taking the one with maximal length, but I would prefer a more efficient algorithm if there is one. </p>&#xA;
algorithms graphs
1
Find the longest path from root to leaf in a tree -- (algorithms graphs) <p>I have a <a href="https://www.iis.se/docs/DNS-bok-sid-14.jpg" rel="noreferrer">tree</a> (in the graph theory sense), such as the following example:</p>&#xA;&#xA;<p><img src="https://i.stack.imgur.com/sK90D.jpg" alt="enter image description here"></p>&#xA;&#xA;<p>This is a directed tree with one starting node (the root) and many ending nodes (the leaves). Each of the edge has a length assigned to it.</p>&#xA;&#xA;<p>My question is, how to find the longest path starting at the root and ending at any of the leaves? The brute-force approach is to check all the root-leaf paths and taking the one with maximal length, but I would prefer a more efficient algorithm if there is one. </p>&#xA;
habedi/stack-exchange-dataset
1,495
What is the most efficient way to compute factorials modulo a prime?
<p>Do you know any algorithm that calculates the factorial after modulus efficiently?</p>&#xA;&#xA;<p>For example, I want to program:</p>&#xA;&#xA;<pre><code>for(i=0; i&lt;5; i++)&#xA; sum += factorial(p-i) % p;&#xA;</code></pre>&#xA;&#xA;<p>But, <code>p</code> is a big number (prime) for applying factorial directly $(p \leq 10^ 8)$.</p>&#xA;&#xA;<p>In Python, this task is really easy, but i really want to know how to optimize.</p>&#xA;
algorithms efficiency integers
1
What is the most efficient way to compute factorials modulo a prime? -- (algorithms efficiency integers) <p>Do you know any algorithm that calculates the factorial after modulus efficiently?</p>&#xA;&#xA;<p>For example, I want to program:</p>&#xA;&#xA;<pre><code>for(i=0; i&lt;5; i++)&#xA; sum += factorial(p-i) % p;&#xA;</code></pre>&#xA;&#xA;<p>But, <code>p</code> is a big number (prime) for applying factorial directly $(p \leq 10^ 8)$.</p>&#xA;&#xA;<p>In Python, this task is really easy, but i really want to know how to optimize.</p>&#xA;
habedi/stack-exchange-dataset
1,507
Runtime of the optimal greedy $2$-approximation algorithm for the $k$-clustering problem
<p>We are given a set 2-dimensional points $|P| = n$ and an integer $k$. We must find a collection of $k$ circles that enclose all the $n$ points such that the radius of the largest circle is as small as possible. In other words, we must find a set $C = \{ c_1,c_2,\ldots,c_k\}$ of $k$ center points such that the cost function $\text{cost}(C) = \max_i \min_j D(p_i, c_j)$ is minimized. Here, $D$ denotes the Euclidean distance between an input point $p_i$ and a center point $c_j$. Each point assigns itself to the closest cluster center grouping the vertices into $k$ different clusters.</p>&#xA;&#xA;<p>The problem is known as the (discrete) $k$-clustering problem and it is $\text{NP}$-hard. It can be shown with a reduction from the $\text{NP}$-complete dominating set problem that if there exists a $\rho$-approximation algorithm for the problem with $\rho &lt; 2$ then $\text{P} = \text{NP}$. </p>&#xA;&#xA;<p>The optimal $2$-approximation algorithm is very simple and intuitive. One first picks a point $p \in P$ arbitrarily and puts it in the set $C$ of cluster centers. Then one picks the next cluster center such that is as far away as possible from all the other cluster centers. So while $|C| &lt; k$, we repeatedly find a point $j \in P$ for which the distance $D(j,C)$ is maximized and add it to $C$. Once $|C| = k$ we are done.</p>&#xA;&#xA;<p>It is not hard to see that the optimal greedy algorithm runs in $O(nk)$ time. This raises a question: can we achieve $o(nk)$ time? How much better can we do?</p>&#xA;
algorithms computational geometry
1
Runtime of the optimal greedy $2$-approximation algorithm for the $k$-clustering problem -- (algorithms computational geometry) <p>We are given a set 2-dimensional points $|P| = n$ and an integer $k$. We must find a collection of $k$ circles that enclose all the $n$ points such that the radius of the largest circle is as small as possible. In other words, we must find a set $C = \{ c_1,c_2,\ldots,c_k\}$ of $k$ center points such that the cost function $\text{cost}(C) = \max_i \min_j D(p_i, c_j)$ is minimized. Here, $D$ denotes the Euclidean distance between an input point $p_i$ and a center point $c_j$. Each point assigns itself to the closest cluster center grouping the vertices into $k$ different clusters.</p>&#xA;&#xA;<p>The problem is known as the (discrete) $k$-clustering problem and it is $\text{NP}$-hard. It can be shown with a reduction from the $\text{NP}$-complete dominating set problem that if there exists a $\rho$-approximation algorithm for the problem with $\rho &lt; 2$ then $\text{P} = \text{NP}$. </p>&#xA;&#xA;<p>The optimal $2$-approximation algorithm is very simple and intuitive. One first picks a point $p \in P$ arbitrarily and puts it in the set $C$ of cluster centers. Then one picks the next cluster center such that is as far away as possible from all the other cluster centers. So while $|C| &lt; k$, we repeatedly find a point $j \in P$ for which the distance $D(j,C)$ is maximized and add it to $C$. Once $|C| = k$ we are done.</p>&#xA;&#xA;<p>It is not hard to see that the optimal greedy algorithm runs in $O(nk)$ time. This raises a question: can we achieve $o(nk)$ time? How much better can we do?</p>&#xA;
habedi/stack-exchange-dataset
1,511
"Dense" regular expressions generate $\Sigma^*$?
<p>Here's a conjecture for regular expressions:</p>&#xA;&#xA;<blockquote>&#xA; <p>For regular expression $R$, let the length $|R|$ be the number of symbols in it,&#xA; ignoring parentheses and operators. E.g. $|0 \cup 1| = |(0 \cup 1)^*| = 2$</p>&#xA; &#xA; <p><strong>Conjecture:</strong> If $|R| &gt; 1$ and $L(R)$ contains every string of length $|R|$ or less, then $L(R) = \Sigma^*$.</p>&#xA;</blockquote>&#xA;&#xA;<p>That is, if $L(R)$ is 'dense' up to $R$'s length, then $R$ actually generates everything.</p>&#xA;&#xA;<p>Some things that may be relevant:</p>&#xA;&#xA;<ol>&#xA;<li>Only a small part of $R$ is needed to generate all strings. For example in binary, $R = (0 \cup 1)^* \cup S$ will work for any $S$.</li>&#xA;<li>There needs to be a Kleene star in $R$ at some point. If there isn't, it will miss some string of size less than $|R|$. </li>&#xA;</ol>&#xA;&#xA;<p>It would be nice to see a proof or counterexample. Is there some case where it's obviously wrong that I missed? Has anyone seen this (or something similar) before? </p>&#xA;
formal languages regular languages regular expressions
1
"Dense" regular expressions generate $\Sigma^*$? -- (formal languages regular languages regular expressions) <p>Here's a conjecture for regular expressions:</p>&#xA;&#xA;<blockquote>&#xA; <p>For regular expression $R$, let the length $|R|$ be the number of symbols in it,&#xA; ignoring parentheses and operators. E.g. $|0 \cup 1| = |(0 \cup 1)^*| = 2$</p>&#xA; &#xA; <p><strong>Conjecture:</strong> If $|R| &gt; 1$ and $L(R)$ contains every string of length $|R|$ or less, then $L(R) = \Sigma^*$.</p>&#xA;</blockquote>&#xA;&#xA;<p>That is, if $L(R)$ is 'dense' up to $R$'s length, then $R$ actually generates everything.</p>&#xA;&#xA;<p>Some things that may be relevant:</p>&#xA;&#xA;<ol>&#xA;<li>Only a small part of $R$ is needed to generate all strings. For example in binary, $R = (0 \cup 1)^* \cup S$ will work for any $S$.</li>&#xA;<li>There needs to be a Kleene star in $R$ at some point. If there isn't, it will miss some string of size less than $|R|$. </li>&#xA;</ol>&#xA;&#xA;<p>It would be nice to see a proof or counterexample. Is there some case where it's obviously wrong that I missed? Has anyone seen this (or something similar) before? </p>&#xA;
habedi/stack-exchange-dataset
1,514
Is it possible to create a "Time Capsule" using encryption?
<p>I want to create a digital time capsule which will remain unreadable for some period of time and then become readable. I do not want to rely on any outside service to, for instance, keep the key secret and then reveal it at the required time. Is this possible? If not, is some kind of proof possible that it is not?</p>&#xA;&#xA;<p>One strategy would be based on projections of future computing capabilities, but that is unreliable and makes assumptions about how many resources would be applied to the task.</p>&#xA;
cryptography encryption digital preservation
1
Is it possible to create a "Time Capsule" using encryption? -- (cryptography encryption digital preservation) <p>I want to create a digital time capsule which will remain unreadable for some period of time and then become readable. I do not want to rely on any outside service to, for instance, keep the key secret and then reveal it at the required time. Is this possible? If not, is some kind of proof possible that it is not?</p>&#xA;&#xA;<p>One strategy would be based on projections of future computing capabilities, but that is unreliable and makes assumptions about how many resources would be applied to the task.</p>&#xA;
habedi/stack-exchange-dataset
1,517
If A is mapping reducible to B then the complement of A is mapping reducible to the complement of B
<p>I'm studying for my final in theory of computation, and I'm struggling with the proper way of answering whether this statement is true of false.</p>&#xA;&#xA;<p>By the <a href="https://en.wikipedia.org/wiki/Mapping_reducibility" rel="noreferrer">definition</a> of $\leq_m$ we can construct the following statement, </p>&#xA;&#xA;<p>$w \in A \iff f(w) \in B \rightarrow w \notin A \iff f(w) \notin B$ </p>&#xA;&#xA;<p>This is where I'm stuck, I want to say that since we have such computable function $f$ then it'll only give us the mapping from A to B if there is one, otherwise it wont. </p>&#xA;&#xA;<p>I don't know how to phrase this correctly, or if I'm even on the right track.</p>&#xA;
complexity theory computability reductions
1
If A is mapping reducible to B then the complement of A is mapping reducible to the complement of B -- (complexity theory computability reductions) <p>I'm studying for my final in theory of computation, and I'm struggling with the proper way of answering whether this statement is true of false.</p>&#xA;&#xA;<p>By the <a href="https://en.wikipedia.org/wiki/Mapping_reducibility" rel="noreferrer">definition</a> of $\leq_m$ we can construct the following statement, </p>&#xA;&#xA;<p>$w \in A \iff f(w) \in B \rightarrow w \notin A \iff f(w) \notin B$ </p>&#xA;&#xA;<p>This is where I'm stuck, I want to say that since we have such computable function $f$ then it'll only give us the mapping from A to B if there is one, otherwise it wont. </p>&#xA;&#xA;<p>I don't know how to phrase this correctly, or if I'm even on the right track.</p>&#xA;
habedi/stack-exchange-dataset
1,525
Chomsky normal form and regular languages
<p>I'd love your help with the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let $G$ be context free grammar in the <strong>Chomksy normal form</strong> with $k$&#xA; variables.</p>&#xA; &#xA; <p>Is the language $B = \{ w \in L(G) : |w| &gt;2^k \}$ regular ?</p>&#xA;</blockquote>&#xA;&#xA;<p>What is it about the amount of variables and the Chomsky normal form that is supposed to help me solve this question? I tried to look it up on the web, but besides information about the special form itself, I didn't find an answer to my question.</p>&#xA;&#xA;<p>The answer for the question is that $B$ might be regular.</p>&#xA;
formal languages regular languages context free formal grammars
1
Chomsky normal form and regular languages -- (formal languages regular languages context free formal grammars) <p>I'd love your help with the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let $G$ be context free grammar in the <strong>Chomksy normal form</strong> with $k$&#xA; variables.</p>&#xA; &#xA; <p>Is the language $B = \{ w \in L(G) : |w| &gt;2^k \}$ regular ?</p>&#xA;</blockquote>&#xA;&#xA;<p>What is it about the amount of variables and the Chomsky normal form that is supposed to help me solve this question? I tried to look it up on the web, but besides information about the special form itself, I didn't find an answer to my question.</p>&#xA;&#xA;<p>The answer for the question is that $B$ might be regular.</p>&#xA;
habedi/stack-exchange-dataset
1,531
Is Logical Min-Cut NP-Complete?
<h3>Logical Min Cut (LMC) problem definition</h3>&#xA;&#xA;<p>Suppose that $G = (V, E)$ is an unweighted digraph, $s$ and $t$ are two vertices of $V$, and $t$ is reachable from $s$. The LMC Problem studies how we can make $t$ unreachable from $s$ by the removal of some edges of $G$ following the following constraints:</p>&#xA;&#xA;<ol>&#xA;<li>The number of the removed edges must be minimal.</li>&#xA;<li>We cannot remove every exit edge of any vertex of $G$ (i.e., no vertex with outgoing edges can have all its outgoing edges removed).</li>&#xA;</ol>&#xA;&#xA;<p>This second constraint is called logical removal. So we look for a <em>logical, minimal removal</em> of some edges of $G$ such that $t$ would be unreachable from $s$.</p>&#xA;&#xA;<h3>Solution attempts</h3>&#xA;&#xA;<p>If we ignore the logical removal constraint of LMC problem, it will be the min-cut problem in the unweighted digraph $G$, so it will be solvable polynomially (max-flow min-cut theorem).</p>&#xA;&#xA;<p>If we ignore the minimal removal constraint of the LMC problem, it will be again solvable polynomially in a DAG: find a vertex $k$ such that $k$ is reachable from $s$ and $t$ is not reachable from $k$. Then consider a path $p$ which is an arbitrary path from $s$ to $k$. Now consider the path $p$ as a subgraph of $G$: the answer will be every exit edge of the subgraph $p$. It is obvious that the vertex $k$ can be found by DFS in $G$ in polynomial time. Unfortunately this algorithm <a href="https://cs.stackexchange.com/questions/1531/is-logical-min-cut-np-complete#comment13693_1531">doesn't work in general</a> for an arbitrary directed graph.</p>&#xA;&#xA;<p>I tried to solve the LMC problem by a dynamic programming technique but the number of required states for solving the problem became exponential. Moreover, I tried to reduce some NP-Complete problems such as 3-SAT, max2Sat, max-cut, and clique to the LMC problem I didn't manage to find a reduction.</p>&#xA;&#xA;<p>I personally think that the LMC problem is NP-Complete even if $G$ is a binary DAG (i.e., a DAG where no node has out-degree greater than 2).</p>&#xA;&#xA;<h3>Questions</h3>&#xA;&#xA;<ol>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary digraph $G$? (main question)</li>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary DAG $G$?</li>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary binary DAG $G$?</li>&#xA;</ol>&#xA;
complexity theory graphs np complete
1
Is Logical Min-Cut NP-Complete? -- (complexity theory graphs np complete) <h3>Logical Min Cut (LMC) problem definition</h3>&#xA;&#xA;<p>Suppose that $G = (V, E)$ is an unweighted digraph, $s$ and $t$ are two vertices of $V$, and $t$ is reachable from $s$. The LMC Problem studies how we can make $t$ unreachable from $s$ by the removal of some edges of $G$ following the following constraints:</p>&#xA;&#xA;<ol>&#xA;<li>The number of the removed edges must be minimal.</li>&#xA;<li>We cannot remove every exit edge of any vertex of $G$ (i.e., no vertex with outgoing edges can have all its outgoing edges removed).</li>&#xA;</ol>&#xA;&#xA;<p>This second constraint is called logical removal. So we look for a <em>logical, minimal removal</em> of some edges of $G$ such that $t$ would be unreachable from $s$.</p>&#xA;&#xA;<h3>Solution attempts</h3>&#xA;&#xA;<p>If we ignore the logical removal constraint of LMC problem, it will be the min-cut problem in the unweighted digraph $G$, so it will be solvable polynomially (max-flow min-cut theorem).</p>&#xA;&#xA;<p>If we ignore the minimal removal constraint of the LMC problem, it will be again solvable polynomially in a DAG: find a vertex $k$ such that $k$ is reachable from $s$ and $t$ is not reachable from $k$. Then consider a path $p$ which is an arbitrary path from $s$ to $k$. Now consider the path $p$ as a subgraph of $G$: the answer will be every exit edge of the subgraph $p$. It is obvious that the vertex $k$ can be found by DFS in $G$ in polynomial time. Unfortunately this algorithm <a href="https://cs.stackexchange.com/questions/1531/is-logical-min-cut-np-complete#comment13693_1531">doesn't work in general</a> for an arbitrary directed graph.</p>&#xA;&#xA;<p>I tried to solve the LMC problem by a dynamic programming technique but the number of required states for solving the problem became exponential. Moreover, I tried to reduce some NP-Complete problems such as 3-SAT, max2Sat, max-cut, and clique to the LMC problem I didn't manage to find a reduction.</p>&#xA;&#xA;<p>I personally think that the LMC problem is NP-Complete even if $G$ is a binary DAG (i.e., a DAG where no node has out-degree greater than 2).</p>&#xA;&#xA;<h3>Questions</h3>&#xA;&#xA;<ol>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary digraph $G$? (main question)</li>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary DAG $G$?</li>&#xA;<li>Is the LMC problem NP-Complete in an arbitrary binary DAG $G$?</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
1,536
Closure against the operator $A(L)=\{ww^Rw \mid w \in L \wedge |w| \lt 2007\}$
<p>I would like your help with the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let $L$ be a language, and operator $A(L)=\{\,ww^Rw \mid w \in L\ \wedge\ |w| \lt 2007\,\}$ where $x^R$ is the reversed string of $x$. Which of the&#xA; following statements are correct?</p>&#xA; &#xA; <ol>&#xA; <li>If $L$ is regular so $A(L)$ is regular.</li>&#xA; <li>If $L$ is a CFL which is not regular then $A(L)$ is CFL which is not regular.</li>&#xA; <li>If $L$ is a CFL which is not regular, then $A(L)$ is a CFL which may or may not be regular.</li>&#xA; <li>If $L$ is not a CFL then $A(L)$ is not CFL.</li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<p>What does the fact that $|w|&lt; 2007$ help me with the decision? &#xA;For (2) I can choose $O^n1^n$ and I get that $0^n1^{2n}0^{2n}1^n$, which is not regular, but for (3),(4) I can't find an examples to refute it. The answer is 3, but I can't understand why, since $A(L)= ww^R \circ w$ but $ww^R$ is not regular.</p>&#xA;
formal languages regular languages context free closure properties
1
Closure against the operator $A(L)=\{ww^Rw \mid w \in L \wedge |w| \lt 2007\}$ -- (formal languages regular languages context free closure properties) <p>I would like your help with the following question:</p>&#xA;&#xA;<blockquote>&#xA; <p>Let $L$ be a language, and operator $A(L)=\{\,ww^Rw \mid w \in L\ \wedge\ |w| \lt 2007\,\}$ where $x^R$ is the reversed string of $x$. Which of the&#xA; following statements are correct?</p>&#xA; &#xA; <ol>&#xA; <li>If $L$ is regular so $A(L)$ is regular.</li>&#xA; <li>If $L$ is a CFL which is not regular then $A(L)$ is CFL which is not regular.</li>&#xA; <li>If $L$ is a CFL which is not regular, then $A(L)$ is a CFL which may or may not be regular.</li>&#xA; <li>If $L$ is not a CFL then $A(L)$ is not CFL.</li>&#xA; </ol>&#xA;</blockquote>&#xA;&#xA;<p>What does the fact that $|w|&lt; 2007$ help me with the decision? &#xA;For (2) I can choose $O^n1^n$ and I get that $0^n1^{2n}0^{2n}1^n$, which is not regular, but for (3),(4) I can't find an examples to refute it. The answer is 3, but I can't understand why, since $A(L)= ww^R \circ w$ but $ww^R$ is not regular.</p>&#xA;
habedi/stack-exchange-dataset
1,542
Approximation algorithm for TSP variant, fixed start and end anywhere but starting point + multiple visits at each vertex ALLOWED
<p>NOTE: Due to the fact that the trip does not end at the same place it started and also the fact that every point can be visited more than once as long as I still visit all of them, this is not really a TSP variant, but I put it due to lack of a better definition of the problem.</p>&#xA;&#xA;<p>This problem was originally posted on StackOverflow, but I was told that this would be a better place. I got one pointer, which converted the problem from non-metric to a metric one.</p>&#xA;&#xA;<p>So..</p>&#xA;&#xA;<p>Suppose I am going on a hiking trip with n points of interest. These points are all connected by hiking trails. I have a map showing all trails with their distances, giving me a directed graph.</p>&#xA;&#xA;<p>My problem is how to approximate a tour that starts at a point A and visits all n points of interest, while ending the tour anywhere but the point where I started and I want the tour to be as short as possible.</p>&#xA;&#xA;<p>Due to the nature of hiking, I figured this would sadly not be a symmetric problem (or can I convert my asymmetric graph to a symmetric one?), since going from high to low altitude is obviously easier than the other way around.</p>&#xA;&#xA;<p>Since there are no restrictions regarding how many times I visit each point, as long as I visit all of them, it does not matter if the shortest path from a to d goes through b and c. Is this enough to say that triangle inequality holds and thus I have a metric problem?</p>&#xA;&#xA;<p>I believe my problem is easier than TSP, so those algorithms do not fit this problem. I thought about using a minimum spanning tree, but I have a hard time applying it to this problem, which under the circumstances, should be a metric asymmetric directed graph?</p>&#xA;&#xA;<p>What I really want are some pointers as to how I can come up with an approximation algorithm that will find a near optimal tour through all n points</p>&#xA;
algorithms complexity theory graphs approximation
1
Approximation algorithm for TSP variant, fixed start and end anywhere but starting point + multiple visits at each vertex ALLOWED -- (algorithms complexity theory graphs approximation) <p>NOTE: Due to the fact that the trip does not end at the same place it started and also the fact that every point can be visited more than once as long as I still visit all of them, this is not really a TSP variant, but I put it due to lack of a better definition of the problem.</p>&#xA;&#xA;<p>This problem was originally posted on StackOverflow, but I was told that this would be a better place. I got one pointer, which converted the problem from non-metric to a metric one.</p>&#xA;&#xA;<p>So..</p>&#xA;&#xA;<p>Suppose I am going on a hiking trip with n points of interest. These points are all connected by hiking trails. I have a map showing all trails with their distances, giving me a directed graph.</p>&#xA;&#xA;<p>My problem is how to approximate a tour that starts at a point A and visits all n points of interest, while ending the tour anywhere but the point where I started and I want the tour to be as short as possible.</p>&#xA;&#xA;<p>Due to the nature of hiking, I figured this would sadly not be a symmetric problem (or can I convert my asymmetric graph to a symmetric one?), since going from high to low altitude is obviously easier than the other way around.</p>&#xA;&#xA;<p>Since there are no restrictions regarding how many times I visit each point, as long as I visit all of them, it does not matter if the shortest path from a to d goes through b and c. Is this enough to say that triangle inequality holds and thus I have a metric problem?</p>&#xA;&#xA;<p>I believe my problem is easier than TSP, so those algorithms do not fit this problem. I thought about using a minimum spanning tree, but I have a hard time applying it to this problem, which under the circumstances, should be a metric asymmetric directed graph?</p>&#xA;&#xA;<p>What I really want are some pointers as to how I can come up with an approximation algorithm that will find a near optimal tour through all n points</p>&#xA;
habedi/stack-exchange-dataset
1,547
Closure against right quotient with a fixed language
<p>I'd really love your help with the following:</p>&#xA;&#xA;<p>For <em>any</em> fixed $L_2$ I need to decide whether there is closure under the following operators:</p>&#xA;&#xA;<ol>&#xA;<li><p>$A_r(L)=\{x \mid \exists y \in L_2 : xy \in L\}$</p></li>&#xA;<li><p>$A_l(L)=\{x \mid \exists y \in L : xy \in L_2\}$.</p></li>&#xA;</ol>&#xA;&#xA;<p>The relevant options are:</p>&#xA;&#xA;<ol>&#xA;<li><p>Regular languages are closed under $A_l$ resp. $A_r$, for any language $L_2$ </p></li>&#xA;<li><p>For some languages $L_2$, regular languages are closed under $A_l$ resp. $A_r$, and for some languages $L_2$, regular languages are not closed under $A_l$ resp. $A_r$.</p></li>&#xA;</ol>&#xA;&#xA;<p>I believed that the answer for (1) should be (2), because when I get a word in $w \in L$ and $w=xy$ I can build an automaton that can guess where $x$ turning to $y$, but then it needs to verify that $y$ belongs to $L_2$ and if it won't be regular, how would it do that?<br>&#xA;The answer for that is (1).</p>&#xA;&#xA;<p>What should I do in order to analyze those operators correctly and to determine if the regular languages are closed under them or not?</p>&#xA;
formal languages regular languages closure properties
1
Closure against right quotient with a fixed language -- (formal languages regular languages closure properties) <p>I'd really love your help with the following:</p>&#xA;&#xA;<p>For <em>any</em> fixed $L_2$ I need to decide whether there is closure under the following operators:</p>&#xA;&#xA;<ol>&#xA;<li><p>$A_r(L)=\{x \mid \exists y \in L_2 : xy \in L\}$</p></li>&#xA;<li><p>$A_l(L)=\{x \mid \exists y \in L : xy \in L_2\}$.</p></li>&#xA;</ol>&#xA;&#xA;<p>The relevant options are:</p>&#xA;&#xA;<ol>&#xA;<li><p>Regular languages are closed under $A_l$ resp. $A_r$, for any language $L_2$ </p></li>&#xA;<li><p>For some languages $L_2$, regular languages are closed under $A_l$ resp. $A_r$, and for some languages $L_2$, regular languages are not closed under $A_l$ resp. $A_r$.</p></li>&#xA;</ol>&#xA;&#xA;<p>I believed that the answer for (1) should be (2), because when I get a word in $w \in L$ and $w=xy$ I can build an automaton that can guess where $x$ turning to $y$, but then it needs to verify that $y$ belongs to $L_2$ and if it won't be regular, how would it do that?<br>&#xA;The answer for that is (1).</p>&#xA;&#xA;<p>What should I do in order to analyze those operators correctly and to determine if the regular languages are closed under them or not?</p>&#xA;
habedi/stack-exchange-dataset
1,556
Is $A=\{ w \in \{a,b,c\}^* \mid \#_a(w)+ 2\#_b(w) = 3\#_c(w)\}$ a CFG?
<p>I wonder whether the following language is a context free language:&#xA;$$A = \{w \in \{a,b,c\}^* \mid \#_a(w) + 2\#_b(w) = 3\#c(w)\}$$&#xA;where $\#_x(w)$ is the number of occurrences of $x$ in $w$.&#xA;I can't find any word that would be useful to refute by the pumping lemma, on the other hand I haven't been able to find a context free grammar generating it. It looks like it has to remember more than one PDA can handle.</p>&#xA;&#xA;<p>What do you say?</p>&#xA;
formal languages context free
1
Is $A=\{ w \in \{a,b,c\}^* \mid \#_a(w)+ 2\#_b(w) = 3\#_c(w)\}$ a CFG? -- (formal languages context free) <p>I wonder whether the following language is a context free language:&#xA;$$A = \{w \in \{a,b,c\}^* \mid \#_a(w) + 2\#_b(w) = 3\#c(w)\}$$&#xA;where $\#_x(w)$ is the number of occurrences of $x$ in $w$.&#xA;I can't find any word that would be useful to refute by the pumping lemma, on the other hand I haven't been able to find a context free grammar generating it. It looks like it has to remember more than one PDA can handle.</p>&#xA;&#xA;<p>What do you say?</p>&#xA;
habedi/stack-exchange-dataset
1,560
Can a program language be malleable enough to allow programs to extend language semantics
<p>With reference to features in languages like ruby (and javascript), which allow a programmer to extend/override classes any time after defining it (including classes like String), is it theoretically feasible to design a language which can allow programs to later on extend its semantics.</p>&#xA;&#xA;<p>ex: Ruby does not allow multiple inheritance, yet can I extend/override the default language behaviour to allow an implementation of multiple inheritance. </p>&#xA;&#xA;<p>Are there any other languages which allow this? Is this actually a subject of concern for language designers? Looking at the choice of using ruby for building rails framework for web application development, such languages may be very powerful to allow designing frameworks(or DSLs) for wide variety of applications.</p>&#xA;
programming languages semantics
1
Can a program language be malleable enough to allow programs to extend language semantics -- (programming languages semantics) <p>With reference to features in languages like ruby (and javascript), which allow a programmer to extend/override classes any time after defining it (including classes like String), is it theoretically feasible to design a language which can allow programs to later on extend its semantics.</p>&#xA;&#xA;<p>ex: Ruby does not allow multiple inheritance, yet can I extend/override the default language behaviour to allow an implementation of multiple inheritance. </p>&#xA;&#xA;<p>Are there any other languages which allow this? Is this actually a subject of concern for language designers? Looking at the choice of using ruby for building rails framework for web application development, such languages may be very powerful to allow designing frameworks(or DSLs) for wide variety of applications.</p>&#xA;
habedi/stack-exchange-dataset
1,562
Turing reducibility implies mapping reducibility
<p>The question is whether the following statement is true or false:</p>&#xA;&#xA;<p>$A \leq_T B \implies A \leq_m B$</p>&#xA;&#xA;<p>I know that if $A \leq_T B$ then there is an oracle which can decide A relative to B. I know that this is not enough to say that there is a computable function from A to B that can satisfy the reduction.</p>&#xA;&#xA;<p>I don't know how to word this in the proper way or if what I'm saying is enough to say that the statement is false. How would I go about showing this?</p>&#xA;&#xA;<p>EDIT: This is not a homework problem per se, I'm reviewing for a test.&#xA;Where $\leq_T$ is <a href="http://en.wikipedia.org/wiki/Turing_reduction" rel="nofollow">Turing reducibility</a>, and $\leq_m$ is <a href="http://en.wikipedia.org/wiki/Mapping_reduction" rel="nofollow">mapping reducibility</a>.</p>&#xA;
computability reductions turing machines
1
Turing reducibility implies mapping reducibility -- (computability reductions turing machines) <p>The question is whether the following statement is true or false:</p>&#xA;&#xA;<p>$A \leq_T B \implies A \leq_m B$</p>&#xA;&#xA;<p>I know that if $A \leq_T B$ then there is an oracle which can decide A relative to B. I know that this is not enough to say that there is a computable function from A to B that can satisfy the reduction.</p>&#xA;&#xA;<p>I don't know how to word this in the proper way or if what I'm saying is enough to say that the statement is false. How would I go about showing this?</p>&#xA;&#xA;<p>EDIT: This is not a homework problem per se, I'm reviewing for a test.&#xA;Where $\leq_T$ is <a href="http://en.wikipedia.org/wiki/Turing_reduction" rel="nofollow">Turing reducibility</a>, and $\leq_m$ is <a href="http://en.wikipedia.org/wiki/Mapping_reduction" rel="nofollow">mapping reducibility</a>.</p>&#xA;
habedi/stack-exchange-dataset
1,567
Running time - Linked Lists Polynomial
<p>I have developed two algorithms and now they are asking me to find their running time.&#xA;The problem is to develop a singly linked list version for manipulating polynomials. The two main operations are <em>addition</em> and <em>multiplication</em>.</p>&#xA;&#xA;<p>In general for lists the running for these two operations are ($x,y$ are the lists lengths):</p>&#xA;&#xA;<ul>&#xA;<li>Addition: Time $O(x+y)$, space $O(x+y)$</li>&#xA;<li>Multiplication: Time $O(xy \log(xy))$, space $O(xy)$</li>&#xA;</ul>&#xA;&#xA;<p>Can someone help me to find the running times of my algorithms?&#xA;I think for the first algorithm it is like stated above $O(x+y)$, for the second one I have two nested loops and two lists so it should be $O(xy)$, but why the $O(xy \log(xy))$ above?</p>&#xA;&#xA;<p>These are the algorithms I developed (in Pseudocode):</p>&#xA;&#xA;<pre><code> PolynomialAdd(Poly1, Poly2):&#xA; Degree := MaxDegree(Poly1.head, Poly2.head);&#xA; while (Degree &gt;=0) do:&#xA; Node1 := Poly1.head;&#xA; while (Node1 IS NOT NIL) do:&#xA; if(Node1.Deg = Degree) then break;&#xA; else Node1 = Node1.next;&#xA; Node2 := Poly2.head;&#xA; while (Node2 IS NOT NIL) do:&#xA; if(Node2.Deg = Degree) then break;&#xA; else Node2 = Node2.next;&#xA; if (Node1 IS NOT NIL AND Node2 IS NOT NIL) then&#xA; PolyResult.insertTerm( Node1.Coeff + Node2.Coeff, Node1.Deg);&#xA; else if (Node1 IS NOT NIL) then&#xA; PolyResult.insertTerm(Node1.Coeff, Node1.Deg);&#xA; else if (Node2 IS NOT NIL) then&#xA; PolyResult.insertTerm(Node2.Coeff, Node2.Deg);&#xA; Degree := Degree – 1;&#xA; return PolyResult; &#xA;&#xA; PolynomialMul(Poly1, Poly2): &#xA; Node1 := Poly1.head;&#xA; while (Node1 IS NOT NIL) do:&#xA; Node2 = Poly2.head;&#xA; while (Node2 IS NOT NIL) do:&#xA; PolyResult.insertTerm(Node1.Coeff * Node2.Coeff, &#xA; Node1.Deg + Node1.Deg);&#xA; Node2 = Node2.next; &#xA; Node1 = Node1.next;&#xA; return PolyResult;&#xA;</code></pre>&#xA;&#xA;<p><code>InsertTerm</code> inserts the term in the correct place depending on the degree of the term. </p>&#xA;&#xA;<pre><code> InsertTerm(Coeff, Deg):&#xA; NewNode.Coeff := Coeff;&#xA; NewNode.Deg := Deg;&#xA; if List.head = NIL then&#xA; List.head := NewNode;&#xA; else if NewNode.Deg &gt; List.head.Deg then&#xA; NewNode.next := List.head;&#xA; List.head := NewNode;&#xA; else if NewNode.Deg = List.head.Deg then &#xA; AddCoeff(NewNode, List.head);&#xA; else&#xA; Go through the List till find the same Degree and summing up the coefficient OR&#xA; adding a new Term in the right position if Degree not present;&#xA;</code></pre>&#xA;
algorithms algorithm analysis runtime analysis
1
Running time - Linked Lists Polynomial -- (algorithms algorithm analysis runtime analysis) <p>I have developed two algorithms and now they are asking me to find their running time.&#xA;The problem is to develop a singly linked list version for manipulating polynomials. The two main operations are <em>addition</em> and <em>multiplication</em>.</p>&#xA;&#xA;<p>In general for lists the running for these two operations are ($x,y$ are the lists lengths):</p>&#xA;&#xA;<ul>&#xA;<li>Addition: Time $O(x+y)$, space $O(x+y)$</li>&#xA;<li>Multiplication: Time $O(xy \log(xy))$, space $O(xy)$</li>&#xA;</ul>&#xA;&#xA;<p>Can someone help me to find the running times of my algorithms?&#xA;I think for the first algorithm it is like stated above $O(x+y)$, for the second one I have two nested loops and two lists so it should be $O(xy)$, but why the $O(xy \log(xy))$ above?</p>&#xA;&#xA;<p>These are the algorithms I developed (in Pseudocode):</p>&#xA;&#xA;<pre><code> PolynomialAdd(Poly1, Poly2):&#xA; Degree := MaxDegree(Poly1.head, Poly2.head);&#xA; while (Degree &gt;=0) do:&#xA; Node1 := Poly1.head;&#xA; while (Node1 IS NOT NIL) do:&#xA; if(Node1.Deg = Degree) then break;&#xA; else Node1 = Node1.next;&#xA; Node2 := Poly2.head;&#xA; while (Node2 IS NOT NIL) do:&#xA; if(Node2.Deg = Degree) then break;&#xA; else Node2 = Node2.next;&#xA; if (Node1 IS NOT NIL AND Node2 IS NOT NIL) then&#xA; PolyResult.insertTerm( Node1.Coeff + Node2.Coeff, Node1.Deg);&#xA; else if (Node1 IS NOT NIL) then&#xA; PolyResult.insertTerm(Node1.Coeff, Node1.Deg);&#xA; else if (Node2 IS NOT NIL) then&#xA; PolyResult.insertTerm(Node2.Coeff, Node2.Deg);&#xA; Degree := Degree – 1;&#xA; return PolyResult; &#xA;&#xA; PolynomialMul(Poly1, Poly2): &#xA; Node1 := Poly1.head;&#xA; while (Node1 IS NOT NIL) do:&#xA; Node2 = Poly2.head;&#xA; while (Node2 IS NOT NIL) do:&#xA; PolyResult.insertTerm(Node1.Coeff * Node2.Coeff, &#xA; Node1.Deg + Node1.Deg);&#xA; Node2 = Node2.next; &#xA; Node1 = Node1.next;&#xA; return PolyResult;&#xA;</code></pre>&#xA;&#xA;<p><code>InsertTerm</code> inserts the term in the correct place depending on the degree of the term. </p>&#xA;&#xA;<pre><code> InsertTerm(Coeff, Deg):&#xA; NewNode.Coeff := Coeff;&#xA; NewNode.Deg := Deg;&#xA; if List.head = NIL then&#xA; List.head := NewNode;&#xA; else if NewNode.Deg &gt; List.head.Deg then&#xA; NewNode.next := List.head;&#xA; List.head := NewNode;&#xA; else if NewNode.Deg = List.head.Deg then &#xA; AddCoeff(NewNode, List.head);&#xA; else&#xA; Go through the List till find the same Degree and summing up the coefficient OR&#xA; adding a new Term in the right position if Degree not present;&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
1,577
How do I test if a polygon is monotone with respect to a line?
<p>It's well known that <a href="http://en.wikipedia.org/wiki/Monotone_polygon" rel="nofollow noreferrer">monotone polygons</a> play a crucial role in <a href="http://en.wikipedia.org/wiki/Polygon_triangulation" rel="nofollow noreferrer">polygon triangulation</a>. </p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Definition:</strong> A polygon $P$ in the plane is called monotone with respect to a straight line $L$, if every line orthogonal to $L$ intersects $P$ at most twice.</p>&#xA;</blockquote>&#xA;&#xA;<p>Given a line $L$ and a polygon $P$, is there an efficient algorithm to determine if a polygon $P$ is monotone with respect to $L$?</p>&#xA;
algorithms computational geometry
1
How do I test if a polygon is monotone with respect to a line? -- (algorithms computational geometry) <p>It's well known that <a href="http://en.wikipedia.org/wiki/Monotone_polygon" rel="nofollow noreferrer">monotone polygons</a> play a crucial role in <a href="http://en.wikipedia.org/wiki/Polygon_triangulation" rel="nofollow noreferrer">polygon triangulation</a>. </p>&#xA;&#xA;<blockquote>&#xA; <p><strong>Definition:</strong> A polygon $P$ in the plane is called monotone with respect to a straight line $L$, if every line orthogonal to $L$ intersects $P$ at most twice.</p>&#xA;</blockquote>&#xA;&#xA;<p>Given a line $L$ and a polygon $P$, is there an efficient algorithm to determine if a polygon $P$ is monotone with respect to $L$?</p>&#xA;
habedi/stack-exchange-dataset
1,580
Distributed vs parallel computing
<p>I often hear people talking about <em>parallel</em> computing and <em>distributed</em> computing, but I'm under the impression that there is no clear boundary between the 2, and people tend to confuse that pretty easily, while I believe it is very different:</p>&#xA;&#xA;<ul>&#xA;<li><em>Parallel</em> computing is more tightly coupled to multi-threading, or how to make full use of a single CPU.</li>&#xA;<li><em>Distributed</em> computing refers to the notion of divide and conquer, executing sub-tasks on different machines and then merging the results.</li>&#xA;</ul>&#xA;&#xA;<p>However, since we stepped into the <em>Big Data</em> era, it seems the distinction is indeed melting, and most systems today use a combination of parallel and distributed computing.</p>&#xA;&#xA;<p>An example I use in my day-to-day job is Hadoop with the Map/Reduce paradigm, a clearly distributed system with workers executing tasks on different machines, but also taking full advantage of each machine with some parallel computing.</p>&#xA;&#xA;<p>I would like to get some advice to understand how exactly to make the distinction in today's world, and if we can still talk about parallel computing or there is no longer a clear distinction. To me it seems distributed computing has grown a lot over the past years, while parallel computing seems to stagnate, which could probably explain why I hear much more talking about distributing computations than parallelizing.</p>&#xA;
terminology distributed systems parallel computing
1
Distributed vs parallel computing -- (terminology distributed systems parallel computing) <p>I often hear people talking about <em>parallel</em> computing and <em>distributed</em> computing, but I'm under the impression that there is no clear boundary between the 2, and people tend to confuse that pretty easily, while I believe it is very different:</p>&#xA;&#xA;<ul>&#xA;<li><em>Parallel</em> computing is more tightly coupled to multi-threading, or how to make full use of a single CPU.</li>&#xA;<li><em>Distributed</em> computing refers to the notion of divide and conquer, executing sub-tasks on different machines and then merging the results.</li>&#xA;</ul>&#xA;&#xA;<p>However, since we stepped into the <em>Big Data</em> era, it seems the distinction is indeed melting, and most systems today use a combination of parallel and distributed computing.</p>&#xA;&#xA;<p>An example I use in my day-to-day job is Hadoop with the Map/Reduce paradigm, a clearly distributed system with workers executing tasks on different machines, but also taking full advantage of each machine with some parallel computing.</p>&#xA;&#xA;<p>I would like to get some advice to understand how exactly to make the distinction in today's world, and if we can still talk about parallel computing or there is no longer a clear distinction. To me it seems distributed computing has grown a lot over the past years, while parallel computing seems to stagnate, which could probably explain why I hear much more talking about distributing computations than parallelizing.</p>&#xA;
habedi/stack-exchange-dataset
1,591
Finding the maximum bandwidth along a single path in a network
<p>I am trying to search for an algorithm that can tell me which node has the highest download (or upload) capacity given a weighted directed graph, where weights correspond to individual link bandwidths. I have looked at the maximal flow problem and at the Edmond-Karp algorithm. My questions are the following: </p>&#xA;&#xA;<ol>&#xA;<li>Edmond-Karp just tells us how much throughput we can get (at the sink) from source to sink if any of the paths were used. Correct?</li>&#xA;<li>Edmond-Karp does not tell us which path can give us the maximum flow. Correct?</li>&#xA;</ol>&#xA;
algorithms graphs network flow
1
Finding the maximum bandwidth along a single path in a network -- (algorithms graphs network flow) <p>I am trying to search for an algorithm that can tell me which node has the highest download (or upload) capacity given a weighted directed graph, where weights correspond to individual link bandwidths. I have looked at the maximal flow problem and at the Edmond-Karp algorithm. My questions are the following: </p>&#xA;&#xA;<ol>&#xA;<li>Edmond-Karp just tells us how much throughput we can get (at the sink) from source to sink if any of the paths were used. Correct?</li>&#xA;<li>Edmond-Karp does not tell us which path can give us the maximum flow. Correct?</li>&#xA;</ol>&#xA;
habedi/stack-exchange-dataset
1,592
Why does $A(L)= \{ w_1w_2: |w_1|=|w_2|$ and $w_1, w_2^R \in L \}$ generate a context free language for regular $L$?
<p>How can I prove that the language that the operator $A$ defines for regular language $L$ is a context free language.</p>&#xA;&#xA;<p>$A(L)= \{ w_1w_2: |w_1|=|w_2|$ and $w_1, w_2^R \in L \}$, where $x^R$ is the reversed form of $x$. </p>&#xA;&#xA;<p>I understand that since $L$ is regular so does $L^R$.also on my way for a CFG I can reach $w_1$ by the CFG of $L$ concatenation with the one of $L^R$ for making $w_2$. so far I have a CFG, but what promises me that $|w_1|=|w_2|$? how can I generate a grammar that will also keep that in addition to the other conditions?</p>&#xA;
formal languages regular languages context free formal grammars
1
Why does $A(L)= \{ w_1w_2: |w_1|=|w_2|$ and $w_1, w_2^R \in L \}$ generate a context free language for regular $L$? -- (formal languages regular languages context free formal grammars) <p>How can I prove that the language that the operator $A$ defines for regular language $L$ is a context free language.</p>&#xA;&#xA;<p>$A(L)= \{ w_1w_2: |w_1|=|w_2|$ and $w_1, w_2^R \in L \}$, where $x^R$ is the reversed form of $x$. </p>&#xA;&#xA;<p>I understand that since $L$ is regular so does $L^R$.also on my way for a CFG I can reach $w_1$ by the CFG of $L$ concatenation with the one of $L^R$ for making $w_2$. so far I have a CFG, but what promises me that $|w_1|=|w_2|$? how can I generate a grammar that will also keep that in addition to the other conditions?</p>&#xA;
habedi/stack-exchange-dataset
1,597
Maximise sum of "non-overlapping" numbers in square array - help with proof
<p>A <a href="https://stackoverflow.com/questions/10378738/maximise-sum-of-non-overlapping-numbers-from-matrix">question was posted on Stack Overflow</a> asking for an algorithm to solve this problem:</p>&#xA;&#xA;<blockquote>&#xA; <p>I have a matrix (call it A) which is nxn. I wish to select a subset&#xA; (call it B) of points from matrix A. The subset will consist of n&#xA; elements, where one and only one element is taken from each row and&#xA; from each column of A. The output should provide a solution (B) such&#xA; that the sum of the elements that make up B is the maximum possible&#xA; value, given these constraints (eg. 25 in the example below). If&#xA; multiple instances of B are found (ie. different solutions which give&#xA; the same maximum sum) the solution for B which has the largest minimum&#xA; element should be selected.</p>&#xA; &#xA; <p>B could also be a selection matrix which is nxn, but where only the n&#xA; desired elements are non-zero.</p>&#xA; &#xA; <p>For example: if A =</p>&#xA;&#xA;<pre><code>|5 4 3 2 1|&#xA;|4 3 2 1 5|&#xA;|3 2 1 5 4|&#xA;|2 1 5 4 3|&#xA;|1 5 4 3 2|&#xA;</code></pre>&#xA; &#xA; <p>=> B would be</p>&#xA;&#xA;<pre><code> |5 5 5 5 5|&#xA;</code></pre>&#xA;</blockquote>&#xA;&#xA;<p>I <a href="https://stackoverflow.com/a/10387455/1191425">proposed a dynamic programming solution</a> which I suspect is as efficient as any solution is going to get. I've copy-pasted my proposed algorithm below.</p>&#xA;&#xA;<hr>&#xA;&#xA;<ul>&#xA;<li>Let $A$ be a square array of $n$ by $n$ numbers.</li>&#xA;<li>Let $A_{i,j}$ denote the element of $A$ in the <code>i</code>th row and <code>j</code>th column.</li>&#xA;<li>Let $S( i_1:i_2, j_1:j_2 )$ denote the optimal sum of non-overlapping numbers for a square subarray of $A$ containing the intersection of rows $i_1$ to $i_2$ and columns $j_1$ to $j_2$.</li>&#xA;</ul>&#xA;&#xA;<p>Then the optimal sum of non-overlapping numbers is denoted <code>S( 1:n , 1:n )</code> and is given as follows:</p>&#xA;&#xA;<p>$$S( 1:n , 1:n ) = \max \left \{ \begin{array}{l} S( 2:n , 2:n ) + A_{1,1} \\&#xA; S( 2:n , 1:n-1 ) + A_{1,n} \\&#xA; S( 1:n-1 , 2:n ) + A_{n,1} \\&#xA; S( 1:n-1 , 1:n-1 ) + A_{n,n} \\&#xA; \end{array} \right.$$</p>&#xA;&#xA;<pre><code>Note that S( i:i, j:j ) is simply Aij.&#xA;</code></pre>&#xA;&#xA;<p>That is, the optimal sum for a square array of size <code>n</code> can be determined by separately computing the optimal sum for each of the four sub-arrays of size <code>n-1</code>, and then maximising the sum of the sub-array and the element that was "left out".</p>&#xA;&#xA;<pre><code>S for |# # # #|&#xA; |# # # #|&#xA; |# # # #|&#xA; |# # # #|&#xA;&#xA;Is the best of the sums S for:&#xA;&#xA;|# | | #| |# # # | | # # #|&#xA;| # # #| |# # # | |# # # | | # # #|&#xA;| # # #| |# # # | |# # # | | # # #|&#xA;| # # #| |# # # | | #| |# |&#xA;</code></pre>&#xA;&#xA;<hr>&#xA;&#xA;<p>This is a very elegant algorithm and I strongly suspect that it is correct, but I can't come up with a way to <strong>prove</strong> it is correct.</p>&#xA;&#xA;<p>The main difficulty I am having it proving that the problem displays optimal substructure. I believe that if the four potential choices in each calculation are the <em>only</em> four choices, then this is enough to show optimal substructure. That is, I need to prove that this:</p>&#xA;&#xA;<pre><code>| # |&#xA;| # # #|&#xA;| # # #| &#xA;| # # #|&#xA;</code></pre>&#xA;&#xA;<p>Is not a valid solution, either because it's impossible (i.e. proof by contradiction) or because this possibility is already accounted for by one of the four "<code>n-1</code> square" variations.</p>&#xA;&#xA;<p>Can anyone point out any flaws in my algorithm, or provide a proof that it really does work?</p>&#xA;
algorithms dynamic programming check my algorithm
1
Maximise sum of "non-overlapping" numbers in square array - help with proof -- (algorithms dynamic programming check my algorithm) <p>A <a href="https://stackoverflow.com/questions/10378738/maximise-sum-of-non-overlapping-numbers-from-matrix">question was posted on Stack Overflow</a> asking for an algorithm to solve this problem:</p>&#xA;&#xA;<blockquote>&#xA; <p>I have a matrix (call it A) which is nxn. I wish to select a subset&#xA; (call it B) of points from matrix A. The subset will consist of n&#xA; elements, where one and only one element is taken from each row and&#xA; from each column of A. The output should provide a solution (B) such&#xA; that the sum of the elements that make up B is the maximum possible&#xA; value, given these constraints (eg. 25 in the example below). If&#xA; multiple instances of B are found (ie. different solutions which give&#xA; the same maximum sum) the solution for B which has the largest minimum&#xA; element should be selected.</p>&#xA; &#xA; <p>B could also be a selection matrix which is nxn, but where only the n&#xA; desired elements are non-zero.</p>&#xA; &#xA; <p>For example: if A =</p>&#xA;&#xA;<pre><code>|5 4 3 2 1|&#xA;|4 3 2 1 5|&#xA;|3 2 1 5 4|&#xA;|2 1 5 4 3|&#xA;|1 5 4 3 2|&#xA;</code></pre>&#xA; &#xA; <p>=> B would be</p>&#xA;&#xA;<pre><code> |5 5 5 5 5|&#xA;</code></pre>&#xA;</blockquote>&#xA;&#xA;<p>I <a href="https://stackoverflow.com/a/10387455/1191425">proposed a dynamic programming solution</a> which I suspect is as efficient as any solution is going to get. I've copy-pasted my proposed algorithm below.</p>&#xA;&#xA;<hr>&#xA;&#xA;<ul>&#xA;<li>Let $A$ be a square array of $n$ by $n$ numbers.</li>&#xA;<li>Let $A_{i,j}$ denote the element of $A$ in the <code>i</code>th row and <code>j</code>th column.</li>&#xA;<li>Let $S( i_1:i_2, j_1:j_2 )$ denote the optimal sum of non-overlapping numbers for a square subarray of $A$ containing the intersection of rows $i_1$ to $i_2$ and columns $j_1$ to $j_2$.</li>&#xA;</ul>&#xA;&#xA;<p>Then the optimal sum of non-overlapping numbers is denoted <code>S( 1:n , 1:n )</code> and is given as follows:</p>&#xA;&#xA;<p>$$S( 1:n , 1:n ) = \max \left \{ \begin{array}{l} S( 2:n , 2:n ) + A_{1,1} \\&#xA; S( 2:n , 1:n-1 ) + A_{1,n} \\&#xA; S( 1:n-1 , 2:n ) + A_{n,1} \\&#xA; S( 1:n-1 , 1:n-1 ) + A_{n,n} \\&#xA; \end{array} \right.$$</p>&#xA;&#xA;<pre><code>Note that S( i:i, j:j ) is simply Aij.&#xA;</code></pre>&#xA;&#xA;<p>That is, the optimal sum for a square array of size <code>n</code> can be determined by separately computing the optimal sum for each of the four sub-arrays of size <code>n-1</code>, and then maximising the sum of the sub-array and the element that was "left out".</p>&#xA;&#xA;<pre><code>S for |# # # #|&#xA; |# # # #|&#xA; |# # # #|&#xA; |# # # #|&#xA;&#xA;Is the best of the sums S for:&#xA;&#xA;|# | | #| |# # # | | # # #|&#xA;| # # #| |# # # | |# # # | | # # #|&#xA;| # # #| |# # # | |# # # | | # # #|&#xA;| # # #| |# # # | | #| |# |&#xA;</code></pre>&#xA;&#xA;<hr>&#xA;&#xA;<p>This is a very elegant algorithm and I strongly suspect that it is correct, but I can't come up with a way to <strong>prove</strong> it is correct.</p>&#xA;&#xA;<p>The main difficulty I am having it proving that the problem displays optimal substructure. I believe that if the four potential choices in each calculation are the <em>only</em> four choices, then this is enough to show optimal substructure. That is, I need to prove that this:</p>&#xA;&#xA;<pre><code>| # |&#xA;| # # #|&#xA;| # # #| &#xA;| # # #|&#xA;</code></pre>&#xA;&#xA;<p>Is not a valid solution, either because it's impossible (i.e. proof by contradiction) or because this possibility is already accounted for by one of the four "<code>n-1</code> square" variations.</p>&#xA;&#xA;<p>Can anyone point out any flaws in my algorithm, or provide a proof that it really does work?</p>&#xA;
habedi/stack-exchange-dataset
1,603
Mapping Reductions to Complement of A$_{TM}$
<p>I have a general question about mapping reductions. I have seen several examples of reducing functions to $A_{TM}$</p>&#xA;&#xA;<p>where $A_{TM} = \{\langle M, w \rangle : \text{ For } M \text{ is a turing machine which accepts string } w\}$</p>&#xA;&#xA;<p>which is great for proving undecidability. But say I want to prove unrecognizability instead. That is, I want to use the corollary that given $A \le_{m} B$, if $A$ is unrecognizable then $B$ is unrecognizable.</p>&#xA;&#xA;<p>So for any arbitrary unrecognizable language $C$ which can be reduced to $\overline{A_{TM}}$ (any example language would suffice for sake of example), how can I reduce $\overline{A_{TM}} \le_{m} C$?</p>&#xA;&#xA;<p>For simplicity, suffice to merely consider TM in $\overline{A_{TM}}$.</p>&#xA;&#xA;<p><strong>EDIT</strong></p>&#xA;&#xA;<p>For clarification, $\overline{A_{TM}} = \{ \langle M, w \rangle : M \text{ is a turing machine which does not accept string } w \}$</p>&#xA;
computability proof techniques reductions
1
Mapping Reductions to Complement of A$_{TM}$ -- (computability proof techniques reductions) <p>I have a general question about mapping reductions. I have seen several examples of reducing functions to $A_{TM}$</p>&#xA;&#xA;<p>where $A_{TM} = \{\langle M, w \rangle : \text{ For } M \text{ is a turing machine which accepts string } w\}$</p>&#xA;&#xA;<p>which is great for proving undecidability. But say I want to prove unrecognizability instead. That is, I want to use the corollary that given $A \le_{m} B$, if $A$ is unrecognizable then $B$ is unrecognizable.</p>&#xA;&#xA;<p>So for any arbitrary unrecognizable language $C$ which can be reduced to $\overline{A_{TM}}$ (any example language would suffice for sake of example), how can I reduce $\overline{A_{TM}} \le_{m} C$?</p>&#xA;&#xA;<p>For simplicity, suffice to merely consider TM in $\overline{A_{TM}}$.</p>&#xA;&#xA;<p><strong>EDIT</strong></p>&#xA;&#xA;<p>For clarification, $\overline{A_{TM}} = \{ \langle M, w \rangle : M \text{ is a turing machine which does not accept string } w \}$</p>&#xA;
habedi/stack-exchange-dataset
1,606
Restricted version of the Clique problem?
<p>Consider the following version of the Clique problem where the input is of size $n$ and we're asked to find a clique of size $k$. The restriction is that the decision procedure cannot change the input graph into any other representation and cannot use any other representation to compute its answer, other than $\log(n^k)$ extra bits beyond the input graph. The extra bits can be used for example in the brute-force algorithm to keep track of the status of the exhaustive search for a clique, but the decision procedure is welcome to use them in any other way that still decides the problem.</p>&#xA;&#xA;<p>Is anything known at this point about the complexity of this? Has any work been done on other restrictions of Clique, and if so, could you direct me to such work?</p>&#xA;
complexity theory time complexity
1
Restricted version of the Clique problem? -- (complexity theory time complexity) <p>Consider the following version of the Clique problem where the input is of size $n$ and we're asked to find a clique of size $k$. The restriction is that the decision procedure cannot change the input graph into any other representation and cannot use any other representation to compute its answer, other than $\log(n^k)$ extra bits beyond the input graph. The extra bits can be used for example in the brute-force algorithm to keep track of the status of the exhaustive search for a clique, but the decision procedure is welcome to use them in any other way that still decides the problem.</p>&#xA;&#xA;<p>Is anything known at this point about the complexity of this? Has any work been done on other restrictions of Clique, and if so, could you direct me to such work?</p>&#xA;
habedi/stack-exchange-dataset
1,609
Example of Soundness & Completeness of Inference
<p>Is the following example correct about whether an <em>inference</em> algorithm is <em>sound</em> and <em>complete</em>? </p>&#xA;&#xA;<p>Suppose we have needles a, b, c in a haystack, and have also an inference algorithm that is designed to find needles.</p>&#xA;&#xA;<ul>&#xA;<li><p><em>sound</em> - Only needles a, b and c are obtained.</p></li>&#xA;<li><p><em>complete</em> - Needles a, b and c are obtained. Other hay may also be obtained.</p></li>&#xA;</ul>&#xA;
logic
1
Example of Soundness & Completeness of Inference -- (logic) <p>Is the following example correct about whether an <em>inference</em> algorithm is <em>sound</em> and <em>complete</em>? </p>&#xA;&#xA;<p>Suppose we have needles a, b, c in a haystack, and have also an inference algorithm that is designed to find needles.</p>&#xA;&#xA;<ul>&#xA;<li><p><em>sound</em> - Only needles a, b and c are obtained.</p></li>&#xA;<li><p><em>complete</em> - Needles a, b and c are obtained. Other hay may also be obtained.</p></li>&#xA;</ul>&#xA;
habedi/stack-exchange-dataset
1,616
Irregularity of $\{a^ib^jc^k \mid \text{if } i=1 \text{ then } j=k \}$
<p>I read <a href="https://cs.stackexchange.com/questions/1027/using-pumping-lemma-to-prove-language-is-not-regular">on the site</a> on how to use the pumping lemma but still I don't what is wrong with way I'm using it for proving that the following language is not a regular language:</p>&#xA;&#xA;<p>$L = \{a^ib^jc^k \mid \text{if } i=1 \text{ then } j=k \}$</p>&#xA;&#xA;<p>for $i\neq1$ the language is obviously regular but in the case which $i=1$ , we get that the language is $a^1b^nc^n$, now for every division $w=xyz$ such that $|y|&gt;0 , |xy|&lt; p$ where p is the pumping constant I get the word $a^1b^pc^p$ would be out of the language. since $|xy|&lt; p$&#xA;, $y$ may contains only $a's$ or $b's$ or both. if $x= \epsilon$ and $y=a$, pump it once and you're out of the language, if it contains only $b's$, pump it once and your'e out of the language, and if it contains both, pump it and you're out of the language again.</p>&#xA;&#xA;<p>so, why does this language considered as not regular and cannot be proved for its irregularity by the pumping lemma? please point out my mistake. </p>&#xA;
formal languages regular languages pumping lemma
1
Irregularity of $\{a^ib^jc^k \mid \text{if } i=1 \text{ then } j=k \}$ -- (formal languages regular languages pumping lemma) <p>I read <a href="https://cs.stackexchange.com/questions/1027/using-pumping-lemma-to-prove-language-is-not-regular">on the site</a> on how to use the pumping lemma but still I don't what is wrong with way I'm using it for proving that the following language is not a regular language:</p>&#xA;&#xA;<p>$L = \{a^ib^jc^k \mid \text{if } i=1 \text{ then } j=k \}$</p>&#xA;&#xA;<p>for $i\neq1$ the language is obviously regular but in the case which $i=1$ , we get that the language is $a^1b^nc^n$, now for every division $w=xyz$ such that $|y|&gt;0 , |xy|&lt; p$ where p is the pumping constant I get the word $a^1b^pc^p$ would be out of the language. since $|xy|&lt; p$&#xA;, $y$ may contains only $a's$ or $b's$ or both. if $x= \epsilon$ and $y=a$, pump it once and you're out of the language, if it contains only $b's$, pump it once and your'e out of the language, and if it contains both, pump it and you're out of the language again.</p>&#xA;&#xA;<p>so, why does this language considered as not regular and cannot be proved for its irregularity by the pumping lemma? please point out my mistake. </p>&#xA;
habedi/stack-exchange-dataset
1,632
All soldiers should shoot at the same time
<p>When I was a student, I saw a problem in a digital systems/logic design textbook, about N soldiers standing in a row, and want to shoot at the same time. A more difficult version of the problem was that the soldiers stand in a general network instead of a row. I am sure this is a classical problem, but I cannot remember its name. Can you remind me?</p>&#xA;
algorithms distributed systems clocks
1
All soldiers should shoot at the same time -- (algorithms distributed systems clocks) <p>When I was a student, I saw a problem in a digital systems/logic design textbook, about N soldiers standing in a row, and want to shoot at the same time. A more difficult version of the problem was that the soldiers stand in a general network instead of a row. I am sure this is a classical problem, but I cannot remember its name. Can you remind me?</p>&#xA;
habedi/stack-exchange-dataset
1,636
Reason to learn propositional & predicate logic
<p>I can understand the importance that computer scientists or any software development related engineers should have understood the study of basic logics as a basis. </p>&#xA;&#xA;<p>But is there any tasks/jobs that explicitly require the knowledge about these, other than the tasks that require any kind of knowledge representation using <code>Knowledge Base</code>? I want to hear the types of tasks, rather than conceptual responses.</p>&#xA;&#xA;<p>The reason I ask this is just from my curiosity. While CS students have to spend certain amount of time on this subject, some practicality-intensive courses (e.g. <a href="https://www.ai-class.com/">AI-Class</a>) skipped this topic entirely. And I just wonder that for example knowing <code>predicate logic</code> might help drawing <code>ER diagram</code> but might not be a requirement.</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>Update 5/27/2012) Thanks for answers. Now I think I totally understand &amp; agree with the importance of <code>logic</code>in CS with its vast amount of application. I just picked the best answer truly from the impressiveness that I got by the solution for <code>Windows</code>' blue screen issue.</p>&#xA;
logic
1
Reason to learn propositional & predicate logic -- (logic) <p>I can understand the importance that computer scientists or any software development related engineers should have understood the study of basic logics as a basis. </p>&#xA;&#xA;<p>But is there any tasks/jobs that explicitly require the knowledge about these, other than the tasks that require any kind of knowledge representation using <code>Knowledge Base</code>? I want to hear the types of tasks, rather than conceptual responses.</p>&#xA;&#xA;<p>The reason I ask this is just from my curiosity. While CS students have to spend certain amount of time on this subject, some practicality-intensive courses (e.g. <a href="https://www.ai-class.com/">AI-Class</a>) skipped this topic entirely. And I just wonder that for example knowing <code>predicate logic</code> might help drawing <code>ER diagram</code> but might not be a requirement.</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>Update 5/27/2012) Thanks for answers. Now I think I totally understand &amp; agree with the importance of <code>logic</code>in CS with its vast amount of application. I just picked the best answer truly from the impressiveness that I got by the solution for <code>Windows</code>' blue screen issue.</p>&#xA;
habedi/stack-exchange-dataset
1,643
How can we assume that basic operations on numbers take constant time?
<p>Normally in algorithms we do not care about comparison, addition, or subtraction of numbers -- we assume they run in time $O(1)$. For example, we assume this when we say that comparison-based sorting is $O(n\log n)$, but when numbers are too big to fit into registers, we normally represent them as arrays so basic operations require extra calculations per element.</p>&#xA;&#xA;<p>Is there a proof showing that comparison of two numbers (or other primitive arithmetic functions) can be done in $O(1)$? If not why are we saying that comparison based sorting is $O(n\log n)$?</p>&#xA;&#xA;<hr>&#xA;&#xA;<p><em>I encountered this problem when I answered a SO question and I realized that my algorithm is not $O(n)$ because sooner or later I should deal with big-int, also it wasn't pseudo polynomial time algorithm, it was $P$.</em></p>&#xA;
algorithms complexity theory algorithm analysis time complexity reference question
1
How can we assume that basic operations on numbers take constant time? -- (algorithms complexity theory algorithm analysis time complexity reference question) <p>Normally in algorithms we do not care about comparison, addition, or subtraction of numbers -- we assume they run in time $O(1)$. For example, we assume this when we say that comparison-based sorting is $O(n\log n)$, but when numbers are too big to fit into registers, we normally represent them as arrays so basic operations require extra calculations per element.</p>&#xA;&#xA;<p>Is there a proof showing that comparison of two numbers (or other primitive arithmetic functions) can be done in $O(1)$? If not why are we saying that comparison based sorting is $O(n\log n)$?</p>&#xA;&#xA;<hr>&#xA;&#xA;<p><em>I encountered this problem when I answered a SO question and I realized that my algorithm is not $O(n)$ because sooner or later I should deal with big-int, also it wasn't pseudo polynomial time algorithm, it was $P$.</em></p>&#xA;
habedi/stack-exchange-dataset
1,647
How to scale down parallel complexity results to constantly many cores?
<p>I have had problems accepting the complexity theoretic view of "efficiently solved by parallel algorithm" which is given by the class <a href="https://en.wikipedia.org/wiki/NC_%28complexity%29">NC</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>NC is the class of problems that can be solved by a parallel algorithm in time $O(\log^cn)$ on $p(n) \in O(n^k)$ processors with $c,k \in \mathbb{N}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>We can assume a <a href="https://en.wikipedia.org/wiki/Parallel_random_access_machine">PRAM</a>.</p>&#xA;&#xA;<p>My problem is that this does not seem to say much about "real" machines, that is machines with a finite amount of processors. Now I am told that "it is known" that we can "efficiently" simulate a $O(n^k)$ processor algorithm on $p \in \mathbb{N}$ processors.</p>&#xA;&#xA;<p>What does "efficiently" mean here? Is this folklore or is there a rigorous theorem which quantifies the overhead caused by simulation?</p>&#xA;&#xA;<p>What I am afraid that happens is that I have a problem which has a sequential $O(n^k)$ algorithm and also an "efficient" parallel algorithm which, when simulated on $p$ processors, also takes $O(n^k)$ time (which is all that can be expected on this granularity level of analysis if the sequential algorithm is asymptotically optimal). In this case, there is no speedup whatsover as far as we can see; in fact, the simulated parallel algorithm may be <em>slower</em> than the sequential algorithm. That is I am really looking for statements more precise than $O$-bounds (or a declaration of absence of such results).</p>&#xA;
complexity theory reference request parallel computing
1
How to scale down parallel complexity results to constantly many cores? -- (complexity theory reference request parallel computing) <p>I have had problems accepting the complexity theoretic view of "efficiently solved by parallel algorithm" which is given by the class <a href="https://en.wikipedia.org/wiki/NC_%28complexity%29">NC</a>:</p>&#xA;&#xA;<blockquote>&#xA; <p>NC is the class of problems that can be solved by a parallel algorithm in time $O(\log^cn)$ on $p(n) \in O(n^k)$ processors with $c,k \in \mathbb{N}$.</p>&#xA;</blockquote>&#xA;&#xA;<p>We can assume a <a href="https://en.wikipedia.org/wiki/Parallel_random_access_machine">PRAM</a>.</p>&#xA;&#xA;<p>My problem is that this does not seem to say much about "real" machines, that is machines with a finite amount of processors. Now I am told that "it is known" that we can "efficiently" simulate a $O(n^k)$ processor algorithm on $p \in \mathbb{N}$ processors.</p>&#xA;&#xA;<p>What does "efficiently" mean here? Is this folklore or is there a rigorous theorem which quantifies the overhead caused by simulation?</p>&#xA;&#xA;<p>What I am afraid that happens is that I have a problem which has a sequential $O(n^k)$ algorithm and also an "efficient" parallel algorithm which, when simulated on $p$ processors, also takes $O(n^k)$ time (which is all that can be expected on this granularity level of analysis if the sequential algorithm is asymptotically optimal). In this case, there is no speedup whatsover as far as we can see; in fact, the simulated parallel algorithm may be <em>slower</em> than the sequential algorithm. That is I am really looking for statements more precise than $O$-bounds (or a declaration of absence of such results).</p>&#xA;
habedi/stack-exchange-dataset
1,652
The operator $A(L)= \{w \mid ww \in L\}$
<p>Consider the operator $A(L)= \{w \mid ww \in L\}$. Apparently, the class of context free languages is not closed against $A$. Still, after a lot of thinking, I can't find any CFL for which $A(L)$ wouldn't be CFL. </p>&#xA;&#xA;<p>Does anyone have an idea for such a language?</p>&#xA;
formal languages context free closure properties
1
The operator $A(L)= \{w \mid ww \in L\}$ -- (formal languages context free closure properties) <p>Consider the operator $A(L)= \{w \mid ww \in L\}$. Apparently, the class of context free languages is not closed against $A$. Still, after a lot of thinking, I can't find any CFL for which $A(L)$ wouldn't be CFL. </p>&#xA;&#xA;<p>Does anyone have an idea for such a language?</p>&#xA;
habedi/stack-exchange-dataset
1,662
Why are lambda-abstractions the only terms that are values in the untyped lambda calculus?
<p>I am confused about the following claim: "The only values in the untyped lambda calculus are lambda-abstractions".</p>&#xA;&#xA;<p>Why are the other terms not values? What does it mean for a lambda-abstraction to be a value? The first thing that came to my mind was that maybe lambda-abstractions are the only possible normal forms, but this is not true of course, e.g. $(\lambda x.\; x)\;y \to y$.</p>&#xA;&#xA;<p>Can someone enlighten me?</p>&#xA;
logic lambda calculus
1
Why are lambda-abstractions the only terms that are values in the untyped lambda calculus? -- (logic lambda calculus) <p>I am confused about the following claim: "The only values in the untyped lambda calculus are lambda-abstractions".</p>&#xA;&#xA;<p>Why are the other terms not values? What does it mean for a lambda-abstraction to be a value? The first thing that came to my mind was that maybe lambda-abstractions are the only possible normal forms, but this is not true of course, e.g. $(\lambda x.\; x)\;y \to y$.</p>&#xA;&#xA;<p>Can someone enlighten me?</p>&#xA;
habedi/stack-exchange-dataset
1,665
Frame Pointers in Assembler
<p>I am currently learning assembly programming on wombat 4, I am looking at Frame pointers. I understand exactly what a frame pointer is: it is a register and are used to access parameters on a stack. But i'm confused on how they affect the program counter and why they are preferred over normal registers. </p>&#xA;&#xA;<p>Could some one explain, please. </p>&#xA;
computer architecture compilers
1
Frame Pointers in Assembler -- (computer architecture compilers) <p>I am currently learning assembly programming on wombat 4, I am looking at Frame pointers. I understand exactly what a frame pointer is: it is a register and are used to access parameters on a stack. But i'm confused on how they affect the program counter and why they are preferred over normal registers. </p>&#xA;&#xA;<p>Could some one explain, please. </p>&#xA;
habedi/stack-exchange-dataset
1,669
Connection between KMP prefix function and string matching automaton
<p>Let $A_P = (Q,\Sigma,\delta,0,\{m\})$ the <em>string matching automaton</em> for pattern $P \in \Sigma^m$, that is </p>&#xA;&#xA;<ul>&#xA;<li>$Q = \{0,1,\dots,m\}$</li>&#xA;<li>$\delta(q,a) = \sigma_P(P_{0,q}\cdot a)$ for all $q\in Q$ and $a\in \Sigma$</li>&#xA;</ul>&#xA;&#xA;<p>with $\sigma_P(w)$ the length of the longest prefix of $P$ that is a Suffix of $w$, that is</p>&#xA;&#xA;<p>$\qquad \displaystyle \sigma_P(w) = \max \left\{k \in \mathbb{N}_0 \mid P_{0,k} \sqsupset w \right\}$.</p>&#xA;&#xA;<p>Now, let $\pi$ the <em>prefix function</em> from the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm" rel="nofollow">Knuth-Morris-Pratt algorithm</a>, that is</p>&#xA;&#xA;<p>$\qquad \displaystyle \pi_P(q)= \max \{k \mid k &lt; q \wedge P_{0,k} \sqsupset P_{0,q}\}$.</p>&#xA;&#xA;<p>As it turns out, one can use $\pi_P$ to compute $\delta$ quickly; the central observation is:</p>&#xA;&#xA;<blockquote>&#xA; <p>Assume above notions and $a \in \Sigma$. For $q \in \{0,\dots,m\}$ with $q = m$ or $P_{q+1} \neq a$, it holds that</p>&#xA; &#xA; <p>$\qquad \displaystyle \delta(q,a) = \delta(\pi_P(q),a)$</p>&#xA;</blockquote>&#xA;&#xA;<p>But how can I prove this?</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>For reference, this is how you compute $\pi_P$:</p>&#xA;&#xA;<pre><code>m ← length[P ]&#xA;Ο€[0] ← 0&#xA;k ← 0&#xA;for q ← 1 to m βˆ’ 1 do&#xA; while k &gt; 0 and P [k + 1] =6 P [q] do&#xA; k ← Ο€[k]&#xA; if P [k + 1] = P [q] then&#xA; k ← k + 1&#xA; end if&#xA; Ο€[q] ← k&#xA; end while&#xA;end for&#xA;&#xA;return Ο€&#xA;</code></pre>&#xA;
algorithms finite automata strings searching
1
Connection between KMP prefix function and string matching automaton -- (algorithms finite automata strings searching) <p>Let $A_P = (Q,\Sigma,\delta,0,\{m\})$ the <em>string matching automaton</em> for pattern $P \in \Sigma^m$, that is </p>&#xA;&#xA;<ul>&#xA;<li>$Q = \{0,1,\dots,m\}$</li>&#xA;<li>$\delta(q,a) = \sigma_P(P_{0,q}\cdot a)$ for all $q\in Q$ and $a\in \Sigma$</li>&#xA;</ul>&#xA;&#xA;<p>with $\sigma_P(w)$ the length of the longest prefix of $P$ that is a Suffix of $w$, that is</p>&#xA;&#xA;<p>$\qquad \displaystyle \sigma_P(w) = \max \left\{k \in \mathbb{N}_0 \mid P_{0,k} \sqsupset w \right\}$.</p>&#xA;&#xA;<p>Now, let $\pi$ the <em>prefix function</em> from the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm" rel="nofollow">Knuth-Morris-Pratt algorithm</a>, that is</p>&#xA;&#xA;<p>$\qquad \displaystyle \pi_P(q)= \max \{k \mid k &lt; q \wedge P_{0,k} \sqsupset P_{0,q}\}$.</p>&#xA;&#xA;<p>As it turns out, one can use $\pi_P$ to compute $\delta$ quickly; the central observation is:</p>&#xA;&#xA;<blockquote>&#xA; <p>Assume above notions and $a \in \Sigma$. For $q \in \{0,\dots,m\}$ with $q = m$ or $P_{q+1} \neq a$, it holds that</p>&#xA; &#xA; <p>$\qquad \displaystyle \delta(q,a) = \delta(\pi_P(q),a)$</p>&#xA;</blockquote>&#xA;&#xA;<p>But how can I prove this?</p>&#xA;&#xA;<hr>&#xA;&#xA;<p>For reference, this is how you compute $\pi_P$:</p>&#xA;&#xA;<pre><code>m ← length[P ]&#xA;Ο€[0] ← 0&#xA;k ← 0&#xA;for q ← 1 to m βˆ’ 1 do&#xA; while k &gt; 0 and P [k + 1] =6 P [q] do&#xA; k ← Ο€[k]&#xA; if P [k + 1] = P [q] then&#xA; k ← k + 1&#xA; end if&#xA; Ο€[q] ← k&#xA; end while&#xA;end for&#xA;&#xA;return Ο€&#xA;</code></pre>&#xA;
habedi/stack-exchange-dataset
1,671
Connection between castability and convexity
<p>I am wondering if there are any connection between convex polygon and castable object? What can we say about castability of the object if we know that the object is convex polygon and vice versa.</p>&#xA;<p>Let's gather together few basic things that we have to know.</p>&#xA;<blockquote>&#xA;<p>The object is castable if it can removed from the mold.</p>&#xA;<p>The polyhedron P can be removed from its mold by a translation in direction <span class="math-container">$\vec{d}$</span> if and only if <span class="math-container">$\vec{d}$</span> makes an angle of at least <span class="math-container">$90^{\circ}$</span> with the outward normal of all ordinary facets of P.</p>&#xA;</blockquote>&#xA;<p>For a arbitrary object testing for castability has time complexity <span class="math-container">$O(n^2)$</span>. In my opinion, for a convex polygon if could be improved to linear time, because for every new top facet we should test that the vector <span class="math-container">$\vec{d}$</span> makes an angle at least <span class="math-container">$90^{\circ}$</span> with outward normal not of all but only of two adjacent ordinary facets of P.</p>&#xA;<p>If this is true at least we have improvement in testing for castability in case of convex polygon.</p>&#xA;<p>We else can we state about castability and convexity. Especially interesting to know, if castability tells us something about convexity.</p>&#xA;
complexity theory time complexity computational geometry
1
Connection between castability and convexity -- (complexity theory time complexity computational geometry) <p>I am wondering if there are any connection between convex polygon and castable object? What can we say about castability of the object if we know that the object is convex polygon and vice versa.</p>&#xA;<p>Let's gather together few basic things that we have to know.</p>&#xA;<blockquote>&#xA;<p>The object is castable if it can removed from the mold.</p>&#xA;<p>The polyhedron P can be removed from its mold by a translation in direction <span class="math-container">$\vec{d}$</span> if and only if <span class="math-container">$\vec{d}$</span> makes an angle of at least <span class="math-container">$90^{\circ}$</span> with the outward normal of all ordinary facets of P.</p>&#xA;</blockquote>&#xA;<p>For a arbitrary object testing for castability has time complexity <span class="math-container">$O(n^2)$</span>. In my opinion, for a convex polygon if could be improved to linear time, because for every new top facet we should test that the vector <span class="math-container">$\vec{d}$</span> makes an angle at least <span class="math-container">$90^{\circ}$</span> with outward normal not of all but only of two adjacent ordinary facets of P.</p>&#xA;<p>If this is true at least we have improvement in testing for castability in case of convex polygon.</p>&#xA;<p>We else can we state about castability and convexity. Especially interesting to know, if castability tells us something about convexity.</p>&#xA;
habedi/stack-exchange-dataset
1,672
Line separates two sets of points
<p>If there is a way to identify if two sets of points can be separated by a line?</p>&#xA;&#xA;<blockquote>&#xA; <p>We have two sets of points $A$ and $B$ if there is a line that separates $A$ and $B$ such that all points of $A$ and only $A$ on the one side of the line, and all points of $B$ and only $B$ on the other side.</p>&#xA;</blockquote>&#xA;&#xA;<p>The most naive algorithm I came up with is building convex polygon for $A$ and $B$ and test them for intersection. It looks time the time complexity for this should be $O(n\log h)$ as for constructing a convex polygon. Actually I am not expecting any improvements in time complexity, I am not sure it can be improved at all. But al least there should be a more beautiful way to determine if there is such a line.</p>&#xA;
algorithms machine learning computational geometry
1
Line separates two sets of points -- (algorithms machine learning computational geometry) <p>If there is a way to identify if two sets of points can be separated by a line?</p>&#xA;&#xA;<blockquote>&#xA; <p>We have two sets of points $A$ and $B$ if there is a line that separates $A$ and $B$ such that all points of $A$ and only $A$ on the one side of the line, and all points of $B$ and only $B$ on the other side.</p>&#xA;</blockquote>&#xA;&#xA;<p>The most naive algorithm I came up with is building convex polygon for $A$ and $B$ and test them for intersection. It looks time the time complexity for this should be $O(n\log h)$ as for constructing a convex polygon. Actually I am not expecting any improvements in time complexity, I am not sure it can be improved at all. But al least there should be a more beautiful way to determine if there is such a line.</p>&#xA;
habedi/stack-exchange-dataset
1,681
Big-Endian/Little-Endian argument - paper by Danny Cohen
<p>Reading a book I was redirected to <a href="http://www.ietf.org/rfc/ien/ien137.txt" rel="nofollow">"On holy wars and a plea for peace"</a> paper by Danny Cohen, which covers the "holy war" between big-endians and little-endians considering byte-order.</p>&#xA;&#xA;<p>Reaching the summary of the memory section I got confused as the author sais:</p>&#xA;&#xA;<blockquote>&#xA; <p>To the best of my knowledge only the Big-Endians of Blefuscu have&#xA; built systems with a consistent order which works across &#xA; chunk-boundaries, registers, instructions and memories. I<br>&#xA; failed to find a Little-Endians' system which is totally&#xA; consistent.</p>&#xA;</blockquote>&#xA;&#xA;<p>Which kind of contradicts his previous text sections covering little-endian:</p>&#xA;&#xA;<p>e.g.</p>&#xA;&#xA;<blockquote>&#xA; <p>When they add the bit order and the byte order they get:</p>&#xA;&#xA;<pre><code> ...|---word2---|---word1---|---word0---|&#xA; ....|C3,C2,C1,C0|C3,C2,C1,C0|C3,C2,C1,C0|&#xA; .....|B31......B0|B31......B0|B31......B0|&#xA;</code></pre>&#xA; &#xA; <p>In this regime, when word W(n) is shifted right, its LSB moves into&#xA; the MSB of word W(n-1).&#xA; 4</p>&#xA; &#xA; <p>English text strings are stored in the same order, with the&#xA; first character in C0 of W0, the next in C1 of W0, and so on.</p>&#xA; &#xA; <p>This order is very consistent with itself, with the Hebrew language,&#xA; and (more importantly) with mathematics, because significance&#xA; increases with increasing item numbers (address).</p>&#xA;</blockquote>&#xA;&#xA;<p>he even lateron sais:</p>&#xA;&#xA;<blockquote>&#xA; <p>The Big-Endians struck again, and without any resistance got their&#xA; way. The decimal number 12345678 is stored in the VAX memory in this&#xA; order:</p>&#xA;&#xA;<pre><code> 7 8 5 6 3 4 1 2&#xA; ...|-------long0-------|&#xA; ....|--word1--|--word0--|&#xA; .....|-C1-|-C0-|-C1-|-C0-|&#xA; ......|B15....B0|B15....B0|&#xA;</code></pre>&#xA; &#xA; <p>This ugliness cannot be hidden even by the standard Chinese trick.</p>&#xA;</blockquote>&#xA;&#xA;<p><strong>How did the author get to this completely different conclusion on overall consistency?</strong> </p>&#xA;&#xA;<p>An answer does not have to only base on the text, but may also include other sources which might clear up how the statement is sound.</p>&#xA;
terminology computer architecture
1
Big-Endian/Little-Endian argument - paper by Danny Cohen -- (terminology computer architecture) <p>Reading a book I was redirected to <a href="http://www.ietf.org/rfc/ien/ien137.txt" rel="nofollow">"On holy wars and a plea for peace"</a> paper by Danny Cohen, which covers the "holy war" between big-endians and little-endians considering byte-order.</p>&#xA;&#xA;<p>Reaching the summary of the memory section I got confused as the author sais:</p>&#xA;&#xA;<blockquote>&#xA; <p>To the best of my knowledge only the Big-Endians of Blefuscu have&#xA; built systems with a consistent order which works across &#xA; chunk-boundaries, registers, instructions and memories. I<br>&#xA; failed to find a Little-Endians' system which is totally&#xA; consistent.</p>&#xA;</blockquote>&#xA;&#xA;<p>Which kind of contradicts his previous text sections covering little-endian:</p>&#xA;&#xA;<p>e.g.</p>&#xA;&#xA;<blockquote>&#xA; <p>When they add the bit order and the byte order they get:</p>&#xA;&#xA;<pre><code> ...|---word2---|---word1---|---word0---|&#xA; ....|C3,C2,C1,C0|C3,C2,C1,C0|C3,C2,C1,C0|&#xA; .....|B31......B0|B31......B0|B31......B0|&#xA;</code></pre>&#xA; &#xA; <p>In this regime, when word W(n) is shifted right, its LSB moves into&#xA; the MSB of word W(n-1).&#xA; 4</p>&#xA; &#xA; <p>English text strings are stored in the same order, with the&#xA; first character in C0 of W0, the next in C1 of W0, and so on.</p>&#xA; &#xA; <p>This order is very consistent with itself, with the Hebrew language,&#xA; and (more importantly) with mathematics, because significance&#xA; increases with increasing item numbers (address).</p>&#xA;</blockquote>&#xA;&#xA;<p>he even lateron sais:</p>&#xA;&#xA;<blockquote>&#xA; <p>The Big-Endians struck again, and without any resistance got their&#xA; way. The decimal number 12345678 is stored in the VAX memory in this&#xA; order:</p>&#xA;&#xA;<pre><code> 7 8 5 6 3 4 1 2&#xA; ...|-------long0-------|&#xA; ....|--word1--|--word0--|&#xA; .....|-C1-|-C0-|-C1-|-C0-|&#xA; ......|B15....B0|B15....B0|&#xA;</code></pre>&#xA; &#xA; <p>This ugliness cannot be hidden even by the standard Chinese trick.</p>&#xA;</blockquote>&#xA;&#xA;<p><strong>How did the author get to this completely different conclusion on overall consistency?</strong> </p>&#xA;&#xA;<p>An answer does not have to only base on the text, but may also include other sources which might clear up how the statement is sound.</p>&#xA;
habedi/stack-exchange-dataset