instruction stringlengths 0 29.8k ⌀ |
|---|
|strings|dynamic-programming|substrings| |
You need to compute the probability $p$ that two integers between one and nine add to ten. Then solve $p*x=1$ and $x$ is the number of iterations done on average.
I think this is 8.1 which is O(1).
In general you would need to evaluate the running time of your algorithm on random inputs (for a specific probabilit... |
An insight here is that the probability of returning early does not depend on the length of the input (as long as numbers.length is of such a size that you would always expect to find two numbers that add to ten).
You need to compute the probability $p$ that two integers between one and nine add to ten. Then solve $... |
An insight here is that the probability of returning early does not depend on the length of the input (as long as numbers.length is of such a size that you would expect to find two numbers that add to ten).
You need to compute the probability $p$ that two integers between one and nine add to ten. Then solve $p*x=1$ ... |
An insight here is that the probability of returning early does not depend on the length of the input (as long as numbers.length is of such a size that you would expect to find two numbers that add to ten).
You need to compute the probability $p$ that two integers between one and nine add to ten. Then solve $p*x=1$ ... |
Have a look in the book of Hopcroft and Ullman "Introduction to automata theory, languages and computation" (ISBN 0-201-02988-X). I have only the German version of this book, but there is is mentioned as Theorem 12.5.
However the basic idea behind the tape-reduction from $k$ tapes to 1 is quite easy. Assume the runn... |
Have a look in the book of Hopcroft and Ullman "Introduction to automata theory, languages and computation" (ISBN 0-201-02988-X). I have only the German version of this book, but there it is mentioned as Theorem 12.5.
However the basic idea behind the tape-reduction from $k$ tapes to 1 is quite easy. Assume the runn... |
Why does it take $O(f(n)^2)$ to simulate a 3-tape $O(f(n))$-time TM on a 1-tape TM? |
|turing-machines|tape-complexity| |
null |
When considering questions like this you need to make explicit what representation you are using for your languages. In the following I will assume you are using context-sensitive grammars as input for your problems.
(a) is a well known undecidable property of context-sensitive grammars.
(b), (c) and (e) are obvi... |
Is there an algorithm to raise a Matrix M to the n'th power in O(log n) time? I have been searching online, but have been unsuccessful thus far.
Regards.
|
Matrix exponentiation in O(log n) |
|matrices| |
Here is the pseudocode for an $O(lg n)$ matrix exponentiation algorithm. Note that the * operator denotes ordinary matrix multiplication.
MATHPOWER (M, n)
if n == 1
then return M
else
P = MATHPOWER (M, floor(n/2))
if n mod 2 == 0
then return P * P
else
return... |
There are two context-sensitive languages, $L_1$ and $L_2$. Which of the following statements about them are decidable respectively undecidable?
1. $L_1 = \emptyset$
2. $L_1 = \Sigma^*$
3. $L_1 \cap L_2 = \emptyset$
4. $\overline{L_1}$ is also a context-sensitive language.
5. $L_1 = L_2$ |
Which properties of context sensitive languages are decidable? |
|formal-languages|undecidability|context-sensitive| |
When considering questions like this you need to make explicit what representation you are using for your languages. In the following I will assume you are using context-sensitive grammars as input for your problems.
1) is a well known undecidable property of context-sensitive grammars.
2) as well as 3) and 5) ar... |
Just a quick hint on how you can build the guess part of the non-deterministic solver, given a deterministic verifier (using *ASCII art* :)
+----------------------+ +-----------------+
| | | |
| t1 V ... |
Is there an algorithm to raise a Matrix M to the n'th power in $O(log \ n)$ time? I have been searching online, but have been unsuccessful thus far.
|
Is there an algorithm to raise a matrix to the $n$th power in $O(\log n)$ time? I have been searching online, but have been unsuccessful thus far. |
Here is the pseudocode for an $O(\lg n)$ matrix exponentiation algorithm. Note that the * operator denotes ordinary matrix multiplication.
MATHPOWER (M, n)
if n == 1
then return M
else
P = MATHPOWER (M, floor(n/2))
if n mod 2 == 0
then return P * P
else
retur... |
Matrix powering in O(log n) |
> **Substring Diff**
> Given two strings of length $n$, $P = p_1\dots p_n$ and $Q = q_1 \dots q_n$, we define $M(i, j, L)$ as the number of
> mismatches between $p_i \dots p_i+L-1$ and $q_j \dots q_j+L-1$. In set
> notation, $M(i, j, L)$ refers to the size of the set $\{0 \leq x < L \mid p_(i + x) \neq q_(j + x)\}... |
Dynamic programming table for finding similar substrings is too large |
|complexity-theory|terminology|nondeterminism| |
|algorithms|matrices| |
null |
Matrix powering in $O(\log n)$ time? |
> **Substring Diff**
> Given two strings of length $n$, $P = p_1\dots p_n$ and $Q = q_1 \dots q_n$, we define $M(i, j, L)$ as the number of
> mismatches between $p_i \dots p_{i+L-1}$ and $q_j \dots q_{j+L-1}$. In set
> notation, $M(i, j, L)$ refers to the size of the set $\{0 \leq x < L \mid p_{i + x} \neq q_{j + ... |
One can reduce your problem to the following. Given a sequence of $N$ numbers, find a contiguous subsequence of length at most $K+1$ having maximal sum. This problem, in turn, is solvable in time $O(N)$.
What's the connection between your problem and mine? Let the positions of the mistakes be $I_1,\ldots,I_t$, and a... |
There are two other algorithms which may or may not be relevant. The first algorithm diagonalizes your matrix (which is usually possible), writing it as $M = PDP^{-1}$, where $M,D$ in general may be complex-valued. You then compute $M=PD^nP^{-1}$. Note it's very easy to raise a diagonal matrix to the $n$th power. If $M... |
Here's an elaboration of The Unfun Cat's answer. For convenience, let the numbers be $v_1,\ldots,v_n$. Whatever the value of $v_1$ is, for $i>1$ we have $\Pr[v_i = 10-v_1] = 1/10$. Therefore, the number of iterations of the second loop is roughly distributed geometrically $G(1/10)$, so we expect it to run about $10$ ti... |
I'm a little confused by your quote.
There are two equivalent definitions of the NP complexity class in terms of Turing Machines:
1. The class of problems for which a deterministic verifier exists whose runtime is bounded by a polynomial in the size of the problem input.
2. The class of problems for which a no... |
Just a quick hint on how you can build the guess part of the non-deterministic solver, given a deterministic verifier (using *ASCII art* :)
+----------------------+ +-----------------+
| | | |
| t1 V ... |
Just a quick hint on how you can build the guess part of the non-deterministic solver, given a deterministic verifier (using *ASCII art* :)
+----------------------+ +-----------------+
| | | |
| t1 V ... |
An insight here is that the probability of returning early does not depend on the length of the input (as long as numbers.length is of such a size that you would expect to find two numbers that add to ten).
You need to compute the probability $p$ that two integers between one and nine add to ten. Then solve $p*x=1$ ... |
The definitions I've found were highly technical and using terms I've never seen before.
Say, I have a certain irrational number *e* that I get get closer and closer to with a computer and I want to determine if there is a particular digit *d* appearing after a certain position. Or what about the halting problem (g... |
What's an intuitive distinction between semi-computable problems and noncomputable problems/functions? |
|computability| |
Intuitively, a set of numbers is *computable* or *decidable* or *recursive* if there is an algorithm deciding membership for the set. A set of numbers is *semidecidable* or *recursively enumerable* (r.e.) if it has verifiable "proofs" of membership. For example, the set of programs which halt is semidecidable, since gi... |
What differences and relations are between randomized algorithms and nondeterministic algorithms?
From Wikipedia
> A **randomized algorithm** is an algorithm which employs a degree of
> randomness as part of its logic. The algorithm typically uses
> uniformly random bits as an auxiliary input to guide its behav... |
Differences and relations between randomized and nondeterministic algorithms? |
|algorithms| |
I'm familiar with a few problems of each class and even though the definitions are based on sets and polynomial reducibility, I see a pattern with time complexity. NP problems appear to be O(2^n) (minus the P problems of course), and NP-hard problems seem to be worse: n^n or n! (Chess, TSP). Is this a misleading interp... |
What is the relashionship between NP/NP-Complete/NP-Hard to time complexity? |
|complexity-theory|time-complexity|np-hard| |
Im having trouble figuring out how to determine if two finite automations are the same apart from renumbered states.
More specifically, heres an example:
![example][1]
Its easy to generate a regular expression by hand and see that both FA produce:
b + (ab*a(a+b)), though their states are renumbered, they ar... |
Permutation of states in two FA |
|automata|finite-automata| |
There are two other algorithms which may or may not be relevant. The first algorithm [diagonalizes][1] your matrix (which is usually possible), writing it as $M = PDP^{-1}$, where $M,D$ in general may be complex-valued. You then compute $M=PD^nP^{-1}$. Note it's very easy to raise a diagonal matrix to the $n$th power. ... |
null |
See the definition of [NP completeness][1]. For a problem to be NP-complete, it needs to be in NP and all NP problems need to be reducible to it in polynomial time. This condition is what it means to be NP hard.
Thus NP complete problems are the intersection of NP problems and NP hard problems.
NP $\subseteq$ EX... |
I'm familiar with a few problems of each class and even though the definitions are based on sets and polynomial reducibility, I see a pattern with time complexity. NP problems appear to be $O(2^n)$ (minus the P problems of course), and NP-hard problems seem to be worse: $n^n$ or $n!$ (Chess, TSP). Is this a misleading ... |
What is the relationship between NP/NP-Complete/NP-Hard to time complexity? |
Intuitively, a set of numbers is *computable* or *decidable* or *recursive* if there is an algorithm deciding membership for the set. A set of numbers is *semidecidable* or *recursively enumerable* (r.e.) if it has verifiable "proofs" of membership. For example, the set of programs which halt is semidecidable, since gi... |
I can identify a permutation on the set of states $\{1,2,3,4\}$ the turns the left-hand diagram into the right-hand one. In other words, if you renumber the states on the left-hand diagram, you get the right-hand diagram. Thus the two automata are identical up to renumbering. |
Non-deterministic algorithms are very different from probabilistic algorithms.
Probabilistic algorithms are ones using coin tosses, and working "most of the time". As an example, randomized variants of quicksort work in time $\Theta(n\log n)$ in expectation (and with high probability), but if you're unlucky, could ... |
It is possible, if messy, to convert the proof of the Immerman-Szelepcsényi theorem to the reduction you want. There is absolutely no need to use the NL-completeness of st-connectivity.
Given an instance $G=(V,E),s,t$, we construct a new graph $G'=(V',E'),s',t'$. The "major vertices" of $V'$ record the following inf... |
Im having trouble figuring out how to determine if two finite automations are the same apart from renumbered states.
More specifically, heres an example:
![example][1]
Its easy to generate a regular expression by hand and see that both FA produce:
b + (ab*a(a+b)), though their states are renumbered, they ar... |
Finding an isomorphism between finite automata |
|computability|terminology| |
|algorithms|terminology|randomized-algorithms|machine-models|nondeterminism| |
|complexity-theory|terminology|time-complexity|np-hard| |
See the definition of [NP completeness][1]. For a problem to be NP-complete, it
1. needs to be in NP and
2. all NP problems need to be reducible to it in polynomial time.
Condition 2 alone is what it means to be NP hard. Thus NP complete problems are the intersection of NP problems and NP hard problems.
... |
null |
I've given some intervals I = {I(1), I(2), ..., I(m)} for I(i) = [a_i, b_i] (1<=a_i<=b_i<=n). You may suppose that intervals cover each other(sorry i'm poor in english), so there's no intervals such as {[1,5], [3,6]}, {[2,5], [5,7]}. And {[1,1], [2,2], ..., [n,n]} must be included in I.
Let's suppose C(i) = b_i - a_... |
How to optimize this DP solution? |
|algorithms|dynamic-programming| |
IAASDASDADASDASDSADASDADADASDASDASDASD |
`T[1] = 1, T[2] = 2, T[i] = T[i-1] + T[i-3] + T[i-4] (for i>2)`.
I have to calculate that, but N is to big(<=10^9), how can I optimize it? |
null |
Here's an elaboration of The Unfun Cat's answer. For convenience, let the numbers be $v_1,\ldots,v_n$. Whatever the value of $v_1$ is, for $i>1$ we have $\Pr[v_i = 10-v_1] = 1/9$. Therefore, the number of iterations of the second loop is roughly distributed geometrically $G(1/9)$, so we expect it to run about $9$ times... |
As Bartek commented, you are missing a base case. You can compute large values of $T$ in several ways:
* Bartek's suggestion: Use an array to store all the entries computed so far.
* You can optimize the previous method, dramatically reducing the memory needed: store only the last $4$ entries of the array at each p... |
I like to implement an Arc-Legth Parameterization of a cubic bezier curve. so far i have implemented the method of calculating the Arc-Length of the curve and now i'm stuck at calculating the times to divide the original curve into equl arc-length segments.
What i have:
$m = 5$ The number of segments to create
... |
Arc-Length parameterization of a cubic bezier curve |
|algorithms| |
Your understanding is correct at a very high level. A problem being in NP means that the problem is “easy” (in a certain specific sense), whereas a problem being NP-hard means that the problem is “difficult” (in another specific sense), and I think that you understand this correctly.
However, your understanding is ... |
There are many exceptions to your running time summaries.
Probably most notably, TSP can be solved in $n^22^n$ time with dynamic programming; you don't need all $n!$.
There are some NP-hard problems that can even be solved a bit faster than $2^n$. Subset sum can be solved in $O(2^{n/2})$ time, or about $O(1.4^n)... |
There are many exceptions to your running time summaries.
Probably most notably, TSP can be solved in $n^22^n$ time with dynamic programming (the [Held-Karp Algorithm)][1]; you don't need all $n!$.
There are some NP-hard problems that can even be solved a bit faster than $2^n$. Subset sum can be solved in $O(2^{... |
See the definition of [NP completeness][1]. For a problem to be NP-complete, it
1. needs to be in NP and
2. all NP problems need to be reducible to it in polynomial time.
Condition 2 alone is what it means to be NP hard. Thus NP complete problems are the intersection of NP problems and NP hard problems.
... |
null |
An algorithm specifies a method to get from a given input to a desired output that has a certain relation with the input. We say that this algorithm is deterministic if at any point, it is specified exactly and unambiguously what the next step in the algorithm is that must be performed as part of that method, potential... |
There are many exceptions to your running time summaries.
Probably most notably, TSP can be solved in $n^22^n$ time with dynamic programming (the [Held-Karp Algorithm)][1]; you don't need all $n!$.
There are some NP-hard problems that can even be solved a bit faster than $2^n$. Subset sum can be solved in $O(2^{... |
[Newbie here] I have a forest, i.e., nodes with directed edges and no cycles (directed or undirected). I define the height of a vertex $v$ as 0 if it does not have any incoming edges, or the maximum number of edges to traverse in reverse to reach a vertex of height 0.
![enter image description here][1]
I also know... |
Finding the height of all nodes in a forest |
|untagged| |
I don't know if this problem has an official name or not. Your title sums it up well enough. Walking up from the 0 height nodes will be fast, provided you take care to avoid duplicate work. Suppose you have a node with many children and a long path above this node to the root. Suppose also that the heights of each of t... |
Why?
$2^{\log_2 x} = x$
$\log_{10}(2^{\log_2 x}) = \log_{10} x$
$\log_2 x(\log_{10}2) = \log_{10} x$ $(*)$
$\log_2 x = \dfrac{\log_{10} x}{\log_{10}2}$
QED.
$(*) \log x^y = y*\log x$ |
I like to implement an arc-length Parameterization of a cubic bezier curve. So far I have implemented the method of calculating the arc length of the curve and now I'm stuck at calculating the times to divide the original curve into equal arc length segments.
What i have:
* $m = 5$ The number of segments to crea... |
|algorithms|computational-geometry|numerical-analysis| |
I have a forest, i.e., nodes with directed edges and no cycles (directed or undirected). I define the height of a vertex $v$ as 0 if it does not have any incoming edges, or the maximum number of edges to traverse in reverse to reach a vertex of height 0.
![enter image description here][1]
I also know that the aver... |
|algorithms|trees|graph-traversal| |
|algorithms|arrays|subsequences| |
$$\begin{align*}
T[1] &= 1 \\
T[2] &= 2 \\
T[i] &= T[i-1] + T[i-3] + T[i-4] & \text{for \(i \gt 2\)} \\
\end{align*}$$
I have to calculate $T[N]$, but $N$ is to big ($\approx 10^9$), how can I optimize it? |
Optimize a linear recurrence |
|algorithms|dynamic-programming|recursion| |
|algorithms|strings|subsequences| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.