instruction stringlengths 0 29.8k ⌀ |
|---|
|logic|reasoning|natural-deduction| |
null |
null |
$$
\max \prod_{i}p_i\iff \max \sum_{i}\log p_i,\,p_i>0
$$
So it's nearly equal to ask ["single source longest path"](https://en.wikipedia.org/wiki/Longest_path_problem), which is NP-hard in most graphs. There is a Polynomial solution on DAG. [algorithm](https://www.geeksforgeeks.org/find-longest-path-directed-acyc... |
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
1.0, -1.0);
else
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio,
-100.0, 100.0, 1.0, -1.0);
The book just throws in my face those formulas without any explicit mat... |
What's the mathematics behind the technique of "keeping a square a square" in chapter 2 of "OpenGL superbible" 4th Edition? |
|computer-graphics| |
I have a doubt on my solution of the following:
Formalize the language of a Turing machine that takes a Turing machine "M" and a character "a", the language recognizes all and only the Turing machines that write "a" on the tape for every possible input w prove that this language is undecidable.
Formalization:
A={<... |
Turing Machine writes "a" for every input w is undecidable |
|turing-machines|undecidability| |
I have a doubt on my solution of the following:
Formalize the language of a Turing machine that takes a Turing machine "M" and a character "a", the language recognizes all and only the Turing machines that write "a" on the tape for every possible input w prove that this language is undecidable.
Formalization:
A={<... |
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
1.0, -1.0);
else
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio,
-100.0, 100.0, 1.0, -1.0);
The book just throws in my face those formulas without any explicit mat... |
To show that any formal language is NP Complete first it must be showed that this formal language is both in NP and NP Hard.
So to show that Horn Satisfiability is NP Complete first it must be showed that Horn Satisfiability is both in NP and NP Hard.
Horn Satisfiability is definitely in NP because Horn Satisfiab... |
Horn Satisfiability is NP Complete, isn't it? |
|complexity-theory|np-complete|logic|propositional-logic|polynomial-time-reductions| |
I have a doubt on my solution of the following:
Formalize the language of a Turing machine that takes a Turing machine "M" and a character "a" as input, the language recognizes all and only the Turing machines that write "a" on the tape for every possible input w prove that this language is undecidable.
Formalizati... |
Are all np-complete problems also np-hard?
In other words, is np-complete a subset of np-hard?
I don't think it is entirely clear from the illsutration below, so I just wanted to quickly ask to ask to be completely sure. The np-hard area also includes the np-complete section right?
[ that on almost all permutations, the computational comple... |
This algorithm solves the [Two-Sum problem](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/)$^1$ assuming that the input array/list is sorted.
```python
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
N = len(nums)
l, r = 0, N-1
while l < ... |
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity()
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
1.0, -1.0);
else
glOrtho (-100.0 * aspectRatio, 100.0... |
Suppose we have a dataframe with ~10M rows with ~9M duplicate records. What is the most time efficient way of selecting the unique records from this dataframe?
Some sort of sampling algorithm? |
Sampling unique records from a large dataframe |
|algorithms|time-complexity|sorting|hash| |
It's not clear what "can be solved" actually means here. Let me explain with a real example.
It is known that NP-hard problems can be solved on an analog computer in polynomial time.
Suppose that you have a SAT problem in CNF with $m$ clauses and $n$ variables.
Define $c_{i,v}$ to equal $1$ if variable $v$ app... |
null |
I'm reading the DFS section of CLRS-*Introduction to Algorithms*, and confuse on the $\Leftarrow$ direction of the proof of the white-path theorem of DFS algorithm in this book. \
Note that each node u in the graph has 2 **timestamps**: $u.d$ records when u is discovered and $u.f$ records when the search finishes exami... |
Confuse on proof of theorem 22.9 (White-path theorem) Depth-First search (DFS) on Cormen-Leiserson-Rivest-Stein "Introduction to algorithms" book |
|algorithms|graphs|depth-first-search| |
I'm not sure what the problem is, but I will still try to answer.
The predecessor of $v$ in a path from $u$ to $v$ is the last vertex seen before $v$.
Since there exists a path from $u$ to $v$ then, unless $v = u$, $v$ has necessarily a predecessor.
More formally, if $(u_0, u_1, …, u_k)$ is a path of length $k... |
I'm reading the DFS section of CLRS-*Introduction to Algorithms*, and confuse on the $\Leftarrow$ direction of the proof of the white-path theorem of DFS algorithm in this book. \
Note that each node u in the graph has 2 **timestamps**: $u.d$ records when u is discovered and $u.f$ records when the search finishes exami... |
I believe that no faster algorithm is known, at least if you are interested in computing both tableaux. Dan Romik shows in his paper [The Number of Steps in the Robinson-Schensted Algorithm](https://www.math.ucdavis.edu/~romik/data/uploads/papers/schensted.pdf) that on almost all permutations, the computational complex... |
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity()
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
1.0, -1.0);
else
glOrtho (-100.0 * aspectRatio, 100.0... |
null |
Your suspicion is well-founded. The point 4 is invalid.
Imagine the exact moment N "writes 'a' on the tape and reject" in the point 4. That means at that moment, it is known that M loops. However, all the algorithm has done is running M on w for some steps without acceptance nor rejection. It is possible that if we ... |
null |
I was reading [this paper][1], and the author (in private correspondence, though I'm sure it's also in the paper) explains that a bit string generated through Solomonoff induction will have growing (and unbounded) Kolmogorov complexity.
This sounds counterintuitive to me: Solomonoff induction tends to favor bit stri... |
Solomonoff induction generates sequences of unbounded Kolmogorov complexity? |
|turing-machines|kolmogorov-complexity| |
A reasonable approach would be to build a hashtable that stores all unique records. Scan through the records one at a time, adding each to the hashtable if it is not already present; if it already is in the hashtable, do nothing, and if it is not already in the hashtable, add it to the hashtable and output it.
Anot... |
null |
I need to calculate the LR(1) items of the following grammar:
S -> E
E -> E + T
E -> T
T -> ID
T -> ( E )
I can not even calculate the first group {[S -> .E, $]} correctly,
I read and tried to run the algorithm and did not understand why the correct answer for state 0 should be the group ... |
find LR(1) items of the first state |
|automata|formal-grammars|compilers|syntax|lr-k| |
This problem is known as the MaxMin Diversity Problem (MMDP). [It is known to be NP-hard][1]. However, there are algorithms for giving good approximate solutions in reasonable time, such as [this one][2].
I'm answering this question years after it was asked because I was looking for algorithms to solve the same prob... |
As you mentioned the first problem can be reduced to the second one by replacing each positive integer $a_i\in S$ by a paired $(a_i,0)$. Moreover, the second problem can be reduced to the first one by replacing each paired $(a_i,b_i)\in S$ by a pisitive integer $c_i=|a_i-b_i|$ and after partitioning (suppose that $a_i\... |
The language $L=\{ (u\#,v\#) \mid |u|=|2v|\}$ from your question is actually a two-dimensional language, that is a relation between two strings, each written on their own input tape. In that way the condition $|u|=|2v|$ is easy to check, even with a deterministic one-way (two-tape) automaton: when the head moves one c... |
$S\to.E,\$$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,\$$..........$(2)$ and $E\to.T,\$$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and first of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,+$...... |
I have exercise:
We have a given finite deterministic automata. It has 5 states and is
based on the alphabet {a, b, c}. It can create n different words (we assume that n <
inf). What maximum value can n be?
W have 5 states so it should be something like this:
$\varepsilon \ | \ (a|b|c) \ | \ (a|b|c)(a|b|c)... |
Maximum number of words in deterministic finite automata with k-states |
null |
I have an exercise:
We are given a finite deterministic automata. It has 5 states and is
based on the alphabet $\{a, b, c\}$. It can accept $n$ different words (we assume that $n <\infty$). What maximum value can $n$ be?
W have 5 states so it should be something like this:
$\varepsilon \ | \ (a|b|c) \ | \ (... |
Maximum number of words accepts by a deterministic finite automata with 5-states |
$S\to.E,\$$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,\$$..........$(2)$ and $E\to.T,\$$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and first of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,+$...... |
$S\to.E$,\$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,\$$..........$(2)$ and $E\to.T,\$$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and first of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,+$...... |
I have an exercise:
We are given a finite deterministic automaton. It has 5 states and is
based on the alphabet $\{a, b, c\}$. It can accept $n$ different words, $n <\infty$. What maximum value can $n$ be?
W have 5 states so it should be something like this:
$\varepsilon \ | \ (a|b|c) \ | \ (a|b|c)(a|b|c) \... |
Maximum number of words accepted by a deterministic finite automaton with 5-states |
$S\to.E$,\$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,$\$..........$(2)$ and $E\to.T,$\$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and first of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,$\$..... |
Unfortunately, the worst case of this algorithm is $\Theta(n\lg n)$, which is worse than $O(n)$, the time-complexity of the [usual two-pointer algorithm](https://pastebin.com/NqqZ7eUU) that solves the same problem.
------
Consider the case with `nums = list(range(n))` and `target = 3*n//2`, where `n` is an even ... |
null |
{"Voters":[{"Id":755,"DisplayName":"D.W."}]} |
I'm having trouble figuring out *why* using XOR for this problem works; I've done it a couple of times by-hand, and can't really seem to understand it. I know that XOR is commutative and associative, which is why it's good for finding (missing) duplicated numbers in a list. But applying that to the following problem do... |
What property of XOR makes this algorithm work? |
|algorithms|bit-manipulation|xor| |
null |
$S\to.E$,\$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,$\$..........$(2)$ and $E\to.T,$\$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and $FIRST$ of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,$\$... |
$S\to.E$,\$.........$(1)$, now compute closure of $E$ which is $E\to.E+T,$\$..........$(2)$ and $E\to.T,$\$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and $FIRST$ of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find closure of $E$ which is $E\to.E+T,+$.... |
null |
Let $x$ and $y$ be the numbers that appear only once and let $z_1, \dots,z_n$ be the other input numbers (each number appears twice).
Then $x \oplus y \oplus z_1 \oplus \dots \oplus z_n = x \oplus y$ and, in particular, if the generic $i$-th bit in $x \oplus y$ is $1$ then exactly one between $x$ and $y$ has the $i$-t... |
$S\to.E$,\$.........$(1)$, now compute the closure of $E$, which is $E\to.E+T,$\$..........$(2)$ and $E\to.T,$\$.........$(3)$ use lookahead $\$$ because in $(1)$ after $E$ is $\$$ and $FIRST$ of $\$$ is $\$$ that's why lookahead is $\$$ in (2) and (3).
From $(2)$ you need to find the closure of $E$, which is $E\... |
I'll throw a naive algorithm out there.
One way would be to create a hash set of all possible substrings from your first input. Then check if each possible substring from the second input is in that hash set.
Time complexity: $O(N_1^2 + N_2^2)$
Memory usage: $O(min(N_1^2, N_2^2))$ (use shortest input as first ... |
I'll throw a naive algorithm out there.
One way would be to create a hash set of all possible substrings from your first input. Then check if each possible substring from the second input is in that hash set.
Time complexity: $O(N_1^2 + N_2^2)$
Memory usage: $O(min(N_1^2, N_2^2))$ (use shortest input as first ... |
I'm doing an implementation of the traveling salesman problem using genetic algorithms, but I can't get it: If we need to get the best route between a certain set of cities and then go back to the first city, how can we do that without going through cities we've already been through again? What would this return route ... |
How to plot the 'back-to-home-city-path' in TSA without repeating cities |
|graphs|artificial-intelligence|traveling-salesman|genetic-algorithms| |
I'm doing an implementation of the traveling salesman problem using genetic algorithms, but I can't get it: If we need to get the best route in a certain set of cities and then go back to the first city, how can we do that without going through cities we've already been through again? What would this return route look ... |
I'm doing an implementation of the traveling salesman problem using genetic algorithms, but I can't get it: If we need to get the best route in a certain set of cities and then go back to the first city, how can we do that without going through cities we've already been through again? What would this route look like? I... |
null |
In "OpenGL superbible" 4th Edition by RICHARD S.WRIGHT JR page 60, there's this piece of code that confuses me:
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity()
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glO... |
I'm unsure as to the amount of operations in Dijkstra's shortest path in terms of $|V|$ and $|E|$.
My guess is that there are (worst case - complete graph):
$$|V| + \sum^{|V|}_{i=1}{(|V|-i)} = \frac{|V| \cdot (|V| + 1)}{2} \implies O(|V|^2)$$
operations for a graph $G = (V, E)$, assuming there are no negative ... |
Dijkstra's operations in terms of $|V|$ and $|E|$ |
|time-complexity|dijkstras-algorithm| |
>Prove that if $C$ and $D$ are context-free languages, then so is $C\circ D := \cup_{n\ge 0} C^n D C^n $.
I know that $\{0^n 1 0^n : n\ge 0\}$ is context free, being the intersection of $L(0^* 10^*)$ and $L(G)$, where $G$ is the context free grammar with start symbol S given by $S\mapsto S1 S | 0S | \epsilon$. Also,... |
prove that context free languages are closed under the $\circ$ operation |
|formal-languages|automata|finite-automata| |
I'll throw a naive algorithm out there.
One way would be to create a hash set of all possible substrings from your first input. Then check if each possible substring from the second input is in that hash set.
Time complexity: $O(N_1^2 + N_2^2)$
Memory usage: $O(min(N_1^2, N_2^2))$ (use shortest input as first ... |
<del>I think it can be done in O(N).</del>
WLOG, we assume the line is $x=0$, and the intersection set is non empty. We can rotate the point set if the line is not $x=0$. The intersection check can be done in O(n) so we can make such assumption.
So we are going to find two point $(0,a)$ and $(0,b)$, such that $a$ ... |
Efficiently find longest common substring for all substring pairs of S and T |
It is a well known fact that the following 'subset-product' problem is $\mathsf{NP}$-complete when $n/\log M = \Theta(1)$.
> Consider a size-$n$ subset of a multiplicative group $\mathbb{G}\cong\mathbb{Z}^{*}_M$. Then an instance of the subset-product problem consists of $(a_1, a_2,\dots,a_n, t)$ with each $a_i, t\i... |
Is this special case of the subset-product problem $\mathsf{NP}$-complete? |
|complexity-theory|np-complete| |
I am trying to find the Gesalt similarity of a string $S$ and all substrings of $T$ using [Gestalt Pattern Matching (Ratcliff Obershelp Algorithm)](https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching)
This algorithm requires me to find the matches of S and T
which is defined as follows
$$
matches(S,T) = \beg... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.