instruction stringlengths 0 29.8k ⌀ |
|---|
Why S=1, R=1 Is forbidden in RS-Flip Flop |
|logic|circuits|sequential-circuit| |
In the original paper of A* algorithm, [*A Formal Basis for the Heuristic Determination of Minimum Cost Paths*][1], the author proved the optimality of A* in *Theorem 2*, page 105.
However, I cannot understand the proof. The assumption is that we have a node in G_s which is not expanded by algorithm A, but in the pr... |
Proof of the optimality of A* algorithm |
|algorithms|search-algorithms| |
In the original paper of A* algorithm, [*A Formal Basis for the Heuristic Determination of Minimum Cost Paths*][1], the author proved the optimality of A* in *Theorem 2*, page 105.
However, I cannot understand the proof. The assumption is that we have a node in $G_s$ which is not expanded by algorithm A, but in the ... |
There is a land divided to $D$ districts.
There are $C$ citizens.
We want to divide the land to the citizens, such that each citizen receives a single land-plot in a single district.
Each citizen prefers certain districts, however, the preference also depends on the size of plot. For example, Johnny prefers a ... |
Minimal-envy land division |
null |
I'm doing a self-study of [Game Theory Evolving by Gintis][1], and am stuck on problem 4.16 "Poker with Bluffing".
The first question asks "*Show that Ollie has 64 pure strategies and Stan has 8 pure strategies.*". But no matter how I try to approach this, I can't get more then 4 strategies for Stan!
Here is the ... |
Poker with Bluffing (game theory) |
|untagged| |
I have a tree whose vertices I want to label. The leaf nodes should be labeled one. Then, assume the leaves were removed. In the tree that remains, the leaves should be labeled two. This process continues in the obvious way until all vertices have a label. The reason I do this is I want to store the vertices in a queue... |
Linear time labeling algorithm for a tree? |
|algorithms|graph-theory|trees| |
[3-Partition][1] problem is $\mathsf{NP}$-Complete in a strong sense meaning there is no pseudo-polynomial time algorithm for it unless $\mathsf{P}=\mathsf{NP}$. I'm looking for the fastest known algorithm that solves 3-Partition. Is there a fast (e.g subexponential) algorithm for 3-Partition? Is it possible to solve i... |
Stan has two pure strategies for each type of card. Since there are three types of cards, in total he has $2\times 2\times 2 = 8$ strategies. Here is a list of them:
* Always stay.
* Always raise.
* Stay only if H.
* Stay only if M.
* Stay only if L.
* Raise only if H.
* Raise only if M.
* Raise only if L. |
Use DFS instead. Here is a sketch of the algorithm.
* Given a node $v$, if $v$ is a leaf, set $d(v) = 0$.
* If $v$ is not a leaf, run the algorithm on all its children, and then let $d(v) = 1 + \min d(u)$, where $u$ goes over the set of all children. |
Use DFS instead. Here is a sketch of the algorithm.
* Given a node $v$, if $v$ is a leaf, set $d(v) = 1$.
* If $v$ is not a leaf, run the algorithm on all its children, and then let $d(v) = 1 + \min d(u)$, where $u$ goes over the set of all children.
You run this algorithm on the root. |
null |
Starting with $i=0$ and going up, for every $f \in F$ consider a subset of $V$ containing points at the exact distance of $i$ from $f$. Look at intersection of all of those subsets. If you're lucky, as $i$ grows, you'll find this intersection non empty - those will be the solutions.
For the actual implementation, I'... |
null |
I am writing a program to store, retrieve and delete "blocks" of data of varying sizes.
The way it currently works is by keeping a database storing the locations of the blocks and the locations of free space in the file.
The file is split into pages such that in each page there are no two free chunk spaces next t... |
Random file access in a block based file format |
|databases| |
The gist of the problem, I think, is to properly define a partial order on regexps. Since the language accepted by them is potentially infinite, using cardinality seems very difficult.
However, the problem can be broken down to comparing accepted input at each step of the processing of the input string. The compari... |
null |
{"OriginalQuestionIds":[4800],"Voters":[{"Id":98,"DisplayName":"Raphael"}]} |
I am having trouble understanding a mapping reduction and I would appreciate your help. Define
$\quad \begin{align}
A_{TM} &= \{ \langle M, w \rangle \mid M \text{ Turing machine}, w \in \mathcal{L}(M)\} \\
S_{TM} &= \{ \langle M,w \rangle \mid M \text{ Turing machine}, w \in \mathcal{L}(M) \implies w^R \in \m... |
|algorithms|algorithm-analysis|search-algorithms|correctness-proof| |
While proving optimality of the A* algorithm, why can we change graphs? |
If the number of citizens is large enough, such that the effect of one citizen changing his/her selection is negligible, then an envy-free division is equal to a Nash equilibrium in a [congestion game](http://en.wikipedia.org/wiki/Congestion_game).
Specifically, [Igal Milchtaich's papers](http://faculty.biu.ac.il/~m... |
|game-theory|board-games| |
|algorithms|trees| |
|efficiency|databases|filesystems| |
Asymptotic analyses of the space needed to run algorithms. |
Questions about properties of, working with and algorithms on integers. |
Questions about relationships between complexity classes. |
Questions that ask for or about correctness proofs of algorithms. |
Use DFS instead. Here is a sketch of the algorithm.
* Given a node $v$, if $v$ is a leaf, set $d(v) = 1$.
* If $v$ is not a leaf, run the algorithm on all its children, and then let $d(v) = 1 + \max d(u)$, where $u$ goes over the set of all children.
You run this algorithm on the root. |
No, it isn't a problem.
The whole idea is that the algorithm doesn't operate on a single graph, but rather on a family of graphs (with costs), determined by what the algorithm knows from the heuristic and the explored nodes. That family is denoted by $G_{n,\theta}$ in the paper.
The admissibility of the heuristic... |
I have came across a wired experience in C Programming, Let me explain it, Here is the code.
int main(){
int array1[6] = {0, 1, 2, 3, 4, 5};
int array2[6] = {6, 7, 8, 9, 10, 11};
printf("%d\n", array1[-1]);
return 0;
}
When I compile & run this, I don't get any errors or warnings, As My le... |
Array Index in C programming |
|programming-languages|c| |
There are plenty of possibilities. Others have already mentioned automata which offer a rich selection. Consider the following frameworks, too:
1. Some languages can be defined directly by *(co)[inductive definitions](https://en.wikipedia.org/wiki/Inductive_definition)*. For instance, the smallest fixpoint of
$\... |
Arrays are simply laid out as contiguous chunks of memory. An array access such as a[i] is converted to an access to memory location _addressOf_(a)+i. This the code `a[-1]` is perfectly understandable, it simply refers to the address one before the start of the array.
This may seem crazy, but there are many reasons ... |
I have came across a weird experience in C programming. Consider this code:
int main(){
int array1[6] = {0, 1, 2, 3, 4, 5};
int array2[6] = {6, 7, 8, 9, 10, 11};
printf("%d\n", array1[-1]);
return 0;
}
When I compile and run this, I don't get any errors or warnings. As my ... |
Why do negative array indices make sense? |
|programming-languages|arrays| |
null |
The array indexing operation `a[i]` gains its meaning from the following features of C
(1) The syntax `a[i]` is equivalent to `*(a + i)`. Thus it is valid to say `5[a]` to get at the 5th element of `a`.
(2) Pointer-arithmetic says that given a pointer `p` and an integer `i`, `p + i` the pointer `p` advanced... |
In simple words:
All variables(including arrays) in C are stored in memory.
Let's say you have 14 bytes of "memory" and you initialize the following:
int a=0;
int array1[6] = {0, 1, 2, 3, 4, 5};
Also,consider the size of an int as 2 bytes.
Then,hypothetically, in the first 2 bytes of memory the inte... |
The array indexing operation `a[i]` gains its meaning from the following features of C
(1) The syntax `a[i]` is equivalent to `*(a + i)`. Thus it is valid to say `5[a]` to get at the 5th element of `a`.
(2) Pointer-arithmetic says that given a pointer `p` and an integer `i`, `p + i` the pointer `p` advanced... |
The array indexing operation `a[i]` gains its meaning from the following features of C
1. The syntax `a[i]` is equivalent to `*(a + i)`. Thus it is valid to say `5[a]` to get at the 5th element of `a`.
2. Pointer-arithmetic says that given a pointer `p` and an integer `i`, `p + i` the pointer `p` advanced b... |
C is not strongly typed. A standard C compiler wouldn't check array bounds. The other thing is that an array in C is nothing but a contiguous block of memory and indexing starts at 0 so an index of -1 is the location of whatever bit-pattern is before `a[0]`.
Other languages exploit negative indices in a nice way. I... |
As the other answers explain, this is [undefined behaviour][1] in C. Consider that C was defined (and is mostly used) as a "high level assembler". C's users value it for its uncompromising speed, and checking stuff at runtime is (mostly) out of the question for the sake of sheer performance. Some C constructs that _loo... |
I was wondering, since $a^*$ is itself a star-free language, is there a regular language that is not a star-free language? Could you give an example?
---
_(from [wikipdia](http://en.wikipedia.org/wiki/Star-free_language#cite_ref-Law235_1-0))_ Lawson defines star-free languages as:
>A regular language is said to be... |
[3-Partition][1] problem is $\mathsf{NP}$-Complete in a strong sense meaning there is no pseudo-polynomial time algorithm for it unless $\mathsf{P}=\mathsf{NP}$. I'm looking for the fastest known exact algorithm that solves 3-Partition. Is there a fast (e.g subexponential) algorithm for 3-Partition? Is it possible to s... |
I have came across a weird experience in C programming. Consider this code:
int main(){
int array1[6] = {0, 1, 2, 3, 4, 5};
int array2[6] = {6, 7, 8, 9, 10, 11};
printf("%d\n", array1[-1]);
return 0;
}
When I compile and run this, I don't get any errors or warnings. As my ... |
I have an undirected tree whose vertices I want to label. The leaf nodes should be labeled one. Then, assume the leaves were removed. In the tree that remains, the leaves should be labeled two. This process continues in the obvious way until all vertices have a label. The reason I do this is I want to store the vertice... |
Starting with $i=0$ and going up, for every $f \in F$ consider a subset of $V$ containing points at the exact distance of $i$ from $f$. Look at intersection of all of those subsets. If you're lucky, as $i$ grows, you'll find this intersection non empty - those will be the solutions.
For the actual implementation, I'... |
You can give an explicit condition for whether an edge should be in the MST. Consider edge between x and y with weight w. Remove all edges with weights greater than or equal to w. Are x and y still connected? If so, edge e should not be in the MST, otherwise it should.
This isn't qualitatively different to previous ... |
null |
**Disclaimer**: _The following algorithm does not use the standard model for sublinear space complexity (see [WP:DSPACE][1]), because it writes to the input tape. Furthermore the set of (Watson-Crick) palindromes is not in $\mathsf{DSPACE}(\mathcal{O}(1)) = \mathsf{REG}$. Nevertheless, it's an in-place solution for man... |
null |
Use DFS instead. Here is a sketch of the algorithm.
* Given a node $v$, if $v$ is a leaf, set $d(v) = 1$.
* If $v$ is not a leaf, run the algorithm on all its children, and then let $d(v) = 1 + \max d(u)$, where $u$ goes over the set of all children.
You run this algorithm on the root.
Edit: This algorithm as... |
I am supposed to write a Context free grammar that generates the language:
L(G) = {0^(3n)1^(2n)0^(m)1^(m) : n >= 1, m >= 1}
I have the rules:
S -> 000S
S -> S11T
T -> 0T
T -> T1
This looks correct in terms of the structure of the grammar but I am not sure how to denote how to tell the... |
How to write Context Free Grammar with numerical restrictions |
|context-free|formal-grammars| |
I am supposed to write a Context free grammar that generates the language:
$L(G) = $ {$0^{3n}$$1^{2n}$$0^{m}$$1^{m}$ : n $\ge$ 1, m $\ge$ 1}
I have the rules:
S -> 000S
S -> S11T
T -> 0T
T -> T1
This looks correct in terms of the structure of the grammar but I am not sure how to denote ho... |
null |
Edit: I just noticed while reading the FAQ that undergrad-level questions are not supposed to go here. I tried deleting the question, but it won't let me.
This question is something I've been pondering as a self-made prep question for a final I have coming up in 2 weeks.
I want to know if the following problem is... |
Can a Turing Machine decide if an NFA accepts a string of prime length? |
|formal-languages| |
Notice that $L(G)=\{(000)^n(11)^n0^m1^m\}$.
Hint: find a grammar for $\{0^n1^n\}$ |
First off, your grammar isn't quite right, since there's no way to eliminate $S$; every production with $S$ on the LHS produces a string including $S$, so your grammar generates no (finite) strings at all.
To capture the "greater than or equal to 1" requirement, you should have a rule that produces the smallest perm... |
I am supposed to write a Context free grammar that generates the language:
$L(G) = $ {$0^{3n}$$1^{2n}$$0^{m}$$1^{m}$ : n $\ge$ 1, m $\ge$ 1}
I have the rules:
$$S \rightarrow 000S$$
$$S \rightarrow S11T$$
$$T \rightarrow 0T$$
$$T \rightarrow T1$$
This looks correct in terms of the structure of the gramma... |
First off, your grammar isn't quite right, since there's no way to eliminate $S$; every production with $S$ on the LHS produces a string including $S$, so your grammar generates no (finite) strings at all.
To capture the "greater than or equal to 1" requirement, you should have a rule that produces the smallest perm... |
|programming-languages|arrays|c| |
null |
null |
The lengths of the strings accepted by a DFA form a semilinear set (like in [Parikh's theorem][1] for context free languages), the description of those isn't too hard to come by (essentially splice up all possible cycles of the automaton), and by [Dirichlet's theorem][2] any arithmetic progression of the form $a + b k$... |
Unrooted Trees
---
BFS can be used to compute shortest distance from a *single* vertex. In your case, you want to find shortest distance from the set of leaves. Therefore, you do the following:
* Used BFS or DFS to identify the set $L$ of all leaves.
* Add to the graph a new vertex $\lambda$, and connect it to ... |
I have two regular languages *A* and *B*, and I want to determine whether there is any pair of strings, *a* in *A* and *b* in *B*, such that (*a* *b*) is a prefix of a string in (*A* *B*) and the left-most match of *B* in (*a* *b*) includes one or more characters from *a*.
Example
==
For example, ... |
For regular languages A and B, determine whether B might match early in (A B) |
|formal-languages|parsers| |
Assume DFAs given, it is easier. And get rid of useless states, and kill off any dead states.
To get a DFA for the language of all prefixes of $A$ is easy: Make all states final.
Then you can compute the intersection between that and $B$, and you have the set of $B$s that are prefixes of $A$s.
No idea what it ... |
I have an undirected tree whose vertices I want to label. The leaf nodes should be labeled one. Then, assume the leaves were removed. In the tree that remains, the leaves should be labeled two. This process continues in the obvious way until all vertices have a label. The reason I do this is I want to store the vertice... |
I have two regular languages *A* and *B*, and I want to determine whether there is any pair of strings, *a* in *A* and *b* in *B*, such that (*a* *b*) is a prefix of a string in (*A* *B*) and the left-most match of *B* in (*a* *b*) includes one or more characters from *a*.
I think this is equivalent (... |
I want to know if the following problem is decidable:
Instance: An NFA A with n states
Question: Does there exist some prime number p such that A accepts some string of length p.
My belief is that this problem is undecidable, but I can't prove it. The decider can easily have an algorithm to figure out if a par... |
|formal-languages|turing-machines| |
Unrooted Trees
---
You can use a priority queue to solve this in $O(E+V\log V)$:
* Put all vertices in a priority queue, with their priority being their degree.
* While the queue is non-empty:
* Remove a vertex $v$ of minimal priority, which must be $1$ (or $0$ at the very end).
* Let $\sigma(v) = 1 + \max ... |
null |
DFA intersection is a solved problem - given two DFAs (or NFAs, or regular grammars), we can come up with a DFA for the intersection of the two languages accepted by these DFAs. Also, it is known how to check whether the language accepted by a DFA is empty or not. Other closure properties are listed in the [Wikipedia a... |
It is extremely likely that the classical [time-space tradeoff for palindromes][1] holds also in your case. This result states that a Turing machine recognizing palindromes in space $S$ must take time $\Omega(n^2/S)$, i.e.
$$ \textrm{Time} \times \textrm{Space} = \Omega(n^2). $$
In your case, the first algorithm has ... |
I have two regular languages *A* and *B*, and I want to determine whether there is any pair of strings, *a* in *A* and *b* in *B*, such that (*a* *b*) is a prefix of a string in (*A* *B*) and the left-most match of *B* in (*a* *b*) includes one or more characters from *a*.
I think this is equivalent t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.