instruction
stringlengths
0
29.8k
⌀
Consider following [task](https://acm.timus.ru/problem.aspx?space=26&num=1): > we have an input of N+1 lines, where first line contains N ≤ 150000 - number of items, and then we have N lines, each one contains one item, which is a tuple (number id, number m), id ≤ 10^7, m ≤ 100. We have to perform a stable sort o...
null
You are right that the clock speed is determined by the slowest stage. But on most architectures, it is not true that fetching (or any kind of memory access) takes one cycle. This is an illusion provided by the CPU to make things manageable. In practice, if your CPU tries to fetch, and the operation cannot be c...
null
The language of an NFA $A$, denoted $L(A)$, is the set of words $w$ such that there is an accepting run of $A$ on $w$. Hence, when we claim that an NFA $A$ recognizes a language $L$, we mean that $L(A) = L$, and by that we mean equality of sets, that is, we have two-sided containment: (1) $L(A)\subseteq L$: every w...
Let $G=(V,E)$ to be a graph and $u$ and $\nu$ to be its vertices such that $\{u,v\}\subseteq V$ and $(u,\nu)\in E$. Suppose that $u$ is discovered first. Consequently, its color is changed to gray. Then, $\nu$ becomes its descendant (by white path theorem) and the following discovery time relationship holds: $u.d<\...
null
Whenever you think you have solved the *two generals* problem, there is only one thing you need to do to find why your solution is wrong. Take every step s_1...s_n of your algorithm and treat it as the final step before a permanent network failure. Does a general end up dead if any step s_i is the final step befo...
null
Is finding arbitrary-but-fixed length cycles in a graph NP-Hard?
null
I'm giving a language $L=\{0^m 1^n 2^m \mid m,n ∈ N\}$. I designed this stack machine in order to accept $L$. Here, I'm skipping $1$s (no matter how many $1$s there are). Is it acceptable to skip the input this way?[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/ZpDk9.png
null
Why does quicksort have a big $O$ notation of $(n \log n)$. I would like some help understanding what exactly $(n \log n)$ is, and then how it applies to quicksort. Also in $(n \log n)$, what is the base for the $\log$?
null
I know that when I compile a program and then I inspect with objdump, I have addresses. These are **relative addresses**. But if it's a C program and I `printf` with `%p` a pointer, that is a **virtual/logical address**. Who generates this? Is that the loader? If yes, why do I need that a loader does this? **I...
null
I'm currently reading *The Algorithm Design Manual* by Steven&nbsp;S. Skiena as my first book to algorithms. Something in the asymptotic part is kind of confusing to me. > **Proving the Theta** > > The analysis above gives a quadratic-time upper bound on the running time of this simple pattern matching alg...
null
{"Voters":[{"Id":-1,"DisplayName":"Community"}]}
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
Is the knapsack problem for a target weight, let's say 1000 for example, and a target price, let's say 10000, still an NPC problem?
Knapsack Problem for Fixed weight and Fixed price
|algorithms|np-complete|
Probably not. If you have $n$ items, and a capacity of $W$, there is a pseudo-polynomial time algorithm using dynamic programming that runs in $O(Wn)$ time. Thus, for any constant weight, we can solve the Knapsack problem in linear time.
One thing I would like to add is that $O$, $\Omega$, $o$, $\omega$, and $\Theta$ are all about relating functions to one another. In particular for functions $f$ and $g$, $f(x)\in O(g(x))$ says that (in some sense) $g(x)$ is an upper bound for the function $f(x)$, and $f(x) \in\Omega(g(x))$ says that (in some sense) $g...
let's say that I have a Python script that performs various operations, including data manipulation, conditional logic, and iteration. However, I'm concerned about its time and space complexity efficiency. Would it be possible to use logic gates to optimize code by simplifying and reducing redundant logic using techniq...
Can a Code Script be Optimized for Time and Space Complexity Using Logic Gates
|time-complexity|reductions|runtime-analysis|logic|space-complexity|
null
null
L={(ab)^n : n is a natural number apart from 6}, I want to show L is non-regular by finding an infinite set of L-distinguishable words. Could you help me?
How to show L is non-regular without pumping lemma?
|formal-languages|regular-languages|automata|finite-automata|
Well, you can't show that it is not regular, because it is regular. Indeed, $L = (ab)^*\setminus \{(ab)^6\}$, and $(ab)^*$ is regular (concatenation + kleene star), and $\{(ab)^6\}$ is regular (because it is finite), and regular languages are closed under difference.
Here is one approach that ought to run fast on real hardware. Store the structure of your tree in an array $P$ so that the parent of node $i$ is found at $P[i]$. For example, with $$ P = [-1, 0, 0, 2, 3], $$ $P[3] = 2$ so the parent of node 3 is node 2. -1 is a dummy value for the parent-less root node. Store al...
null
null
$L=\{(ab)^n : n\text{ is a natural number apart from }6\}$, I want to show L is non-regular by finding an infinite set of L-distinguishable words. Could you help me?
null
## The problem Trying to improve my algorithms I bumped [into a problem][1] which I can summarise like this: > You are given a list of enemy bases you want to attack. Each base $i$ > requires a minimum number of soldiers $s_i$ to be conquered, will take out a > certain number $b_i$ of the soldiers who attack and ...
## The problem Trying to improve my algorithms I bumped [into a problem][1] which I can summarise like this: > You are given a list of enemy bases you want to attack. Each base $i$ > requires a minimum number of soldiers $s_i$ to be conquered, will take out a > certain number $b_i$ of the soldiers who attack and ...
## The problem Trying to improve my algorithms I bumped [into a problem][1] which I can summarise like this: > You are given a list of enemy bases you want to attack. Each base $i$ > requires a minimum number of soldiers $s_i$ to be conquered, will take out a > certain number $b_i$ of the soldiers who attack and ...
null
## The problem Trying to improve my algorithms I bumped [into a problem][1] by Pedro Pablo Gómez Martín and Marco Antonio Gómez Martín, which I can summarise like this: > You are given a list of enemy bases you want to conquer. You can only attack one base at a time. Each base $i$ > requires a minimum number of so...
null
## The problem Trying to improve my algorithms I bumped [into a problem][1] by Pedro Pablo Gómez Martín and Marco Antonio Gómez Martín, which I can summarise like this: > You are given a list of enemy bases you want to conquer. You can only attack one base at a time. Each base $i$ > requires a minimum number of so...
null
I have to create an NFA $\mathcal{A}$ that accepts the language $L = \{w \in \Sigma^* \ | \ |w|_a \ \text{is divisible by 2 or} \ |w|_b \ \text{is divisible by 3} \}$ So the NFA only accepts words with $|w|_a \ mod \ 2 = 0$ or $|w|_b \ mod \ 3 = 0$. [This is the NFA that I constructed][1] but it is not enough. W...
Create NFA where |w|_a is divisible by 2 or |w|_b is divisible by 3
|automata|finite-automata|
this is a homework question and after struggling with it for a while, I have decided to ask for help here. The task is to construct a language over the alphabet $\{0,1\}$ consisting of precisely those words $w$ with the property that $\#_0(w)$ is an odd number, i.e. the count of 0's in those words is odd (eg. $010,...
Express a language containing the words with an odd amount of 0's using the languages $\{0\}$ and $\{1\}$
|formal-languages|
This is a homework question and after struggling with it for a while, I have decided to ask for help here. The task is to construct a language over the alphabet $\{0,1\}$ consisting of precisely those words $w$ with the property that $\#_0(w)$ is an odd number, i.e. the count of 0's in those words is odd (eg. $010,...
Input: A finite set A, subsets S1, . . . , Sn ⊆ A, and a number k ∈ N. Question: Does there exist a set R ⊆ A with |R| = k such that |R ∩ Si| = |Si| for all 1 ≤ i ≤ n? I read somewhere (without mentioning why) that it's an NP-complete problem, but I think it can be solved simply by taking the union of all subsets and...
Decide whether this Problem NPC or P?
|np-complete|sets|
The following language is the language of even number of 0's: $$ \{1\}^*\cdot (\{0\}\cdot \{1\}^*\cdot\{0\}\cdot \{1\}^*)^*$$ I leave correctness to you. Then, you can complement by taking its difference from the set of all words: $$ (\{0\} \cup \{1\})^*\setminus (\{1\}^*\cdot (\{0\}\cdot \{1\}^*\cdot\{0\}\cdot \...
The following language is the language of even number of 0's: $$ \{1\}^*\cdot (\{0\}\cdot \{1\}^*\cdot\{0\}\cdot \{1\}^*)^*$$ I leave correctness to you. Then, you can complement by taking its difference from the set of all words: $$ (\{0\} \cup \{1\})^*\setminus (\{1\}^*\cdot (\{0\}\cdot \{1\}^*\cdot\{0\}\cdot \...
I'm assuming you mean $L \in P(\Sigma^*)$ instead of $L \in \Sigma^*$. Remember that by $\{x \in D | \varphi(x)\}$ we simply denote $\{x | x \in D \land \psi(x)\}$ and $\overline{\{x | \varphi(x)\}} = \{x | \neg \varphi(x)\}$. The mistake is in the second equivalence of your proof, you assert that $$L \in \overlin...
**Hint:** 1- The language $L$ can be written as the union of two simple regular languages. 2- $\epsilon$ is in the language. 3- When you design an automaton for all words $w$ with $\#_a(w) \mod 2 \equiv 0$, then you should allow for an arbitrary number of $b$'s to appear anywhere in the input $w$.
I'm assuming you mean $L \in P(\Sigma^*)$ instead of $L \in \Sigma^*$. Remember that by $\{x \in D | \varphi(x)\}$ we simply denote $\{x | x \in D \land \psi(x)\}$ and $\overline{\{x | \varphi(x)\}} = \{x | \neg \varphi(x)\}$. The mistake is in the second equivalence of your proof, you assert that $$L \in \overlin...
Right, it is in $\text{P}$. The condition $|R\cap S_i| = |S_i|$ is equivalent to $S_i\subseteq R$. So the problem is to find a subset $R$ whose size is $k$ such that $R$ contains all sets in $\{S_i\}_{i\in [n]}$. In other words, $ \bigcup\limits_{i\in [n]} S_i \subseteq R$. So yes, the problem is in $\text{PTIME}$ as y...
Right, it is in $\text{PTIME}$. The condition $|R\cap S_i| = |S_i|$ is equivalent to $S_i\subseteq R$. So the problem is to find a subset $R$ whose size is $k$ and contains all sets in $\{S_i\}_{i\in [n]}$. In other words, $ \bigcup\limits_{i\in [n]} S_i \subseteq R$. So you can simply find the smallest such set $\bigc...
What theoretical concept lies behind the strong restriction of acquire semantics - to reads, and release semantics - to writes? (With papers titles and authors, if possible.) Is it related to provision of correctness of more complex approaches than lock-based synchronization (as lock-free, wait-free algorithms)? ...
It looks like you have complemented the set $\{ L \subseteq \Sigma^*: \overline{L}\in \text{RE} \}$ incorrectly. Specifically, you assumed that: $$\overline{\{ L \subseteq \Sigma^*: \overline{L}\in \text{RE} \}} = \{ \overline{L}\subseteq \Sigma^*: L\in \text{RE}\}$$ but this is incorrect as you should complement t...
Note that a language $L$ is a subset of $\Sigma^*$ and not an element in $\Sigma^*$, and here we're considering classes of languages. So I assumed that you meant $L$ is a language over $\Sigma$. It looks like you have complemented the set $\{ L \subseteq \Sigma^*: \overline{L}\in \text{RE} \}$ incorrectly. Specific...
I've seen a definition of NP alluded to in different texts where at each choice an NDTM makes a nondeterministic choice between two transition functions and behaves accordingly. It seems like even in a binary alphabet the machine has more than two possible behaviors. Can anyone formalize this and help me understand...
Two transition functions def of NP
|complexity-theory|np|
I've seen a definition of NP alluded to in different texts where at each step an NDTM makes a nondeterministic choice between two transition functions and behaves accordingly. It seems like even in a binary alphabet the machine has more than two possible behaviors. Can anyone formalize this and help me understand w...
null
Let $T$ be a rooted, finitely branching tree, with values from $A$ in its nodes; $T(j)$ is the value of a node called $j$. $A$ is a commutative monoid. The "bottom-up scan tree" of $T$ is a rooted tree $T^\ast$ isomorphic to $T$, such that if $j$ is a leaf of $T$, $T(j)=T^\ast(j)$, and otherwise $T^\ast(j) = \sum_{i\le...
## The problem Trying to improve my algorithms I bumped [into a problem][1] by Pedro Pablo Gómez Martín and Marco Antonio Gómez Martín, which I can summarise like this: > You are given a list of enemy bases you want to conquer. You can only attack one base at a time. Each base $i$ > requires a minimum number of so...
You can choose from among four options by first making one binary choice, then making a second binary choice; there are $2\times 2=4$ total possible outcomes, each of which can be mapped to one of those four options. Similarly, you can choose among any finite set using only binary choices. That's why the two are equi...
Okay! In order to (hopefully) prove that your proposed greedy algorithm is correct, we will make an argument that is very common when dealing with greedy algorithms (as you can see from @D.W. 's linked question). So, suppose you have found an $x$ such that there exists at least one sequence of battles where the army...
I did not find the proof claimed by Garey and Johnson at [SP16]. But I found two other proofs, which seem independent (do not rely on the existing proof): * [Yu, Hoogeveen and Lenstra (2004)][1] * [Caracciolo, Fichera, and Sportiello (2006)][1] [1]: https://doi.org/10.1023/B:JOSH.0000036858.59787.c2
In a fully connected Neural Network, each perceptron has it's bias term $b$ which is learnt. Often (example, in Linear/ Logistic Regression), when we don't want to treat this bias term explicitly, we add an extra "constant" feature $x_0 = 1$ to each training example. Can we show whether this will/ will not work in a Ne...
Representational power of Neural Neural Networks without a bias term
|machine-learning|neural-networks|learning-theory|perceptron|
null
In a fully connected Neural Network, each perceptron has it's bias term $b$ which is learnt. Often (example, in Linear/ Logistic Regression), when we don't want to treat this bias term explicitly, we add an extra "constant" feature $x_0 = 1$ to each training example. Can we show whether this will/ will not work in a Ne...
I was the book "Introduction to Computation and Programming Using Python" and I stumbled upon the concept of representation invariant. What I understood is that the variables (and maybe methods) created inside a class shouldn't be able to be accessed by code outside of the class. Is this definition right? Or I'm comple...
What is Representation Invariant?
|computer-architecture|
Note that the context-free languages are closed under [left-quotient](https://en.wikipedia.org/wiki/Quotient_of_a_formal_language) as well as intersection with regular languages, as John L. noted. Assume, for contradiction, that $L$ was context-free. Then $$L_1 := L \cap a^*ba^* = \{a^iba^{i^2 + 1} : i \geq 0\}$$ ...
Note that the context-free languages are closed under [left-quotient](https://en.wikipedia.org/wiki/Quotient_of_a_formal_language) as well as intersection with regular languages, as John L. noted. Assume, for contradiction, that $L$ was context-free. Then $$L_1 := L \cap a^*ba^* = \{a^iba^{i^2 + 1} : i \geq 0\}$$ ...
Note that the context-free languages are closed under [left-quotient](https://en.wikipedia.org/wiki/Quotient_of_a_formal_language) as well as intersection with regular languages, as John L. noted. Assume, for contradiction, that $L$ was context-free. Then $$L_1 := L \cap a^*ba^* = \{a^iba^{i^2 + 1} : i \geq 0\}$$ ...
I have read a Luby’s paper and understand basic idea of the LT codes, but I want to figure out the analysis when encoding symbols can choose their neighbors with replacement during the encoding process. I have tried some key points like, Repetitive, with replacement... on IEEE.I can not find related paper. Do you...
LT Codes encoding with replacement
|coding-theory|
How functional programming using lambda calculus is analogous to construction of Turing machine as per computational aspects?
Lambda Calculus vs Turing Machine
|automata|lambda-calculus|computation-models|
The short answer is that every computation describable in lambda calculus can be computed on a turing machine, at the same time every Turing machine program can be converted into a lambda calculus. The long answer would include proofs that both of those statements are true but that's a bit out of scope for this site...
It is a classical result that ALOGSPACE=P. You can find a proof in [lecture notes of Madhu Sudan](http://courses.csail.mit.edu/6.841/spring09/scribe/lect08.pdf). Both the circuit value problem and the monotone circuit value problem are P-complete, and in particular in P, and so can be solved in alternating logarithmic ...
null
null
How much money do you have? There is at the moment no technology that could create configurable hardware that is faster than a general purpose CPU. (Improving configurable hardware would improve the general purpose CpU as well). Apple has improved existing CPUs, if say that cost them maybe ten billion dollars. ...