instruction stringlengths 0 29.8k ⌀ |
|---|
For a given input $N$, how many times does the enclosed statement executes?
> for $i$ in $1\ldots N$ loop <br>
> $\quad$for $j$ in $1\ldots i$ loop <br>
> $\quad$$\quad$for $k$ in $i\ldots j$ loop <br>
> $\quad$$\quad$$\quad$$sum = sum + i$ ; <br>
> $\quad$$\quad$end loop; <br>
> $\quad$end loop; <br>
> end lo... |
A puzzle related to nested loops |
|loops| |
|time-complexity|algorithm-analysis| |
You need to solve simple formula
$\sum_{i=1}^N\sum_{j=1}^i\sum_{k=i}^j1$
this will give you overall result of
$\frac{1}{6}N(N+1)(N+2)$
Math is easy to do here but I used [Wolfram Alpha][1]
[1]: http://www.wolframalpha.com/input/?i=sum%20%28sum%28sum%281%29%20from%20i%20to%20j%29%20from%20j=1%20to%20i... |
|algorithm-analysis|loops| |
What you really count in the variable $\text{sum}$ are triples of the form
$$\{ (a,b,c) \mid 1\le a<b<c\le N\}.$$
Clearly there are $N(N-1)(N-2)$ triples of different elements. Since you only consider sorted triples, you only count one of the possible $6=3!$ permutations for every triple containing $a,b,c$. Theref... |
An <i>abstract decision problem</i>, such as <b>clique</b>, is an assignment of a truth value (b>true</b> or <b>false</b>) for each <i>instance</i> of the problem. In the case of <b>clique</b>, each instance is a pair $(G,k)$, where $G$ is a graph and $k$ is a natural number, and the problem assigns <b>true</b> to a pa... |
I am interested in self-reducibility of Graph 3-Coloralibity problem.
**Definition of Graph 3-Coloralibity problem.**
Given an undirected graph $G$ does there exists a way to color the nodes red, green, and blue so that no adjacent nodes have the same color?
**Definition of self-reducibility.**
A language $... |
Graph 3-colorability is self-reducible |
|complexity-theory|reductions| |
Unfortunately I have no idea how to show this:
>Show that the set of $\text{P}$-complete languages is not closed under intersection.
Any help is much appreciated. |
Proof for P-complete is not closed under intersection |
|complexity-theory|time-complexity| |
I think this questions exploits only a technicality. However, you can follow this path
1. The class of ${\sf P}$-complete languages is ${\sf P}$ without $\Sigma^*$ and $\emptyset$.
2. Show that there are two disjoint languages in ${\sf P}$, for simplicity take two disjoint regular languages. |
Unfortunately I have no idea how to show this:
>Show that the set of ${\sf P}$-complete languages is not closed under intersection.
Any help is much appreciated. |
|complexity-theory|time-complexity|reductions| |
null |
As Vor mentions in his comment, your reduction doesn't work, since 3-colorability doesn't accept partial assignments of colors. The problem goes even deeper, since setting the color of a single vertex doesn't make *any* progress in determining whether the graph is 3-colorable: indeed, the graph is 3-colorable iff there... |
Let $A$ be any P-complete problem (say circuit evaluation). Here are two other P-complete problems: $A_0 = \{0x : x \in A \}$ and $A_1 = \{1x : x \in A\}$. The problem $A_0 \cap A_1 = \emptyset$, while definitely in P, isn't P-complete. The latter is true even if we allow Turing reductions, assuming $L \neq P$. |
Given the discrete intervals $[a,b]\subset\mathbb{N}$ and $[c,d]\subset\mathbb{N}$, we might be able to do slightly better than binary search using the midpoint without utilizing gradient descent.
Instead, we could use binary search with $x=a+\lfloor\frac{y-c}{d-c}(b-a)\rfloor$, which corresponds to the below inters... |
|terminology|database-theory|relational-algebra| |
|automata|pushdown-automata|machine-models| |
|complexity-theory|terminology|np-complete| |
null |
In short: an instance of a problem is the input for an algorithm solving the problem. Correspondingly, solutions are the outputs of such an algorithm. |
I am trying to come up with a Grammar for L, but I'm getting no where. Can't figure it out.
I came up with some sample strings from the language which would be accepted: 'b', 'abcab', 'accbcaa'.
I understand the length of the string has to be odd, and the middle character cannot be repeated anywhere in the string.
... |
Grammar for a language |
|formal-languages|formal-grammars| |
Other answers are good, I'll give only another trivial example:
* *problem*: "given two numbers $k,n$ with $1 < k < n$, does a number $m$ smaller or equal than $k$ exist such that $n$ is divisible by $m$ ?"
* the *instances* of the problem (or informally the *input* of the problem) are all the valid pairs $(k,n)$... |
Other answers are good, I'll give only another trivial example:
* *problem*: "given two numbers $k,n$ with $1 < k < n$, does a number $m$ smaller or equal than $k$ exist such that $n$ is divisible by $m$ ?"
* the *instances* of the problem (or informally the *input* of the problem) are all the valid pairs $(k,n)$... |
I don't know exactly how to solve the exercise below.
>Show that the multiplication lies in $\text{FL}$.
>
>Hint: A useful approach to a solution is to split the exercise into two parts and to explain that each function lies in $\text{FL}$. The standard multiplication scheme can be used as an intermediate step. Ex... |
Show that the multiplication lies in FL |
|complexity-theory|space-complexity| |
Assume the middle character is $a$. Then a grammar is
$$A \rightarrow bAb | bAc | cAb | cAc | a$$
Similarly, we can define nonterminals $B$ and $C$ for the strings in our language where $b$ and $c$, respectively, are the middle symbols. Given those, you can get a grammar for your language by taking the union:
$$S \r... |
Hint: Consider the standard multiplication scheme. Suppose that we compute the sum column by column, starting with the LSB. How big is the carry we have to remember?
Comment: Multiplication is actually in NC<sup>1</sup> (hard) and even in TC<sup>0</sup> (harder). |
There are two flavors of outer union: with and without `NULL`s. Google search readily exibits [an example][1] for `NULL`s version. The cleaner version of relational algebra desn't allow `NULL`s, and outer union is defined via De Morgan's law:
$ X \bigcup Y = \overline {\overline X \Join \overline Y} $
Date&Da... |
There are two flavors of outer union: with and without `NULL`s. Google search readily exibits [an example][1] for `NULL`s version. The cleaner version of relational algebra desn't allow `NULL`s, and outer union is defined via De Morgan's law:
$ X \bigcup Y = \overline {\overline X \Join \overline Y} $
Date&Da... |
I am reading Papadimitriou, Computational Complexity, page 24, where it is says
> We say that $M$ accepts $L$ whenever for any string $x \in (\Sigma - \{\sqcup\})^*$, if $x \in L$, then $M(x) =$ ``yes''; however, if $x\notin L$, then $M(x) = \nearrow$.
The key issue is what happens for $x \notin L$. This defini... |
Conflicting definitions of language accepted by Turing Machine? |
|reference-request|turing-machines| |
null |
Unfortunately I have no idea how to show this:
>Show that the set of ${\sf P}$-complete languages is not closed under intersection.
As far as I understand my lecture notes, ${\sf P}$-completeness is defined as follows:
* $A \subset \Sigma^{*}$ is complete for ${\sf P}$ iff $A \in \text{P}$ and $\forall B \in ... |
Consider the following language over the alphabet $\mathcal{A} = \{a,b,c\}$:
$$L = \left\{w \in \mathcal{A}^* \mid \text{\(|w|\) is odd and the middle character in \(w\) occurs nowhere else in \(w\)} \right\}$$
I am trying to come up with a grammar for $L$, but I'm getting nowhere. I came up with some sample string... |
Grammar for a language: odd length, middle character not repeated |
I am reading Papadimitriou, Computational Complexity, page 24, where it is says
> We say that $M$ accepts $L$ whenever for any string $x \in (\Sigma - \{\sqcup\})^*$, if $x \in L$, then $M(x) =$ ``yes''; however, if $x\notin L$, then $M(x) = \nearrow$.
The key issue is what happens for $x \notin L$. This defini... |
I beg to differ to the other answer.
The two definitions are in fact equivalent. Both halt and accept when the word belongs to the language. One is more restricted for strings outside of the language: it is not allowed to halt. Every Turing machine in the "classic" definition (which allows halting with "no") can be ... |
null |
Your question is somewhat unclear, but here is something you can prove using the time hierarchy theorem. We will use the convention that a Turing machine computing some function prints the result at the end, and prints nothing except that. Suppose $T$ is a machine that accepts the code of a machine $P$ running in time ... |
If an optimization problem is known to be inapproximable up to some precision, does this automatically imply that the problem is apx-hard? |
Inapproximability result implies apx-hardness? |
|complexity-theory|approximation| |
As Vor mentions in his comment, your reduction doesn't work, since 3-colorability doesn't accept partial assignments of colors. The problem goes even deeper, since setting the color of a single vertex doesn't make *any* progress in determining whether the graph is 3-colorable: indeed, the graph is 3-colorable iff there... |
If P$=$NP then there is a polytime algorithm for any NP optimization problem, and so *every* problem is APX-hard. So from now on, suppose that P$\neq$NP.
We can associate with any decision problem $L \in NP$ an optimization problem $o_L$ by defining $o_L(x) = 1$ if $x \in L$ and $o_L(x) = 2$ otherwise. Suppose $o_L$... |
The two definitions are in fact equivalent. Both halt and accept when the word belongs to the language. One is more restricted for strings outside of the language: it is not allowed to halt. Every Turing machine in the "classic" definition (which allows halting with "no") can be changed into a non-halting one easily. J... |
Deterministic context-free languages are commonly defined using an *automaton* concept, the (restricted, deterministic) pushdown automaton. To some that is confusing, as the name *context-free* refers to a grammar type.
I seem to remember there exists a characterization of the DCF languages using grammars. In my rec... |
deterministic context-free languages: *grammatical* characterization |
|reference-request|formal-grammars|context-free| |
I am not sure what Proof for Lemma 34.6 in CLRS book 3rd edition pg 1074 means. They provided a diagram regarding the configuration. Can anyone explain me the proof in simple words? |
Circuit Satisfiability problem is NP-Hard? |
|np-complete| |
I am building a program that uses branching-and-bounding to find an optimal path in a complete graph (the heuristic, faster algorithm is the second part). I have to begin and end at node 0. I was given a large hint that eliminating "hopeless" branches early in the algorithm will lead to an overall much faster runtime. ... |
Inferences about Branching in TSP algorithm |
|optimization|graph-traversal| |
The (very) simplified version is that they convert any verification algorithm $A$ for a language $L \in \text{NP}$ into a circuit.
What they end up with is a circuit $C$ that, given a (binary) string $x$ is satisfiable (i.e. $C(x)=1$) if and only if $x \in L$ (i.e. there exists a certificate $y$ such that $A(x,y) = ... |
I am building a program that uses branching-and-bounding to find an optimal path in a complete graph (the heuristic, faster algorithm is the second part). I have to begin and end at node 0. I was given a large hint that eliminating "hopeless" branches early in the algorithm will lead to an overall much faster runtime. ... |
[Integer linear programming](http://en.wikipedia.org/wiki/Linear_programming#Integral_linear_programs) (ILP) is an incredibly powerful tool in combinatorial optimization. If we can formulate some problem as an instance of an ILP then solvers are guaranteed to find the global optimum. However, enforcing integral solutio... |
null |
Like Joe, I'm assuming that you want to find all maximal cliques.
Assuming your representation can represent all graphs (and there's no reason to suspect otherwise), then there's certainly still possibly exponentially many maximal cliques as subgraph - as Joe suggested, this is a property of the graph, independent o... |
I will add an answer for different aspect: *How is an [ADT(Abstract Data Type)][1] different from an abstract type?*
An ADT has:
1. Storage of elements of the same type
2. Limited interface - operations for storing and retrieving elements from the data structure
3. Inner processing - automatic operations th... |
I am investigating a convex hull algorithm that involves sorting. In fact, its running time is limited by sorting, so it is $O(nlogn)$, where $n$ is the number of points on the plane.
That algorithm first sorts the points by x-coordinates. It then includes the first and last points in the convex hull. From there on,... |
How does sorting come into play with convex hull? |
|algorithms| |
null |
I think this questions exploits only a technicality. However, you can follow this path
1. The class of ${\sf P}$-complete languages is ${\sf P}$ without $\Sigma^*$ and $\emptyset$.
2. Show that there are two disjoint ${\sf P}$-complete languages |
I am investigating a convex hull algorithm that involves sorting. In fact, its running time is limited by sorting, so it is $O(n \log n)$, where $n$ is the number of points on the plane.
That algorithm first sorts the points by x-coordinates. It then includes the first and last points in the convex hull. From there ... |
|algorithms|computational-geometry| |
I was wondering if someone knew the origin of the client server model. Where does the term come from (paper, software application, book)? |
What is the origin of the client server model? |
|distributed-systems|history| |
The following exercise is difficult for me:
>Show that for each $k \in \mathbb{N}$ the question of existence of a $k$-clique within a graph lies in $\text{L}$.
>
>Hint: A $k$-clique denotes $k$ verteces within a graph that are all connected with each other.
>
>Annotation: if the question also considers $k$ as pa... |
Show that k-clique lies in L |
|complexity-theory|space-complexity| |
I want to be able to locate a substring in a string allowing for a specified number of mismatches, insertions and deletions - and at the same time know how many mismatches, insertions and deletions were used for any match.
Using brute force backtrack I can find the matches, but I cannot guarantee that the match was ... |
Fuzzy string matching algorithm with allowed events? |
|algorithms|strings|substrings| |
im looking for a proof of the fowling problem:
if L is deterministic context free and R is a regular languages, then LR is a deterministic context free language.
P.S. but RL may not be deterministic context free, foe example let L={wcw^R|w\in (a|b)*}, and R={a}*.
|
deterministic context free languages are closed under regular right product |
|formal-languages| |
I am m looking for a proof of the fowling problem:
> If $L$ is deterministic context-free and $R$ is a regular language, then $LR$ is a deterministic context-free language.
P.S. Notice that $RL$ may not be deterministic context-free, foe example let $L=\{wcw^R \mid w\in \{a,b\}^*\}$, and $R=\{a\}^*$.
|
Deterministic context-free languages are closed under regular right product |
|formal-languages|regular-languages|context-free| |
In my studies in computability I have come across the notion of the "machine", an abstract representation of a device that essentially computes. I have read about Turing Machines and Wolfram's binary cellular automata and I understand them.ie. the rules, states, colours, etc. and how they work. They begin in some state... |
How does an automaton actually "compute"? |
|computability|automata|cellular-automata| |
Here is an idea. You have to work out the details by your own.
Let $Q_R$ be the states of a DEA accepting $R$, and let $Q_L$ be the states of a deterministic PDA accepting $L$. You build now a new deterministic PDA $P$ that accepts $LR$ as follows:
The state space of $P$ is $Q'=Q_L\times \mathcal{P}(Q_R)$. If you... |
The input is what's initially written on the tape of the Turing machine. For cellular automata, I suppose the input is the initial pattern of life and dead cells. Then the rules of the machine define what kind of function to compute on the input.
Since we assume that there are e.g. TM rules to compute any computabl... |
If you consider $k$ a constant, then k-clique can be solved be enumerating all $O(n^k)$ sets of vertices and checking that there are edges present in polynomial time (since the exponent is constant).
Enumerating k-Tuples of numbers up to n can be done in $k\log n$ space, you only have to figure out how to check for... |
Given an undirected Graph. I want to find a hamiltonian path with no restriction to starting or ending vertices. I know there are some smart algorithms for solving that.
Now let's make things interesting: sometimes, when I arrive at a vertex, the edges connected to that vertex change. I.e. some will be removed, othe... |
Hamiltonian path in dynamic graph |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.