instruction stringlengths 0 29.8k ⌀ |
|---|
|context-free|formal-grammars|regular-expressions| |
null |
At the heart of your regex is an alternation {$|$), which means that the regex matches $X$ or $Y$. That's how you should write the CFG:
$$\begin{align}S\to&\;\varepsilon\\
|&\;A
\end{align}$$
It's easy to see what $A$ is: it starts with an $a$ and can be extended arbitrarily with $, a$:
$$\begin{align}S\to&\;\vare... |
I'm trying to figure out a more efficient solution to the following problem.
**Dataset:** A set of arrays of key-value pairs `(K, V)`. The arrays have varying lengths, and the keys are non-zero 16-bit unsigned integers.
Examples:
`[(3, 100)]`
`[(1, 200), (1, 100), (2, 300)]`
`[(2, 200), (2, 300)]`
**I... |
I have the following hash table with hashcodes being quadratic numbers.
[![Table][1]][1]
Why do 0, 16, and 64 have different number of collisions when they map to the same number (line %16). Also how is it possible for 64 to have 6 collisions?
[1]: https://i.stack.imgur.com/rMtJS.png |
Collisions in hash table - Is this table wrong? |
|hash-tables| |
Here collisions means the number of (occupied) positions visited before finding a free spot and placing the number.
64 goes to 0(occupied by 0) - 1(by 1) - 2(by 16) - 3(by 49) - 4(by 4) - 5(by 36) - 6(bingo)
The table is consistent with linear hashing and stepsize $1$. |
null |
I am trying to address the following claim- "running prim algorithm on a disconnected undirected graph returns minimum spanning forest".
I thing that the claim may be false (i.e there might be an example of a disconnected undirected graph so that the prim algorithm doesn't return MSF) but I cannot think of such exampl... |
Why Prim algorithm may fail to return minimum spanning forest on disconnected undirected graph |
|weighted-graphs|minimum-spanning-tree|prims-algorithm| |
It depends on how *you/we* understand/define what is Prim's algorithm when the given graph is disconnected. You did not missing anything important.
"The most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs.", said by [Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm#De... |
It depends on how *you/we* understand/define what is Prim's algorithm when the given graph is disconnected. You did not missing anything important.
"The most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs.", said by [Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm#De... |
Given an undirected graph $G=(V,E)$, and vertex $v\in V$ and a number $k\in \mathbb{N}$, find an algorithm to find whether there exists a spanning tree of $G$ in which $v$ satisfies $d(v)=k$
I've narrowed the solution to 3 situations, in $G$: $d(v)<k , \\d(v)=k\\d(v)>k$
When $d(v)<k$, it is clear that there canno... |
Finding existence(or non existence) of spanning tree with a specific degree on a specific vertex |
|graphs|spanning-trees| |
I am trying to address the following claim- "running prim algorithm on a disconnected undirected graph returns minimum spanning forest".
I thing that the claim may be false (i.e there might be an example of a disconnected undirected graph so that the prim algorithm doesn't return MSF) but I cannot think of such exampl... |
It depends on how *you/we* understand/define what is Prim's algorithm when the given graph is disconnected. You did not missing anything important.
"The most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs.", said by [Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm#De... |
I need to prove that
> $coNP \neq NTIME(n^2) using time hierarchy theorem$
as we know $DTIME(n^4)\subseteq P\subseteq coNP$
from time hierarchy theorem we can derive that $DTIME(n^4) \not \subseteq DTIME(n^2)$
therefore $DTIME(n^2) \neq coNP$
Also
as we know $NTIME(n^4)\subseteq NP$
from time h... |
Prove that $coNP \neq NTIME(n^2)$ |
|complexity-theory|time-complexity| |
I need to prove that
> $coNP \neq NTIME(n^2)$ using time hierarchy theorem.
as we know $DTIME(n^4)\subseteq P\subseteq coNP$
from time hierarchy theorem we can derive that $DTIME(n^4) \not \subseteq DTIME(n^2)$
therefore $DTIME(n^2) \neq coNP$
Also
as we know $NTIME(n^4)\subseteq NP$
from time ... |
Given an undirected graph $G=(V,E)$, and vertex $v\in V$ and a number $k\in \mathbb{N}$, find an algorithm to find whether there exists a spanning tree of $G$ in which $v$ satisfies $d(v)=k$
I've narrowed the solution to 3 situations, in $G$: $d(v)<k , \\d(v)=k\\d(v)>k$
When $d(v)<k$, it is clear that there canno... |
You should use the fact that $\textsf{NTIME}(n^2)\subsetneq \textsf{NP}$. |
You should use the fact that $\textsf{NTIME}(n^2)\subsetneq \textsf{NP}$.
If $\text{co}\mathsf{NP} = \textsf{NTIME}(n^2)$, then $\text{co}\mathsf{NP} \subsetneq \mathsf{NP}$ and you can reach a contradiction. |
>Prove $PSPACE$-completeness of the language $READALLEXACT$ = $\{$$(M, x, 1^ s , t)$ | $A$ deterministic Turing machine $M$ on input $x$ reads all bits of the input in exactly $t$ steps and using no more than $s$ memory cells (consider that a bit is read if the machine head has ever been over it; after reading the inpu... |
Is this language PSPACE complete |
|complexity-theory|boolean-algebra| |
If you want to develop an operating system, you have responsibility for things that most developers don't care about. For example, how to make virtual memory work. How to switch from process A to process B without B being able to access any information from process A, and so on. And everything you do must be 100% relia... |
Simples. Use a hash table. Fill it with a[n-1], a[n-2] ... a[0] in that order. When you add a number to a hash table you will know if it was there already or not. What you want is the last number you added that wasn't in the hash table before you added it.
(It is obvious that you need to examine all array elements,... |
{"Voters":[{"Id":150711,"DisplayName":"Latif Salum"}]} |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true iff $\phi_k$ is satisfiable, in which $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [... |
A sufficient condition for satisfiability |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true iff $\phi_k$ is satisfiable, where $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true if $\phi_k$ is satisfiable, where $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2 ... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Also, if $C_k$ is true, then $\phi_k$ is satisfiable, where $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \o... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Also, if $C_k$ is true, then $\phi_k$ is satisfiable, where $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \o... |
A sufficient condition for unsatisfiability |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Hence, if $C_k$ is true, then $\phi_k$ is satisfiable, where $\phi_k = [x_1 \Rightarrow (\overline{x}_2 \wedge \... |
At the heart of your regex is an alternation {$\alpha|\beta$), which means that the regex matches $\alpha$ or $\beta$. That's how you should write the CFG:
$$\begin{align}S\to&\;\alpha\\
|&\;\beta
\end{align}$$
Here, $\alpha$ is $\varepsilon$ and $\beta$ is the subexpression $a(,a)^*$, for which we'll define the no... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Hence, if $C_k$ is true, then $[x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2 \Rightarrow ... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Hence, if $C_k$ is true, then $[x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2 \Rightarrow ... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Hence, if $C_k$ is true, then $[x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2 \Rightarrow ... |
Let $\varphi = \bigwedge C_k$, in which $C_k = (x_1 \odot x_2 \odot x_3)$, a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). Then, $C_k$ is true iff exactly one of $\{x_1, x_2, x_3\}$ is true. Hence, if $C_k$ is true, then $[x_1 \Rightarrow (\overline{x}_2 \wedge \overline{x}_3)] \wedge [x_2 \Rightarrow ... |
First, verify that $G$ is indeed connected, otherwise say no.
Second, if $G - v$ (the graph after deleting $v$) has more than $k$ components, we can say no.
Pick any $k$ neighbors of $v$ with the restriction that you pick at least one from each component of $G-v$. These are in the spanning tree. Now, let $G'$ be ... |
null |
No. It is not significant. $\varphi'$ is a much weaker condition. $\varphi'$ allows each clause to have either 0 or 1 satisfied literals. It's much easier to satisfy that restriction. I don't expect that this will be useful in practice, and it has no value for proving new theoretical results that I can see.
If ... |
I'm currently stuck showing $NP$-hardness of a problem of mine.
An instance of my problem (I call it (simple) pairwise $2$-Partitioning) is given by the following:
> Given a set of tupels $B=\{(b_1,1),\ldots,(b_n,1)\}$, with $b_i\in\mathbb{N}_{>0}$.\
Goal: A partition of $B$ into two subsets $S_1, S_2$ such that ... |
Reduction from $2$-Partitioning to (simple) pairwise $2$-Partitioning |
|reductions|np-hard|partitions|polynomial-time-reductions| |
I think you took the problem the wrong way, but your idea is good.
Let $A = \{a_1, …, a_n\}$ be an instance of $2$-$\texttt{Partition}$. Let $B = \{(a_1 + 1, 1), …, (a_n+1, 1)\}$. Then $A$ is a positive instance of $2$-$\texttt{Partition}$ if and only if $B$ is a positive instance of $\texttt{Pairwise}$ $2$-$\texttt... |
null |
Convert regex for comma separated value to CFG grammar |
Is there a 2SAT instance of variables $(a,b,c,d,e,f,g)$ that has exactly the solution set $S=\{ (1,0,0,0,0,0,0),(0,1,0,0,0,0,0),(0,0,1,0,0,0,0),(1,1,0,1,0,0,0),(1,0,1,0,1,0,0),(0,1,1,0,0,1,0),(1,1,1,1,1,1,1) \}$? It sounds plausible, but other than enumeration, I can't seem to find a way to prove/disprove that it exist... |
Finding a 2SAT instance that has a specific solution set |
|2-sat| |
Let $\varphi = \bigwedge C_k$, in which $C_k$ is a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). That is, $C_k = (l_i \odot l_j \odot l_u)$ such that $l_i \in \{x_i, \overline{x}_i\}$ for any $i$. Then, $C_k$ is true iff exactly one of $\{l_i, l_j, l_u\}$ is true. Hence, if $C_k$ is true, then $[l_i \R... |
Let $\varphi = \bigwedge C_k$, in which $C_k$ is a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). That is, $C_k = (l_i \odot l_j \odot l_u)$ such that $l_i \in \{x_i, \overline{x}_i\}$ for any $i$. Then, $C_k$ is true iff exactly one of $\{l_i, l_j, l_u\}$ is true. Hence, if $C_k$ is true, then $[l_i \R... |
Let $\varphi = \bigwedge C_k$, in which $C_k$ is a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). That is, $C_k = (l_i \odot l_j \odot l_u)$ such that $l_i \in \{x_i, \overline{x}_i\}$ for any $i$. Then, $C_k$ is true iff exactly one of $\{l_i, l_j, l_u\}$ is true. Hence, if $C_k$ is true, then $[l_i \R... |
Let $\varphi = \bigwedge C_k$, in which $C_k$ is a clause in *X3SAT* (exactly-one *3SAT* or one-in-three *3SAT*). That is, $C_k = (l_i \odot l_j \odot l_u)$ such that $l_i \in \{x_i, \overline{x}_i\}$ for any $i$. Then, $C_k$ is true iff exactly one of $\{l_i, l_j, l_u\}$ is true. Hence, if $C_k$ is true, then $[l_i \R... |
null |
null |
First, verify that $G$ is indeed connected, otherwise say no.
Second, if $G - v$ (the graph after deleting $v$) has more than $k$ components, we can say no.
Pick any $k$ neighbors of $v$ with the restriction that you pick at least one from each component of $G-v$ and mark them. The edges from $v$ to these marked... |
Let $\varphi$ a 2CNF with $S$ as solution set.
- Since $(1,1,1,1,1,1,1)$ satisfies $\varphi$, each clause must contain a positive litteral.
- Since $(1,0,0,0,0,0,0)$ satisfies $\varphi$, each clause must contain either a negative litteral $\neq a$ or $a$.
- Since $(0,1,0,0,0,0,0)$ satisfies $\varphi$, each cla... |
Let $\varphi$ a 2CNF with $S$ as solution set.
- Since $(1,1,1,1,1,1,1)$ satisfies $\varphi$, each clause must contain a positive litteral.
- Since $(1,0,0,0,0,0,0)$ satisfies $\varphi$, each clause must contain either a negative litteral $\neq a$ or $a$.
- Since $(0,1,0,0,0,0,0)$ satisfies $\varphi$, each cla... |
[Federal Information Processing Standard 186-4 appendix C.4][1] gives (without reference) an algorithm intended to test if a positive integer $C$ (which can be thousands bits) is a square:
1. Set $n$, such that $2^n>C\ge2^{(n-1)}$.
2. $m=\lceil n/2\rceil$.
3. $i=0$.
4. Select $X_0$, such that $2^m>X_0\ge2^{(m-1)}$.... |
Correctness of FIPS 186-4 square test algorithm |
|algorithms|correctness-proof|integers| |
This is more or less [Newton's method](https://en.wikipedia.org/wiki/Newton%27s_method) applied to the function $f:x\to x^2 - C$. The algorithm finds $r = \left\lfloor \sqrt{C}\right\rfloor$ and check whether $r^2 = C$ or not.
If we define $g(x) = x - \frac{f(x)}{f'(x)} = x - \frac{x^2-C}{2x} = \frac{x^2+C}{2x}$, th... |
This is more or less [Newton's method](https://en.wikipedia.org/wiki/Newton%27s_method) applied to the function $f:x\to x^2 - C$. The algorithm finds $r = \left\lfloor \sqrt{C}\right\rfloor$ and check whether $r^2 = C$ or not.
If we define $g(x) = x - \frac{f(x)}{f'(x)} = x - \frac{x^2-C}{2x} = \frac{x^2+C}{2x}$, th... |
I need to describe (even in words) an algorithm that gets a connected, undirected, weighted graph so that the weight of each edge is either 1,2 or 3; and returns MST of that graph is time complexity O(|V|+|E|).
I thought to take kruskal algorithm and change the sorting algorithm to be counting sort (O(|E|) instead o... |
Find MST with bounded edge weight in O(|V|+|E|) |
|algorithms|graphs|data-structures|minimum-spanning-tree|prims-algorithm| |
You should use Prim's algorithm instead of Kruskal's algorithm.
Given a weighted undirected graph $G = (V, E, f)$ with $f(E) \subseteq \{1, 2, 3\}$ as an adjacency lists array, the following should work:
- Let $W$ be a boolean array of length $n = |V|$, with all values set to false, except $W[0]$ set to true.
- ... |
According to the theorem, if $L \in NP$, then $L$ can be determined by a deterministic Turing machine in exponential time.
So, are all languages determined in exponential time NP languages? |
Are all languages determined in exponential time NP languages? |
|complexity-theory|time-complexity|turing-machines|np| |
This is a space-time diagram so, going from top to bottom, the time elapsed is increasing. <br> Here, A and B are two nodes that are broadcasting messages to the other nodes present with it on the same channel.<br> At t<sub>A</sub>, A senses that the channel is idle and then starts transmitting its message as shown in ... |
null |
When i iterate $v$ and $x$ factorizations to see if a word is still in a language $L$, do i have to assume that $|v| = |x|$ always or could happen theirs lengths are different?.
I'm asking because i found a grammar for this language:
$L$ = { $a^nb^m, |n-m|$ is even } , so it should be context-free.
But if i try... |
$|v|$ and $|x|$ factorizations (in Pumping lemma for context-free) have the same length? |
|context-free|pumping-lemma| |
When i iterate $v$ and $x$ factorizations to see if a word is still in a language $L$, do i have to assume that $|v| = |x|$ always or could happen theirs lengths are different?.
I'm asking because i found a grammar for this language:
$L$ = { $a^nb^m, |n-m|$ is even } , so it should be context-free.
But if i try... |
Note: the language is even regular.
The pumping says that **THERE EXISTS** a decomposition $s = uvwxy$ verifying the three conditions. It does not mean that such a decomposition is unique, nor that any decomposition works.
In your example, a decomposition $v = a$ and $x = b$ works, but so does $v = \varepsilon$ a... |
You don't become an OS developer in a few days, but in years. And most probably you will never become an OS developer for the highly complex x86 architecture at all. This takes whole teams of specialists. Nowadays the major OSes for this platform (Linux & Windows) are there and there's no need for others.
This said,... |
[This paper][1] provides conditions for uniqueness.
[1]: https://arxiv.org/pdf/2106.12977.pdf |
null |
null |
Let me teach you a systematic way to answer this type of question.
First, write a program to enumerate over all possible clauses, test for each whether it is satisfied by every assignment in $S$, and keep the ones that are satisfied. There are only $O(n^2)$ possible clauses, where $n$ is the number of variables, so... |
|satisfiability|counting|2-sat| |
null |
Suppose that you had two trees.
Our goal is to convert the two trees into two integers such that two trees are the same if and only if the two integers are the same.
Suppose that we have a function named `leaf_hash()` which converts the leaves of the trees into integers such that for any two leaves `x1` an... |
How might we hash two trees? |
|trees|hashing| |
null |
null |
Consider the notion of optimal implementation as follows. Suppose we have some algorithm $A$ whose execution for some problem of size $N$ requires $T(N)$ operations (e.g. arithmetic operations). A library optimally implements this algorithm, when, it executes the algorithm for a problem of size $N$ on a CPU (or some ot... |
Are there any implementations of algorithms on hardware that are (nearly) optimal? |
|algorithms|complexity-theory| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.