instruction stringlengths 0 29.8k ⌀ |
|---|
> When it is compiled, the while clause will generate multiple instructions which it seems to me can lead to a race condition in a pre-emptive scheduling model.
This is the technical beauty of Peterson's algorithm. Even though there could be many possible execution paths for this short and simple-looking code, it gu... |
I have seen this C code showing an implentation of Peterson's Critical Section algorithm. It is obviously skeletal and hardwired for two threads but the logic is supposed to be correct in detail.
[![Peterson's algorithm in pseudocode][1]][1]
Despite reading and talking I remain with a grain of doubt about the fol... |
Race condition, my doubt on Peterson's algorithm vs. C |
|algorithms|operating-systems|threads|critical-section| |
Can we have an algorithm that takes some input and does something random to it (in such a way that the algorithm does terminate) which does not have a worst-case running time upper-bound?
A (non-)example which shows what I mean: If let's say that my algorithm is one that takes an input number, generates a random num... |
Can a program that terminates have a running time of infinity? (Or not have an upper bound) |
|time-complexity|asymptotics|runtime-analysis|randomized-algorithms|infinity| |
Can we have an algorithm that takes some input and does something random to it (in such a way that the algorithm does terminate) which does not have a worst-case running time upper-bound?
A (non-)example which shows what I mean: If let's say that my algorithm is one that takes an input number, generates a random num... |
This is the given question-
**Construct a dfa over the alphabet {0,1} such that it accepts all strings containing
even number of 0's ***OR*** the number of 1's divisible by 3.
**
The very first problem I've encountered was the 'or' mentioned in the question. Does this mean i just '+' the RegEx for -'accepts ... |
Constructing a deterministic finite automata from a very convoluted RegEx |
|automata|finite-automata| |
This is the given question-
**Construct a dfa over the alphabet {0,1} such that it accepts all strings containing
even number of 0's ***OR*** the number of 1's divisible by 3.**
The very first problem I've encountered was the 'or' mentioned in the question. Does this mean i just '+' the RegEx for -'accepts all... |
This is the given question-
**Construct a dfa over the alphabet {0,1} such that it accepts all strings containing
even number of 0's ***OR*** the number of 1's divisible by 3.**
The very first problem I've encountered was the 'or' mentioned in the question. Does this mean i just '+' the RegEx for -'accepts all... |
This is the given question-
**Construct a dfa over the alphabet {0,1} such that it accepts all strings containing
even number of 0's ***OR*** the number of 1's divisible by 3.**
The very first problem I've encountered was the 'or' mentioned in the question. Does this mean i just '+' the RegEx for -'accepts all... |
null |
Ok, so first and foremost:
If some number X appears multiple times in A, we can calculate the answer for X once and just check the precalculated answer.
So basically, now we have 10^6 distinct numbers. AKA, 1,2,3...10^6.
Good! So we just have to calculate the answer for all numbers between 1 and 10^6.
The secon... |
null |
It is a detour to construct the automaton by first determining a regular expression.
The description of the languages gives enough information to obtain possible states for the automaton.
To check whether the number of $0$'s is even we count modulo two.
To check divisibility by three of the number of $1$'s we need... |
LTL.
PS The very book you mention has a historical note section discussing various other temporal logics near page 271.
**Edit (leaving the above intact for the comments to make sense):** None of the named logics in the wikipedia article (at the time of writing this) is the same as/equivalent to Manna and Pnueli'... |
[Update March2023 - non-wikipedia links are broken]
The second (in magnitude) eigenvalue controls the rate of convergence of the random walk on the graph. This is explained in many lecture notes, for example [lecture notes of Luca Trevisan](https://people.eecs.berkeley.edu/~luca/cs278-08/lecture11.pdf). Roughly spea... |
null |
The second (in magnitude) eigenvalue controls the rate of convergence of the random walk on the graph. This is explained in many lecture notes, for example [lecture notes of Luca Trevisan](https://web.archive.org/web/20170829012125/https://people.eecs.berkeley.edu/~luca/cs278-08/lecture11.pdf). Roughly speaking, the L2... |
Michael Sipser's Introduction to Theory of Computation:
[![Book screenshot][1]][1]
Is there a typo in the highlighted line? I ask that because near the beginning it says that R is a set of states of N, and that R itself is a state of M.
It also says that E(R) is 'the collection of states that can be reached from... |
Does Mike Sipser's book on Theory of Computation cover Moore and Mealy machines? |
|finite-automata|computation-models|nondeterminism| |
Is there a typo in this excerpt from the book? |
From 6.3.2 of Aho *et al.*
> When type expressions are represented by graphs, two types are
> structurally equivalent if and only if one of the following conditions
> is true:
> - They are the same basic type.
> - They are formed by applying the same constructor to structurally equivalent types.
> - One is a ty... |
Is order important in Structural Equivalence? |
|compilers|types| |
To clarify, I think they meant that
$$E(R)=\{q|\exists s\in R, q\text{ can be reached from $s$ by $0$ or more $\epsilon$ transitions}\}$$
|
Consider two binary search trees T1 and T2, each with height h, with all values in T1 less than all values in T2. I want to merge these both trees to get a new binary search tree of height at most h+1
**My Thoughts:**
The first thought was to put T1 as the left child of the leftmost node in T2. But the resu... |
Merge two binary search trees |
|binary-search-trees| |
Take the smallest element from $T_2$ (it will be the left-most leaf) and call it $r$.
Make the new tree such that $r$ is the root, $T_1$ is the left-child of $r$ and $T_2$ (with $r$ removed) is the right-child of $r$ |
The given grammar has a direct and an indirect recursion. There is no rule to solve this or such which mentions whether any production is to be changed or not. However one way to keep things clear would be to consider one rule at a time for removing left recursion, which in your case would be as follows
$$S\rightarrow... |
Take the smallest element from $T_2$ (it will be the left-most leaf) and call it $r$. Note that you may have to "fix" $r$'s right child by putting it in place of where $r$ was.
Make the new tree such that $r$ is the root, $T_1$ is the left-child of $r$ and $T_2$ (with $r$ removed) is the right-child of $r$ |
null |
null |
null |
null |
Consider two red-black trees T1 and T2, each with black-height h, with all values in T1 less than all values in T2. How to merge these two trees to obtain a red-black tree in O(h). The root is always considered black in the red-black tree |
Merge two red black trees with the same black height |
|balanced-search-trees|red-black-trees| |
null |
null |
Sure. Consider the following algorithm: flip a fair coin; if it is heads, terminate; if it is tails, go back to the beginning and repeat. There is no upper limit to the amount of time this algorithm could take. |
null |
Consider a DAG such as one shown below:
[![enter image description here][1]][1]
How do I find a particular topological order of nodes, such that when the nodes are placed in a straight line, the total lengths of the edges is minimal. Or in other words (not sure if it is equivalent), the total number of times edge... |
Topological sort of DAG that minimizes the total edge length when the nodes are placed in a straight line at a fixed distance |
|weighted-graphs|dag|topological-ordering| |
Consider a DAG such as one shown below:
[![enter image description here][1]][1]
How do I find a particular topological order of nodes, such that when the nodes are placed in a straight line, the total lengths of the edges is minimal. Or in other words (not sure if it is equivalent), the total number of times edge... |
|graphs|weighted-graphs|dag|topological-ordering| |
Consider a DAG such as one shown below:
[![enter image description here][1]][1]
How do I find a particular topological order of nodes, such that when the nodes are placed in a straight line, the total lengths of the edges is minimal. Or in other words (not sure if it is equivalent), the total number of times edge... |
Constructing a deterministic finite automaton from a very convoluted RegEx |
Super late to this party, but Phylliida is correct. This is an NP-hard problem so there is no "efficient" solution, and the proposal is known as "simulated annealing" which is the best you are going to get.
Look up wedding seating for a bunch of articles on why it is NP complete.
-- Henry |
Since you allow inputs, you can imagine a program that inputs a natural number $n$ and then performs $n$ steps. No further randomness is required.
More interesting is the case without inputs. If you want an input-less, terminating program with unbounded executions then you require a source of (countably) infinite ra... |
null |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could have equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc(since $w, x,y, z\geq 0.$). So the grammar will be only this equal case:
$S\to aSd. $
$X\to aXc. $
$Y\to bY... |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could have equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc(since $w, x,y, z\geq 0.$). So the grammar will be only this equal case:
$S\to aSd. $
$X\to aXc. $
$Y\to bY... |
null |
Your language is NCFL. Your design of NPDA is perfectly right. And in state $q_0,q_1$ and $q_2$ transitions makes your diagram NPDA. You accepts your strings by final state that is $q_3.$ If you want to accept by empty stack(without final state) then no need to move and create the new state $q_3.$ You just give the tr... |
Consider the alphabet $\Sigma = \Sigma_c \cup \Sigma_i \cup \Sigma_r$ separated into call, internal, and return letters. Assume that $c \in \Sigma_c, r \in \Sigma_c$, and $a \in \Sigma_i$.
I have a question regarding whether the language:
$L = c^n a c^* a r^n$ is accepted by some Visibly Pushdown Automaton or not. $... |
Is the following language recognizable by a visibly pushdown automata? |
|formal-languages|automata|pushdown-automata| |
null |
A type constructor is a way to build a type from other types (possibly zero other types), in the same way that a value constructor is a way to build a value from (possibly 0) other values. Constructors are usually identified by a name. The details can vary between programming languages; in my examples I'll use a syntax... |
The N-Queens in question is referring to the one where it is interested in finding all solutions for some natural number n. I just read about the idea of a verifier being an algorithm that verifies whether it accepts an input and a "certificate".
So say for example that I want to check some configuration of n queen... |
Why is there no polynomial time verifier for N Queens |
|algorithms|np-hard| |
Consider a DAG such as one shown below:
[![enter image description here][1]][1]
How do I find a particular topological order of nodes, such that when the nodes are placed in a straight line, the maximum number of unique-edges that cross through any node is minimized. Unique edges are edges that originate from uni... |
Topological sort of DAG that minimizes maximum number of unique-source-edges crossing through any node when placed in 1-d line |
null |
null |
You're not missing anything. Verifying that a candidate solution is valid (i.e., that no queen attacks any other) can be done in polynomial time.
Finding a solution might take more than polynomial time (I don't know). Also, checking whether $n$ is the smallest possible value such that you can place $n$ queens in a... |
null |
The most widely used notion of equivalence of regular expressions
$r_1$ and $r_2$, or finite status automata ${A}_1$ and ${A}_2$ resp., over an alphabet $\Sigma$, is to consider their languages: we can define
$$r_1 \cong r_2
\qquad\text{iff}\qquad
\mathsf{language}(r_1) = \mathsf{language}(r_2)
$$
and likew... |
Reference request about equivalence of automata / regular expressions up-to a language |
|formal-languages|regular-languages|automata|reference-request|regular-expressions| |
The most widely used notion of equivalence of regular expressions
$r_1$ and $r_2$, or finite status automata ${A}_1$ and ${A}_2$ resp., over an alphabet $\Sigma$, is to consider their languages: we can define
$$r_1 \cong r_2
\qquad\text{iff}\qquad
\mathsf{language}(r_1) = \mathsf{language}(r_2)
$$
and likew... |
Problem: Given an integer n >= 1, is there a way to put n queens on an n by n chessboard so that none attacks another one?
The algorithm “return “yes” if and only if n != 2 and n != 3” may be correct and runs in O(1). Assume this is not true or not provable.
I’m unsure if an actual solution can be found in polyn... |
null |
The most widely used notion of equivalence of regular expressions
$r_1$ and $r_2$, or finite state automata ${A}_1$ and ${A}_2$ resp., over an alphabet $\Sigma$, is to consider their languages: we can define
$$r_1 \cong r_2
\qquad\text{iff}\qquad
\mathsf{language}(r_1) = \mathsf{language}(r_2)
$$
and likewi... |
There is actually a very simple answer: Measure. If you cannot measure the difference between different load factors then the whole question is pointless.
The actual optimal load factor depends on the cost of calculating hash values, cost of comparing items with same hash value, performance cost of having a larger ... |
This idea blows my mind, I would appreciate for any guidance. In essence, the question is how a machine should work to transform any kind of formal logic into its graphical representation (e.g. conceptual graph)? And moreover, from graphs into linear form.
I have heard about ISO standard for Common Logic framework. ... |
How to make a GUI for first-order logic representation? |
|logic|python|knowledge-representation| |
I have a problem to solve, but I am having some issues with it...
Find an algorithm with time complexity O(V+E), where V and E stand for vertices and edges respectively. The algorithm searches a tree graph for a subgraph. The subgraph is supposed to be the so called centipede graph, i.e. a path with "legs" or "hair"... |
Find the largest centipede subtree |
|algorithms|graphs|trees|search-algorithms|graph-traversal| |
I've read that in general for a modal formula P, a world w and a Kripke frame ⟨W,R⟩
w⊨□P if and only if for every u∈W, if wRu then u⊢P
In case of LTL, being a modal logic, I assumed that the worlds are different moments in time and the relation R is the chain of "arrows" between those moments. However, in this ca... |
What is the Kripke semantic for a linear temporal logic? |
|logic|linear-temporal-logic|temporal-logic|modal-logic| |
In LTL, you don't have $\diamond$ and $\Box$, but you have $X$ and $U$, meaning _next_ and _until_, respectively.
In LTL, every world has a unique successor.
Next is defined as $w \models X \phi$ if $w' \models \phi$, where $w'$ is the successor of $w$.
Until is defined as follows: $w \models \phi U \psi$ if t... |
null |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to freeze the game.), but does not allow parameters (i.e. running "`alias d... |
|automata|finite-automata| |
null |
Recently, I’ve been interested in the console of the Source game engine, more specifically, its `alias` command, which allows one command to invoke others. It may allow recursion (i.e. running `alias freeze freeze` will cause inputting `freeze` to freeze the engine), but does not allow parameters (i.e. running "`alias ... |
This idea blows my mind, I would appreciate for any guidance. In essence, the question is how a machine should work to transform any kind of formal logic into its graphical representation (e.g. conceptual graph)? And moreover, from graphs into linear form.
I have heard about ISO standard for Common Logic framework. ... |
Put all the primes in a sieve, ignoring duplicates. O(n), giving about n / ln n primes.
Put all the numbers in a sieve, counting multiplicity. O(n).
Take each prime in turn, count all multiples and how often they are present, then remove the multiples. The time is n / p, summed over the primes from 1 to n. I th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.