instruction stringlengths 0 29.8k ⌀ |
|---|
The solution in the question is correct.
As the comments say, with $i$ steps any TM can check only inputs of length at most $i$ (the behaviour on longer inputs will be the same as the behaviour on their prefix of length $i$). There is a finite number of those, which can be checked one by one by running $i$ steps on ... |
Given an $n \times n$ matrix $\mathbf{A}$. Let the inverse matrix of $\mathbf{A}$ be $\mathbf{A}^{-1}$ (that is, $\mathbf{A}\mathbf{A}^{-1} = \mathbf{I}$). Assume that one element in $\mathbf{A}$ is changed (let's say $a _{ij}$ to $a' _{ij}$). The objective is to find $\mathbf{A}^{-1}$ after this change. Is there a met... |
Computing inverse matrix when an element changes |
The [Sherman-Morrison formula][1] could help:
$$ (A + uv^T)^{-1} = A^{-1} - \frac{A^{-1} uv^T A^{-1}}{1 + v^T A^{-1} u}. $$
Let $u = (a'_{ij}-a_{ij}) e_i$ and $v = e_j$, where $e_i$ is the standard basis column vector. You can check that if the updated matrix is $A'$ then
$$ A^{\prime -1} = A^{-1} - \frac{(a'_{i... |
Suppose I am using the [Bucket-Sort][1] algorithm and on each bucket/list I sort with insertion sort (replace nextSort with insertion sort in the wikipedia psuedocode).
In the worst case, this would imply that we would have $O(n^2)$ performance because if every element was in one bucket than we would have to use ins... |
You should first understand the proof that bucket sort runs in expected linear time if insertion sort is used. At some point in the proof, the worst-case running time of insertion sort shows up. See what happens when you plug in instead the worst-case running time of any other sorting algorithm.
The reason insertio... |
null |
I have an algorithm where the number of items in my set decrease by $sigma/(1+sigma)$ on each iteration until all items are exhausted.
$S_0$ = $S$
$S_k$ = $S_k$ - $S_k$$sigma/(1+sigma)$
sigma is a small value
How can I find number of iterations? I know it is a geometric series but can't seem to simplify for... |
Big O Complexity |
|time-complexity| |
I have an algorithm where the number of items in my set decrease by $\sigma/(1+\sigma)$ on each iteration until all items are exhausted.
$$
\begin{align*}
S_0 &= S \\
S_{k+1} &= S_k - S_k \frac{\sigma}{1+\sigma}
\end{align*}
$$
$\sigma$ is a small value
How can I find number of iterations? I know it is a ... |
Presumably the correct form of the recursive step is
$$ S_{k+1} \leq S_k - S_k \frac{\sigma}{1+\sigma} = \frac{S_k}{1+\sigma}. $$
Using induction, we can show that
$$ S_t \leq \frac{S}{(1+\sigma)^t}. $$
So the algorithm will end by the time $T$ satisfying
$$ \frac{S}{(1+\sigma)^T} < 1.$$
I'll let you solve this y... |
[One-in-three 3SAT][1] is NP-complete. Looking at the reduction, it inherits the APX-hardness of 3SAT. You can formulate one-in-three 3SAT as a binary integer program with binary entries, so you problem is APX-hard.
[1]: http://en.wikipedia.org/wiki/One-in-three_3SAT |
Given a $0,1$ (binary) integer program of the form:
$$
\begin{array}{lll}
\text{min} & f(x) & \\
\text{s.t.} &A\vec{x} = \vec{b} & \quad \forall i\\
&x_i\ge 0 & \quad \forall i\\
&x_i \in \{0,1\} & \quad \forall i
\end{array}
$$
Note: the size of $A$ is not fixed in either dimension.
I believe this probl... |
I am given the following problem in an Algorithms class:
> Assume that you are given an array A[1 . . . n] of distinct numbers.
> You are told that the sequence of numbers in the array is unimodal, in
> other words, there is an index i such that the sequence A[1 . . . i]
> is increasing (A[j] < A[j + 1] for 1 ≤ j... |
Algorithm to find the mode in a unimodal array |
|algorithms|algorithm-analysis|arrays| |
I am given the following problem in an Algorithms class:
> Assume that you are given an array A[1 . . . n] of distinct numbers.
> You are told that the sequence of numbers in the array is unimodal, in
> other words, there is an index i such that the sequence A[1 . . . i]
> is increasing (A[j] < A[j + 1] for 1 ≤ j... |
Almost correct. Just a small correction. It should be
if A[mid] > a[mid+1]
If two consecutive elements are increasing then they are in the increasing portion of the array, so the mode is to the right. Hence the correction. |
null |
This language is decidable.
Hint: If you are allowed to run for only $i$ steps, what can you do with input of size $j>i$?
Consider moving this question to cs.stackexchange.com, it's not really research-level. |
null |
Suppose I am using the [Bucket-Sort][1] algorithm, and on each bucket/list I sort with insertion sort (replace nextSort with insertion sort in the wikipedia pseudocode).
In the worst case, this would imply that we would have $O(n^2)$ performance, because if every element was in one bucket, then we would have to use ... |
null |
|algorithms|terminology|time-complexity|asymptotics|landau-notation| |
You are referring to the [Landau notation](https://en.wikipedia.org/wiki/Landau_symbols). They are not different symbols for the same thing but have entirely different meanings. Which one is "preferable" depends entirely on the desired statement.
$f \in \cal{O}(g)$ means that $f$ grows at most as fast as $g$, asympt... |
## Master Theorem
The [Master theorem](https://en.wikipedia.org/wiki/Master_theorem) gives asymptotics for the solutions of so-called [divide & conquer](https://en.wikipedia.org/wiki/Divide_and_conquer_algorithm) recurrences, that is such that divide their parameter into proportionate chunks (instead of cutting away... |
Your problem is a special case of a broader class of problems named *node-deletion problems*:
[J. M. Lewis and M. Yannakakis, "The node-deletion problem for hereditary properties is NP-complete" ][1]
... This paper deals with the class of graph problems defined as follows:<br>
for a fixed graph property $\Pi$, ... |
This language is decidable.
Hint: If you are allowed to run for only $i$ steps, what can you do with input of size $j>i$?
|
Let $I$ denote the number of iterations and $s$ the size of your set. Then we have
$$I(s)=I(s-\frac{\sigma}{1+\sigma})+1=I(s-2\frac{\sigma}{1+\sigma})+2=\dots=I(s-k\frac{\sigma}{1+\sigma})+k$$
$s-k\frac{\sigma}{1+\sigma}=0$ when $k=s\frac{1+\sigma}{\sigma}$. Therefore
$$I(s)=s\frac{1+\sigma}{\sigma}$$ |
A single element change, given $A$ with $A^{-1}$, may be tracked with a rank one update. So yes, absolutely, there is a better way than recalculating the inverse from scratch.
Let $\delta = a_{ij}' - a_{ij}$ be the change of the element $a_{ij}$. Using $e_i$ as the unit column vector of one in the $i$ position and z... |
fyi theres a neat, provably "optimal" (in some sense) algorithm for this problem in [Structure and interpretation of computer programs](http://mitpress.mit.edu/sicp/) (free online version) by Abelson and Sussman. it involves partitioning the line in two pieces in a ratio [$\phi$](http://en.wikipedia.org/wiki/Golden_rat... |
Being a programmer I appreciate the errors given by a compiler for a programming language and come to rely on the compiler's error as a safety net.
In learning category theory I would like to have some tool that also acted as a safety net letting me experiment with diagrams and pointing out my mistakes when I make o... |
Tool/app for learning category theory? |
|category-theory| |
Please have a look at this blog:
[Introduction to Category Theory in Scala][1]
It uses Scalaz libray for category theory. There are some in [Haskell][2].
[1]: http://hseeberger.wordpress.com/2010/11/25/introduction-to-category-theory-in-scala/
[2]: http://en.wikipedia.org/wiki/Haskell_%28programming_lan... |
Please have a look at this blog:
[Introduction to Category Theory in Scala][1]
It uses Scalaz libray for category theory. There are some in [Haskell][2].
[1]: http://hseeberger.wordpress.com/2010/11/25/introduction-to-category-theory-in-scala/
[2]: http://www.haskell.org/haskellwiki/Category_theory |
I am trying to analyze the running time of a bad implementation of generating the $n$th member of the fibonacci sequence (which requires generating the previous 2 values from the bottom up).
Why does this algorithm have a time complexity of at least $O(2^{\frac{n}{2}})$? Where does the exponent come from? |
Why does a recurrence of $T(n - 1) + T(n - 2)$ indicate an asymptotic performance of at least $O(2^{\frac{n}{2}})$? |
|runtime-analysis| |
There are at least three encodings of (aspects of) [Category Theory in Coq][1]. Approaches using a proof assistant guarantee correctness by design, though I don't know whether they will enhance understand. You'll then have both the proof assistant and Category Theory to learn.
If you want a reasonably introductory,... |
I'm developing software to run variations on a base process flow (see #1, below). A user specifies in a text file what steps in the process to modify. Because each step takes a long time to run, I'd like to minimize the amount of duplicate processing required. For example, if variations occur at step B, I could run ste... |
Algorithm for finding optimal branch points |
|optimization| |
null |
I have a language for sensor networks (generates C code) and I want to define the formal semantics of it.
The language has this form:
{STATE name_state:
EVERY time
SELECT {variable [, variable] ...}
[SENDIF send_condition]
[CHANGEIF change_condition GOTO new_state];
} ...
START... |
Formally describing a sensor network language |
|formal-languages|programming-languages|semantics| |
The running time of the naive solution is: $$T(n)=T(n-1)+T(n-2) \lt 2T(n-1)$$
Now, $$2T(n-1)=2(2T(n-2))=2(2(2T(n-3)))=\dots=2^kT(n-k)=\dots=2^nT(0)=2^n$$
The base case takes time $T(0)=\Theta(1)$. So that's where the exponent is coming from. This result is an upper bound; you can obtain a tighter bound if you solve... |
The solution in the question is correct.
The constraint $i\ne j$ is the one that gives us trouble. To get around it we have to split into two cases: (i) $i<j$, and (ii) $i>j$ (but still $i<2j$)
thus
$S\to S_{(i)} \mid S_{(ii)}$
as the first production splits into this two cases.
Now, divide and conquer... |
you can find for **Every linear recurrence with constant coefficients** a closed form. (See the [link][1]) the [Fibonacci][2] numbers have a closed-form solution as (the approximation is for large ns):
$F_n \times \sqrt{5} ={ \left( \frac { 1+\sqrt { 5 } }{ 2 } \right) }^{ n }-{ \left( \frac { 1-\sqrt { 5 } }{ 2... |
The running time of the naive solution is: $$T(n)=T(n-1)+T(n-2) \lt 2T(n-2)$$
Now, $$2T(n-2)=2(2T(n-4))=2(2(2T(n-6)))=\dots=2^kT(n-2k)=\dots=2^nT(0)=2^{\frac n 2}$$
The base case takes time $T(0)=\Theta(1)$. So that's where the exponent is coming from. This result is an upper bound; you can obtain a tighter bound i... |
It's not $O(2^{n\over 2})$ is $\Theta(\phi^n)$ which doesn't belong to $O(2^{n\over 2})$ but you can say belongs to $\Omega(2^{n\over 2})$ or belongs to $O(2^n)$ (and saadtaame showed this in his answer), So be careful about abuse of notations. But why is $\Theta(\phi^n)$? as a student of CS you should try to solve it ... |
[A Course on Deterministic Distributed Algorithms][1] by Jukka Suomela.
Is about:
- distributed systems as a model of computation.
- distributed algorithms in the port-numbering model.
- optimisation problems about vertex covers and edge dominating sets.
- networks with unique identifiers.
- ramsey theo... |
The running time of the naive solution is: $$T(n)=T(n-1)+T(n-2) \lt 2T(n-1)$$
Now, $T(n) < 2T(n-1)<2^2 T(n-2)....<2^n T(0)$.
The base case takes time $T(0)=\Theta(1)$. So that's where the exponent is coming from. This result is an upper bound; you can obtain a tighter bound if you solve the recurrence using generat... |
you can find for **Every linear recurrence with constant coefficients** a closed form. (See the [link][1]) the [Fibonacci][2] numbers have a closed-form solution as (the approximation is for large ns):
$F_n \times \sqrt{5} ={ \left( \frac { 1+\sqrt { 5 } }{ 2 } \right) }^{ n }-{ \left( \frac { 1-\sqrt { 5 } }{ 2... |
It's not $O(2^{n\over 2})$ is $\Theta(\phi^n)$ which doesn't belong to $O(2^{n\over 2})$ but you can say belongs to $\Omega(2^{n\over 2})$ or belongs to $O(2^n)$ (and saadtaame showed this in his answer), So be careful about abuse of notations. But why is $\Theta(\phi^n)$? as a student of CS you should try to solve it ... |
The running time of the naive solution is: $$T(n)=T(n-1)+T(n-2) \lt 2T(n-1)$$
Now, $$2T(n-1)=2(2T(n-2))=2(2(2T(n-3)))=\dots=2^kT(n-k)=\dots=2^nT(0)=O(2^n)$$
The base case takes time $T(0)=\Theta(1)$. So that's where the exponent is coming from. This result is an upper bound; you can obtain a tighter bound if you so... |
[Backus-Naur form][1] used to be popular for these purposes. Another possibility is [Wirth syntax notation][2]. You can find other possibilities in the "see also" section of the article on Backus-Naur form.
[1]: http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form
[2]: http://en.wikipedia.org/wiki/Wirth_synt... |
Expanding on Reza's answer, every recurrence of the form $T(n) = T(n-1) + T(n-2)$, with arbitrary starting values, has a solution of the form
$$ T(n) = A \left( \frac{1+\sqrt{5}}{2} \right)^n + B \left( \frac{1-\sqrt{5}}{2} \right)^n, $$
for some $A,B$. Note that $|(1-\sqrt{5})/2| < 1$, and so the second term tends t... |
Expanding on Reza's answer, every recurrence of the form $T(n) = T(n-1) + T(n-2)$, with arbitrary initial values, has a solution of the form
$$ T(n) = A \left( \frac{1+\sqrt{5}}{2} \right)^n + B \left( \frac{1-\sqrt{5}}{2} \right)^n, $$
for some $A,B$. Note that $|(1-\sqrt{5})/2| < 1$, and so the second term tends to... |
I have an algorithm where the number of items in my set decrease by $\sigma/(1+\sigma)$ on each iteration until all items are exhausted.
$$
\begin{align*}
S_0 &= S \\
S_{k+1} &= S_k - S_k \frac{\sigma}{1+\sigma}
\end{align*}
$$
Here $\sigma$ is a small value.
How can I find number of iterations? I know it... |
Finding the number of iterations to a recurrence |
|time-complexity|recurrence-relation|discrete-mathematics| |
There's a neat, provably "optimal" (in some sense) algorithm for this problem in [Structure and interpretation of computer programs](http://mitpress.mit.edu/sicp/) (free online version) by Abelson and Sussman. It involves partitioning the line in two pieces in a ratio [$\phi$](http://en.wikipedia.org/wiki/Golden_ratio)... |
Intuition about decidability |
SAT [5] can be solved with resolution definitively, i.e. if the formula has a true assignment, resolution can find it, and if it cant be satisfied, resolution can show that no assignment exists (at least in exponential time/space.). [4]
> Is there a good fully-self contained description somewhere of solving SAT wit... |
Description of resolution algorithm as it applies to SAT |
Worst case analysis of bucket sort using insertion sort for the buckets |
null |
null |
$P$ is defined as the class of (decision) problems that have an algorithm that solves them in polynomial time (in a TM, or a polynomially-equivalent model). Thus, $P$ contains exactly these problems, no more and no less.
As for $NP$- the situation is more delicate. A problem is in $NP$ if it has a nondeterministic a... |
Are all algorithms which have polynomial time complexity belong to P class ? And P class do not have any algorithm which does have not polynomial complexity ?
Are all algorithms which have non polynomial complexity belong to NP or NP-Hard or both ?
I am just trying to understand the basic relationship. |
The exact relation between complexity classes and algorithm complexities |
|complexity-classes|np|polynomial-time| |
null |
null |
null |
null |
Von Neumann suggested his famous computer architecture as a way to simulate the laws of (classical) physics. Furthermore, it was shown that these laws can be simulated efficiently.
If you believe that the human brain works under the constraints of classical physics (also, to an extent, under quantum physics), then t... |
Facial recognition. Human does better and quicker here than computers. |
Are there any problems which can be solved by human brain in a very less time but a computer may take a lot of time or a computer could never solve it ? |
What are some problems which are easily solved by human brain but which would take more time computers? |
|algorithms| |
null |
I would like to find the height of a d-ary heap. Assuming you have an Array that starts indexing at $1$ we have the following:
The parent of a node $i$ is given by: $\left\lfloor\frac{i+1}{d}\right\rfloor$
The $d$ children of a parent at node $i$ are given by: $di + 1, di+2, \ldots di+d$
The height of a heap (... |
Finding the height of a d-ary heap |
|data-structures|recurrence-relation|heaps| |
If you consider **computability**, human brain is **not stronger than Turing machine**. Turing machine could have infinite memory (arbitrarily extendable tape) while our memory is not (limit in storing information).
But in some current applications it seems human brain works better according to performance than curr... |
Language processing.
Every kid learns how to use language within his first 1-3 years. Computers still don't understand simple language structures, not to mention ambiguity, sarcasm, subtleties, etc. |
|algorithms|artificial-intelligence|computer-vs-human| |
I would like to find the height of a d-ary heap. Assuming you have an Array that starts indexing at $1$ we have the following:
The parent of a node $i$ is given by: $\left\lfloor\frac{i+1}{d}\right\rfloor$
The $d$ children of a parent at node $i$ are given by: $di-d+1, di-d+2,\ldots di+1$
The height of a heap ... |
A different approach is to calculate the number of points $n_d(h)$ in a saturated (maximal) $d$-ary heap of height $h$. Given $n_d(h)$, the height of a $d$-ary heap of size $n$ is the minimal $h$ such that $n_d(h) \geq n$. Given the formula for $n_d(h)$, you should be able to find $h$ explicitly. |
If whatever happens after $B$ depends on that, you can't "reuse" any runs after a modified $B$. So the tree-like scheduling is really the best that can be done.
If the later steps are independent of (some) of the previous steps, things get more interesting... but that presumes you have a completely reliable way of d... |
All algorithms that solve some decision problem in polynomial time show that their problems are in $P$. But there are certainly algorithms that don't take polynomial time for problems in $P$. You could sort by generating all $n!$ permutations of the input, and check each if it is sorted. That algorithm does take a more... |
null |
{"OriginalQuestionIds":[9556],"Voters":[{"Id":472,"DisplayName":"Juho"},{"Id":4249,"DisplayName":"Pål GD"},{"Id":19,"DisplayName":"Nicholas Mancuso"},{"Id":39,"DisplayName":"Gilles"}]} |
null |
Since the input is of length $n^2$, it makes sense that the TM must read it at least once (to learn the value of $n$), and we have a trivial lower bound of $\Omega(n^2)$. It is my understanding that what you actually ask is "*can we complete the task with $O(n^2)$ steps as well*"?
You suggest using the [Sieve of ... |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.