instruction
stringlengths
0
29.8k
⌀
For most of the time one can't make sweeping statements about operations between any non-regular language and any regular language. The intuitive reasoning is that regular languages are a very broad collection of languages. Every non-regular language is the subset of a regular language, and every non-regular language h...
null
As we all know, 3-SAT is NP-hard. Two of the less known results are that [Planar 3-SAT is NP-hard][1] and also a ['restricted' 3-SAT][2], where any literal appears in at most two clauses turns out to be NP-hard. My question is if there is any known result on what happens if we combine these two conditions? That is, ...
In the PROOF of LEMMA 2: > Now consider some admissible deciding run from $C_0$ in which process p takes no steps, and let u be the associated schedule. The protocol can become deciding without talking to p. This requires the protocol can tolerate one fault. In other words, if the protocol tolerates no f...
From what I see, your equation has the form $$A(1+a)^y+B(1+b)^y+C=0$$ where $a,b$ are small. Such a nonlinear equation cannot be solved analytically. To find an approximate solution, you can write $$0=A(1+a)^y+B(1+b)^y+C\approx A(1+ay)+B(1+by)+C$$ and solve for $y$. An even better approximation comes from $...
I'd like to implement pagination for an API. The elements are ordered by time but there can be multiple elements with the same timestamp. So there can be some duplication between the last elements of the previous page and the first elements of the next pages. So far the de-duplication is handled on the client side b...
Sending set of string in HTTP query string
|data-structures|sets|
From what I see, your equation has the form $$A(1+a)^y+B(1+b)^y+C=0$$ where $a,b$ are small. Such a nonlinear equation cannot be solved analytically. To find an approximate solution, you can write $$0=A(1+a)^y+B(1+b)^y+C\approx A(1+ay)+B(1+by)+C$$ and solve for $y$. An even better approximation comes from $...
As the title says, I'm trying to solve the question where: Input: A directed tree $T = (V, E)$. Output: The maximal subset $A \subseteq V$ of vertices such that there doesn't exist any two vertices $u, v \in A$ that have a directed path between of distance $2$ or less. I thought of starting to append all of t...
Set of all vertices in a directed tree that are within distance of 2 or more from each other
|algorithms|graphs|trees|graph-traversal|
I am looking for all possible ways to find and eliminate ambiguity in CF grammar. Please share your knowledge or opinion (preferably you will indicate the literature so that I can familiarize myself).I know that it is impossible to check whether the grammar is ambiguous and there is no 100% solution, but I need to cons...
I found a grammar for this language. $S->caZac |cccc $. $Z->aZa | cc$ But if I try to use pumping lemma for context-free languages on $L$ with the word: $ca^ncca^nc$ I obtain it's not context-free. How is it possible?
Question about $L$ = { $ww$ | $w$ ∊ $ca^*c$}
|context-free|pumping-lemma|
I have just started to look into time and space complexity and it is all a mess for me atm, but this particular problem can be solved with converting the list of integers into a set, then comparing lenghts. Would that be linear in time? Sample function: ``` def same_diff(a_list): a_list.sort() temp_set = s...
Set of all vertices in a directed tree that are within distance of greater than 2
Set of all vertices in a directed tree that are within distance of strictly larger than 2
The pumping lemma is verified with a pumping length $n=6$. Indeed, let $ww\in L$, $|ww| \geqslant n$. Then $ww =ca^kcca^kc$ with $k\geqslant 1$. Then $ww = uvxyz$ with $u = ca^{k-1}$, $v = a$, $x=cc$, $y=a$ and $z=a^{k-1}c$, and: 1. $|vxy| = 4 \leqslant n$; 2. $|vy| = 2 > 0$; 3. for $i\geqslant 0$, $uv^ixyv^iz = ...
I am reading about algorithms to find the shortest path on a graph with one source, and I have a doubt about Dijkstra's algorithm about the negative weights on edges. In this case is Bellman-Ford algorithm a better solution for this part?
Dijkstra's shortest path algorithm
|shortest-path|dijkstras-algorithm|
This updated dialogue is complete and can be replicated in ChatGPT. ChatGPT confirms that the halt status criteria that I use in my rebuttal of the halting theorem is correct. olcott void D(void (*x)()) { int Halt_Status = H(x, x); if (Halt_Status) HERE: goto HERE; return...
null
null
In my class a student asked whether all finite automata could be drawn without crossing edges (it seems all my examples did). Of course the answer is negative, the obvious automaton for the language $\{\; x\in\{a,b\}^* \mid \#_a(x)+2\#_b(x) \equiv 0 \mod 5 \;\}$ has the structure of $K_5$, the complete graph on five no...
It isn't true that every DFA for this language is non-planar: [![Counterexample][1]][1][![diagram of the example][2]][2] Here is a language that is truly non-planar: $$ \left\{ x \in \{\sigma_1,\ldots,\sigma_6\}^* \middle| \sum_{i=1}^6 i\#_{\sigma_i}(x) \equiv 0 \pmod 7 \right\}. $$ Take any planar FSA for th...
This might be a a simple and for some a silly question as well. If I buy two hard drives and have windows in one and Ubuntu in the other, can I work with both two systems(one at a time). Example, I wanna edit a photo and I quickly need to go to Adobe Photoshop, so I plug in the Windows harddrive and start editin...
Does the OS come in the hard drive?
|memory-hardware|os-kernel|
This might be a a simple and for some a silly question as well. If I buy two hard drives and have windows in one and Ubuntu in the other, can I work with both two systems(one at a time). Example, I wanna edit a photo and I quickly need to go to Adobe Photoshop, so I plug in the Windows harddrive and start editin...
If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index
If an array is stored from lower region of memory to higher region, how'll the indexing formula look like?
|data-structures|
If an array is stored from higher region of memory to lower region, how'll the indexing formula look like?
If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index w = word length
If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index w = word length $$L<i<U$$
If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index w = word length $$L<i<U$$ $$A_i > A_{i+1}$$
If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index w = word length But for the case in question, we have: $$L<i<U$$ ...
Grammar for this language based on @Yuval Filmus's answer: $S \rightarrow X_{1}$| $X_{2}$|$X_{3}b \Sigma^{*}$|$X_{4}a \Sigma^{*}$ $X_{1} \rightarrow \Sigma X_{1} \Sigma$|$\Sigma^{+} c$ $X_{2} \rightarrow \Sigma X_{2} \Sigma$|$c \Sigma^{+}$ $X_{3} \rightarrow \Sigma X_{3} \Sigma$|$a \Sigma^{*} c$ $X_{4} \...
[![enter image description here][1]][1] If an array is stored from lower region of memory to higher region, we've this indexing formula. $$ Address (A[i]) = M+(i-L)*w$$ Where: M = memory location where first element is to be stored. L= Lower bound for index i = index w = word length But for the ...
We have an array of `n` measurements: `(m_0, m_1, ..., m_n-1)`. The measurements are voltages, but that's not important, so let's say they are just numbers. The measurements can be positive, negative or zero. There are no NaNs or infinites, only "regular" numbers. We are given a certain non-negative `threshold`. We ...
maximum span between two numbers
|maximum-subarray|
I think you can solve this problem in $O(n \log n)$ time. In a preliminary stage, repeat the following: - Set $g := n-1$. - Repeat while $g>0$: - Mark $m_g$ green. - Find the largest $j$ such that $m_j \ge m_g$ and $j<g$, and set $g := j$; or $g := -\infty$ if there is no such $j$. Collect all of the g...
I think you can solve this problem in $O(n \log n)$ time. In a preliminary stage, find the Pareto front, where a pair $(j,m_j)$ is better (dominates another pair) if $j$ is larger and $m_j$ is smaller. This can be done in $O(n \log n)$ time: see https://cs.stackexchange.com/q/108522/755, https://cs.stackexchange.c...
I think you can solve this problem in $O(n \log n)$ time. I'll list two solutions. Pareto optimality + binary search ================================= In a preliminary stage, find the Pareto front, where a pair $(j,m_j)$ is better (dominates another pair) if $j$ is larger and $m_j$ is smaller. This can be don...
We were given a question in class as follows: You have a "magic oracle" that can decide if a Turing Machine halts. You have three TMs $T_1, T_2, T_3$. Device an algorithm that decides if all TMs halt or not by asking the oracle at most twice. The sketch of the solution given was Construct a new TM $T_A$ that t...
Detecting if three Turing Machines halt given a magic oracle that is only used twice
|turing-machines|halting-problem|oracle-machines|
null
One way to built $T_A$ works is roughly as follows: While (true) { run $T_1$ for 10 steps, if $T_1$ halts during that time, $i := 1$, break; run $T_2$ for 10 steps, if $T_1$ halts during that time, $i := 2$, break; run $T_3$ for 10 steps, if $T_1$ halts during that time, $i := 3$, break; ...
We were given a question in class as follows: You have a "magic oracle" that can decide if a Turing Machine halts. You have three TMs $T_1, T_2, T_3$. Device an algorithm that decides if all TMs halt or not by asking the oracle at most twice. The sketch of the solution given was Construct a new TM $T_A$ that t...
If the array grows from a higher address to lower address, you need to subtract the offset from base address $$Address(A[i])=M-(i−L)∗w$$
A question is asked in the below link, which asks for the number of cases we can partition a multiset, where each part/segment in the partition has distinct elements. https://math.stackexchange.com/questions/4622246/how-many-ways-we-can-partition-a-multiset-where-each-part-segment-in-the-partit?noredirect=1#comment9...
Is there any upper bound for the number of ways we can partition a multiset, where each part/segment in the partition has distinct elements?
|combinatorics|discrete-mathematics|partitions|
|time-complexity|combinatorics|discrete-mathematics|partitions|
null
|turing-machines|undecidability|rice-theorem|
Here's a question in the OS textbook about calculating the cpu utilization. [![enter image description here][1]][1] [![enter image description here][2]][2] I've tried to write down the (A) by myself as below. (35+303)/((3+0.05)5 + (30+0.05)3) = 99.6xx% But I'm not sure if it is right. [1]: http...
A question about cpu utilization
|cpu|
null
Say there exists some optimal online algorithm $A$ that is better than any offline algorithm. We can create an offline algorithm $A'$ such that when $A'$ receives the input sequence, it will not perform any preprocessing; instead it will feed each request to $A$ one at a time. This offline algorithm must be optimal, gi...
null
In a sorting algorithm, While computing the complexity of an algorithm why do we only account for the number of comparisons done but not the number of swappings done?
Definition of complexity of an algorithm
|complexity-theory|
In a sorting algorithm, While computing the complexity of an algorithm why do we only account for the number of comparisons done but not the number of swappings done? And what's the formal definition of complexity?
If you have an online algorithm, you can always execute it offline by feeding the elements one at a time, and there's no loss of efficiency. So offline can beat online, and not conversely.
null
We know that the P language class is a polynomial-time solvable language class, and the NP language class can be determined in exponential time. And there exist some languages that can be decided only in exponential time and no polynomial time solution has been found yet, such as SAT language. My question is whether...
Whether the class of languages with time complexity between polynomial and exponential is an NP language?
|complexity-theory|time-complexity|turing-machines|np|
This problem is open. In fact, we cannot even rule out the stronger claim that NP = EXP. This is almost certainly false but proving it is beyond what current techniques can do.
null
This might be a a simple and for some a silly question as well. If I buy two hard drives and have windows in one and Ubuntu in the other, can I work with both two systems(one at a time). Example, I wanna edit a photo and I quickly need to go to Adobe Photoshop, so I plug in the Windows harddrive and start editin...
Yes, you could do that but it is rather awkward. Instead, you can use a [boot loader](https://en.m.wikipedia.org/wiki/Booting#Second-stage_boot_loader) which can load an operating system pass on the execution to it. Many issues and caveats on [multi-booting exist](https://en.m.wikipedia.org/wiki/Multi-booting). In a...
null
From the formula, $$ \text{Address} (A[L]) = M+(L-L)*w=M$$ and $$ \text{Address}(A[U]) = M+(U-L)*w$$ If $\text{Address} (A[L])>\text{Address} (A[U])$, you conclude that $w<0$.
Here is a simple algorithm that is based on your idea to reduce the capacity function. ------ Suppose the given flow network is directed graph $G=(V,E)$ with source $s$, sink $t$ and capacity function $c$. Let $\epsilon>0$ be a constant that is small enough. Consider a new capacity function $c^-$ that is $\ep...
null
null
(15 marks) Suppose a ray comes from a point (2, 8) and hits at mirror point (6, 6). Assume that perpendicular vector a point (6, 6) is ̅= (0, 3). Find the reflection emitting point from (6, 6). [Assume 2-D coordinate system, you must draw the appropriate diagram of your solution]
What is this question actually asking for me to solve?
|graphics|computer-graphics|
One way to built $T_A$ works is roughly as follows: While (true) { run $T_1$ for 10 steps, if $T_1$ halts during that time, $i := 1$, break; run $T_2$ for 10 steps, if $T_2$ halts during that time, $i := 2$, break; run $T_3$ for 10 steps, if $T_3$ halts during that time, $i := 3$, break; ...
null
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
I have a directed graph $G(V,A)$ with arc costs $c_{ij} = \alpha_{ij} +\beta_{ij}x_{ij}$, where $\alpha_{ij}$ and $\beta_{ij}$ are, respectively, a fixed cost and a cost per unit of flow pushed along arc $(i,j)$. I'd like to solve the [minimum-cost flow (MCF) problem][1] in this graph, i.e., given a supply/demand of $k...
Successive shortest paths with fixed costs and costs per unit
|graphs|shortest-path|correctness-proof|network-flow|
I have a directed graph $G(V,A)$ with arc costs $c_{ij} = \alpha_{ij} +\beta_{ij}x_{ij}$, where $\alpha_{ij}$ and $\beta_{ij}$ are, respectively, a fixed cost and a cost per unit of flow pushed along arc $(i,j)$. I'd like to solve the [minimum-cost flow (MCF) problem][1] in this graph, i.e., given a supply/demand of $k...
|algorithms|graphs|shortest-path|correctness-proof|network-flow|
The question is vague, so I will provide two possible answers: 1. **No**, we cannot compute $A(L)$ from $M(L)$ without first building $A(M(L))$, essentially because $A(M(L))$ is obtained from $M(L)$ by forgetting some information; in other words, if you are given $M(L)$, then, you know $A(M(L))$ without having to d...
null
I'm trying to learn the implementation of the Monte Carlo method in R language. I am following a course with an example of predicting results for a board game. What I'm not understanding is the usage of a function that was implemented on the top of the code, and that is: set.seed(5678) Do you know what this f...
What set.seed() mean in the Monte Carlo method