instruction
stringlengths
0
29.8k
⌀
Ok so I'm learning in my Theory of Computation course and understand the basic FSM but can't wrap my head around this question: The AC should only turn on if a person is detected in the room and the temperature is hot (80 degrees or higher). It turns off when no one is detected in the room, the window is open, or the...
How would I design a State Diagram (FSM) for a AC unit?
|regular-languages|finite-automata|regular-expressions|
Ok so I'm learning Finite Automata in my Theory of Computation course and understand the basic FSM but can't wrap my head around this question: The AC should only turn on if a person is detected in the room and the temperature is hot (80 degrees or higher). It turns off when no one is detected in the room, the window...
AYun's right. I was confused by the "trivial" instances in P because there is no mapping from SAT to an all-yes problem. Here is original Answer: $NPC\subset NP$, that's your possible mistake. Do not use **equal**, because they are not equal at all.
If P=NP, are all P problems NP-complete?
null
null
You are reading it correctly. Those are two different uses of the word "cluster graph". In graph theory, and usually in computer science, when you refer to a _cluster graph_ it is of the latter kind. For graph classes, the holy scripture is `graphclasses.org`, in which you can find [Graphclass: cluster](https://...
How to analyze the amortized running time of an indexed linked list operations using potential method
I'm looking for an algorithm that finds a simple path from S to T in a directed graph (which might have cycles) so that the product of edge weights in the path is maximum. All the edge weights of the graph are larger than zero. For any pair of nodes, there might be more than 1 edge. I thought of the following approa...
Find a simple path from S to T in a directed graph so that the product of its weights is maximum
|graphs|shortest-path|directed-graphs|
The problem is NP-hard by a reduction from the Hamiltonian-path problem. If all edge weights are set to some constant $c>1$ and $P$ is a simple path from $s$ to $t$ that maximizes the product of the edge weights, you have that the number of edges in $P$ is $n-1$ (where $n$ is the number of vertices of the graph) if ...
Your question's answer could be solve by Finite Automata with output that is Moore Machine or Mealy Machine. You have three cases: $Case:1$ When temperature is equal or more than $80°$ then output is $1$(Turn on). $Case:2$ When temperature is less than $32°$ then output is $0$(Turn off). $Case:3$ When te...
$L = \{a^nb^m | n \le m \le 3n \} $ This is by far the hardest pushdown automaton I had to design. I literally have no idea where to start. Here's my thought process. Firstly, I thought that for each valid pair $(n,m)$ the differences between the number of $b$s abd $a$s will be the same. That wasn't true, as the num...
Design a Pushdown automaton for $L = \{a^nb^m | n \le m \le 3n \} $
|formal-languages|automata|pushdown-automata|stacks|
Your question's answer could be solve by Finite Automata with output that is Moore Machine or Mealy Machine. You have three cases: $Case:1$ When temperature is equal or more than $80°$ then output is $1$(Turn on). $Case:2$ When temperature is less than $32°$ then output is $0$(Turn off). $Case:3$ When te...
null
How to analyze the amortized running time of indexed linked list operations using potential method
First of all your language is CFL means NCFL not DCFL because here has push and pop confusion. Therefore DPDA design is not possible. Only NPDA has power to accept your language. You have to understand what is grammar for your language. Suppose $n=0,$ then $m=0$ and string becomes $\epsilon.$ So your language conta...
A bipartite graph corresponds to a rectangle of ones in the adjacency matrix of this graph. Having a sparse graph, I would like to find the largest approximated bipartite graph. approximated means that some edges not in the sparse graph will be in the bipartite graph. I think this problem can be reformulated ...
How can I find the largest bipartite graph?
|approximation|bipartite-graph|
I reached a subproblem where I have an array of numbers (0 to n) un-sorted and I want to retrieve, for each element, the index of the farthest value from it **to the RIGHT** of that element. Like ``` 0 1 2 3 4 5 6 7 8 (indexes) 0 3 7 5 4 2 8 1 6 ``` so the answer would be ``` 6 6 7 7 7 6 7 8 -1 ``` Can anyo...
Retreive farthest value to the right of element
|c++|
I reached a subproblem where I have an array of numbers (0 to n) un-sorted and I want to retrieve, for each element, the index of the farthest value from it **to the RIGHT** of that element. Like ``` 0 1 2 3 4 5 6 7 8 (indexes) 0 3 7 5 4 2 8 1 6 ``` so the answer would be ``` 6 6 7 7 6 6 7 8 -1 ``` Can anyo...
First of all your language is CFL means NCFL not DCFL because machine has push confusion. Therefore DPDA design is not possible. Only NPDA has power to accept your language. You have to understand what is grammar for your language. Suppose $n=0,$ then $m=0$ and string becomes $\epsilon.$ So your language contain $...
First of all your language is CFL means NCFL not DCFL because machine has push confusion. Therefore DPDA design is not possible. Only NPDA has power to accept your language. You have to understand what is grammar for your language. Suppose $n=0,$ then $m=0$ and string becomes $\epsilon.$ So your language contain $...
[Splaying trees][1] are a heavily researched of theoretical computer science as they are conjectured to be optimal binary trees. They were first presented by Sleator & Tarjan in [Self-Adjusting Binary Search Trees][2]. In their paper, on pages 19-20, they propose to reduce the number of operations needed for a splay, b...
Implementation of join and split operations on semisplaying tree
|binary-trees|search-trees|splay-trees|
I reached a subproblem where I have an array of numbers (0 to n) un-sorted and I want to retrieve, for each element, the index of the farthest value from it **to the RIGHT** of that element. Like ``` 0 1 2 3 4 5 6 7 8 (indexes) 0 3 7 5 4 2 8 1 6 (array) ``` so the answer would be ``` 6 6 7 7 6 6 7 8 -1 ``` ...
|algorithms|c++|
Based on your sample, I would assume that farthest from $x$, means the value $y$ on the right of $x$ that maximizes $|x-y|$. And that's what I am using in my answer. Observe that the farthest value is either the lowest or highest value among the elements on the right of $x$. Let $min$ and $max$ be the inidices of...
I figured out that the maximum difference can only be found at the minimum or maximum value to the right of concerned value. So, I start from end of the array in reverse order and keep track of max and min upto the traversed part (k to n-1) Now, at each iteration, max(ele-min, max-ele) would be the answer for the...
Based on your sample, I would assume that farthest from $x$, means the value $y$ on the right of $x$ that maximizes $|x-y|$. And that's what I am using in my answer. Observe that the farthest value is either the lowest or highest value among the elements on the right of $x$. Let $min$ and $max$ be the inidices of...
Why not try to take logarithm of every edge's weight? $$ \min \prod_{i}p_i\iff \min \sum_{i}\log p_i,\,p_i>0 $$ But $\log p_i$ might give a negative cycle(e.g. every edge's weight < 1). In shortest path problem, negative cycle is undefined, but for this certain problem, we can simply ignore it with applying an ...
How to analyze the amortized running time of indexed linked list operations using potential method?
Why not try to take logarithm of every edge's weight? $$ \min \prod_{i}p_i\iff \min \sum_{i}\log p_i,\,p_i>0 $$ But $\log p_i$ might give a negative cycle(e.g. every edge's weight < 1). Now it becomes another problem: simple-path, and [this](https://cstheory.stackexchange.com/questions/17462/finding-the-shortes...
{"Voters":[{"Id":151342,"DisplayName":"LighT"}]}
[Cross-posted on cs-theory-stackexchange.][1] [Splaying trees][2] are a heavily researched of theoretical computer science as they are conjectured to be optimal binary trees. They were first presented by Sleator & Tarjan in [Self-Adjusting Binary Search Trees][3]. In their paper, on pages 19-20, they propose to redu...
A degenerate polygon is one that has zero area. The answer chosen above does not fully define a degenerate polygon. Consider the case of a square with two identical vertices. This could be defined as one or two non-degenerate triangles.
[Splaying trees][2] are a heavily researched of theoretical computer science as they are conjectured to be optimal binary trees. They were first presented by Sleator & Tarjan in [Self-Adjusting Binary Search Trees][3]. In their paper, on pages 19-20, they propose to reduce the number of operations needed for a splay, b...
null
This algorithm solves the [Two-Sum problem](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/)$^1$ assuming that the input array/list is sorted. ```python class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: N = len(nums) l, r = 0, N-1 while l < ...
Is the complexity of this two-sum binary search algorithm $O(\lg n)$ or $O((\lg n)^2)$?
|algorithms|time-complexity|runtime-analysis|python|
Unfortunately, the worst case of this algorithm is $\Theta(n\lg n)$, which is worse than $O(n)$, the time-complexity of the usual two-pointer algorithm that solves the same problem. ------ Consider the case with `nums = list(range(n))` and `target = 3*n//2`, where `n` is an even number. At the start of each ...
null
[Splaying trees][2] are a heavily researched of theoretical computer science as they are conjectured to be optimal binary trees. They were first presented by Sleator & Tarjan in [Self-Adjusting Binary Search Trees][3]. In their paper, on pages 19-20, they propose to reduce the number of operations needed for a splay, b...
Efficient Implementation of join and split operations on semisplaying tree
|data-structures|binary-trees|search-trees|splay-trees|
Solving this problem will in the worst case require an exhaustive search with possibly exponential growth. We modifiy the problem slightly to reduce the search space. Given $X ≥ 2$, we call $X_1, X_2, ... , X_k$ an "exact factoring of $X$" if the $X_i$ are all distinct, greater than 1, and their product $P$ equals $...
Solving this problem will in the worst case require an exhaustive search with possibly exponential growth. We modifiy the problem slightly to reduce the search space. Given $X ≥ 2$, we call $X_1, X_2, ... , X_k$ an "exact factoring of $X$" if the $X_i$ are all distinct, greater than 1, and their product $P$ equals $...
>Is there an NFA with n states so that the DFA resulting from the standard conversion of the NFA to a DFA has at least $2^n - \alpha$ reachable states for some integer $\alpha \ge 1$? Let $N= (Q, \Sigma, \mu, q_0, F)$ be the NFA. Construct a DFA $M = (Q',\Sigma, \delta, q, F')$ as follows: $Q' = \mathcal{P}(Q), F' =...
an NFA whose corresponding DFA has at least $2^n - \alpha$ reachable states
|formal-languages|automata|finite-automata|
$L= \{ a^nb^m | n \le m \le 2n \}$ As you may recall, I posted a question a few hours ago about designing a PDA for a language similar to the one I have now. I have seen that the easiest way to construct it is to define a CFG for the language, and then transform it to non-deterministic PDA *which accepts strings by ...
Designing a PDA without using CFG -> PDA for the language $ \{ a^nb^m | n \le m \le 2n \}$
|automata|context-free|pushdown-automata|nondeterminism|
The language $L=\{ (u\#,v\#) \mid |u|=|2v|\}$ from your question is actually a two-dimensional language, that is a relation between two strings, each written on their own input tape. In that way the condition $|u|=|2v|$ is easy to check, even with a deterministic one-way (two-tape) automaton: when the head moves one c...
By "physical means", I mean, for example, using water pouring down tubes, or combining chemicals, etc. Basically, using some experiment in the physical world to perform some computation. I'll call this physical computation. As the simplest example, if I want to add the numbers 3 and 5, I could just pour 3mL into a ...
The class of problems that can be solved efficiently using physical means?
|complexity-theory|np-hard|computation-models|polynomial-time|physics|
Your design is perfectly right. And in state $q_0$ and $q_2$ transition makes your diagram NPDA. You accepts your strings by final state that is $q_3.$ If you want to accept by empty stack no need to move and create the new state $q_3.$ You just give the transition in $q_2$ $(\epsilon,A/\epsilon)$ that is $\delta(q_2,...
By "physical means", I mean, for example, using water pouring down tubes, or combining chemicals, etc. Basically, using some experiment in the physical world to perform some computation. I'll call this physical computation. As the simplest example, if I want to add the numbers 3 and 5, I could just pour 3mL into a ...
By "physical means", I mean, for example, using water pouring down tubes, or combining chemicals, etc. Basically, using some experiment in the physical world to perform some computation. I'll call this physical computation. As the simplest example, if I want to add the numbers 3 and 5, I could just pour 3mL into a ...
Your design is perfectly right. And in state $q_0,q_1$ and $q_2$ transition makes your diagram NPDA. You accepts your strings by final state that is $q_3.$ If you want to accept by empty stack no need to move and create the new state $q_3.$ You just give the transition in $q_2$ $(\epsilon,A/\epsilon)$ that is $\delta(...
null
Given two strings $S$ and $T$, how can I efficiently find the lowest common substring for arbitrary substrings of $S$ and $T$? Example $S = \text{'abaaba'}$ $T = \text{'caaaba'}$ $LCS(S[1:4],T[2:4])= LCS(\text{'baab'}, \text{'aab'}) = \text{'aab'}$
Efficiently find lower common substring of two substrings
|substrings|longest-common-substring|
It's not clear what "can be solved" actually means here. Let me explain with a real example. It is known that NP-hard problems can be solved on an analog computer in polynomial time. Suppose that you have a SAT problem in CNF with $m$ clauses and $n$ variables. Define $c_{i,v}$ to equal $1$ if variable $v$ app...
{"OriginalQuestionIds":[3381],"Voters":[{"Id":4287,"DisplayName":"Hendrik Jan"},{"Id":755,"DisplayName":"D.W."}]}
Your language is NCFL. Your design of NPDA is perfectly right. And in state $q_0,q_1$ and $q_2$ transition makes your diagram NPDA. You accepts your strings by final state that is $q_3.$ If you want to accept by empty stack no need to move and create the new state $q_3.$ You just give the transition $(\epsilon,A/\epsi...
Efficiently find lowest common substring of two substrings
No one knows. The [extended Church-Turing hypothesis](https://en.wikipedia.org/wiki/Church%E2%80%93Turing_thesis#Variations) is sometimes described as saying that the answer is Phys-P = BPP. This is a conjecture or hypothesis but it is not proven. The answer depends on the physics that underlies the universe. It is...
Your question's answer could be solved by Finite Automata with output that is Moore Machine or Mealy Machine. You have three cases: $Case:1$ When temperature is equal or more than $80°$ then output is $1$(Turn on) which is associated with state. $Case:2$ When temperature is less than $32°$ then output is $0$...
Efficiently find longest common substring of two substrings
Given two strings $S$ and $T$, how can I efficiently find the longest common substring for arbitrary substrings of $S$ and $T$? Example $S = \text{'abaaba'}$ $T = \text{'caaaba'}$ $LCS(S[1:4],T[2:4])= LCS(\text{'baab'}, \text{'aab'}) = \text{'aab'}$
It's not clear what "can be solved" actually means here. Let me explain with a real example. It is known that NP-hard problems can be solved on an analog computer in polynomial time. Suppose that you have a SAT problem in CNF with $m$ clauses and $n$ variables. Define $c_{i,v}$ to equal $1$ if variable $v$ app...
{"Voters":[{"Id":151342,"DisplayName":"LighT"}]}
Why not try to take logarithm of every edge's weight? $$ \min \prod_{i}p_i\iff \min \sum_{i}\log p_i,\,p_i>0 $$ But $\log p_i$ might give a negative cycle(e.g. every edge's weight < 1). Now it becomes another problem: simple-path, and [this](https://cstheory.stackexchange.com/questions/17462/finding-the-shortes...
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 no need to move and create the new state $q_3.$ You just give the transition $(\epsilon,A/\eps...
null
Given two strings $S$ and $T$, how can I efficiently find the longest common substring for arbitrary substrings of $S$ and $T$? Example: $S = \text{'abaaba'}$ $T = \text{'caaaba'}$ $LCS(S[1:4],T[2:4])= LCS(\text{'baab'}, \text{'aab'}) = \text{'aab'}$ I'm running the Ratcliff-Obershelp algorithm over th...
null
I think it can be done in O(N). WLOG, we assume the line is $x=0$, and the intersection set is non empty. We can rotate the point set if the line is not $x=0$. The intersection check can be done in O(n) so we can make such assumption. So we are going to find two point $(0,a)$ and $(0,b)$, such that $a$ is the max...
null
Your question's answer could be solved by Finite Automata with output that is Moore Machine or Mealy Machine. You have three cases: $Case:1$ When temperature is equal or more than $80°$ then output is $1$(Turn on) which is associated with state i.e.$(q_i, 1).$ $Case:2$ When temperature is less than $32°$ the...
Summary: Start with a minimum spanning Tree (MST). Then modify it slightly to a Hamiltonian circuit. #### Mini-step traversal of $(T,s)$ Let $T$ be a tree. **Definitions**: For two vertices $u$ and $v$, let $d(u,v)$ be the number of edges in the unique path from $u$ to $v$. A sequence $v_1, v_2, \cdo...
[Splaying trees][2] are a heavily researched of theoretical computer science as they are conjectured to be optimal binary trees. They were first presented by Sleator & Tarjan in [Self-Adjusting Binary Search Trees][3]. In their paper, on pages 19-20, they propose to reduce the number of operations needed for a splay, b...
The "classical" partition problem asks whether a given multiset $S$ of positive integers can be partitioned into two subsets $S_1$ and $S_2$ such that the sum of the numbers in $S_1$ equals the sum of the numbers in $S_2$. The problem is known to be NP-hard. I want to know if a similar problem is also NP-hard (I be...
Complexity of the partition problem with additional constraint
|optimization|np-hard|partitions|
Suppose that I have proof tree starting with some statement |- B in a sequent calculus, leading to two premises/leafs |- A. Is it always possible to transform such a proof tree into another proof tree, which only contains one leaf |- A only using standard rules of natural deduction? More schematically I want to per...
Elemination of duplicate premise