instruction
stringlengths
0
29.8k
⌀
|formal-languages|regular-languages|regular-expressions|
null
Could someone clarify what strings are accepted by the described DFA? > Draw a DFA for the set of all strings with two consecutive 0’s followed by two consecutive 1’s over Ʃ= {0,1}
What strings are accepted by the described DFA?
null
I am a research scholar in the field of algorithms and complexity theory. The problem that I am currently working is the $[1,j]$-domination problem. Given a graph $G = (V, E)$, with $n = |V|$, the problem asks to compute a minimum dominating set $D$, such that all the vertices outside the solution set $D$ have at most ...
I am working on the $[1,j]$-dominating set problem defined in <a href="https://www.sciencedirect.com/science/article/abs/pii/S0304397519307583">this</a> paper. In section 4, they study the problem complexity on degenerate graphs and prove that the problem is W[1]-hard for the parameter solution size. The reduction foll...
Is variable a constant or a parameter
|algorithms|graphs|np-hard|
null
**Problem Statement** Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread. The way I approached it: ``` def restaurant(l, b): ...
A practical issue in the code of HackerRank Restaurant problem
|python|
null
{"Voters":[{"Id":151464,"DisplayName":"Balchandar Reddy"}],"DeleteType":1}
**Problem Statement** Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $\ell \times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread. $\ell$ and $b$ denote the length a...
null
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for the $n$-th order $k$-tree, like in the article below. - A. Gainer-Dewar, Γ-species and t...
Generating algorithm (or program) for $k$-trees
|graphs|
For a size N I need an algorithm to generate all variations (no duplicates allowed) of natural numbers greater than zero. For N=1, this is trivial: ``` [1], [2], [3], ... ``` For N=2, I think of having rounds with an increasing limit L where the first element starts from 1 to L and the second element is L w...
Algorithm to generate all N-size variations of natural numbers
|algorithms|combinatorics|number-theory|
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
null
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
1. Mutual exclusion: the `while` loop is only executed with `key=true` so it can only set `lock=true`. As the `swap` is atomic, only one process can get a `false`, which is immediately "consumed". Only at the end of the critical section is the `false` restored. That `false` acts as a unique token. 2. Progress: if `l...
{"Voters":[{"Id":151464,"DisplayName":"Balchandar Reddy"}]}
A "mental model" as you say would be on the same lines as you proceeded with your example. The testing for the 3 conditions should focus on "breaking them", as a single false case is sufficient for non satisfaction. Additionally you can even check for deadlocks, which will imply no progress. This is evident in your 2n...
Try all possible permutation and combination of the set $S$. There are exactly $\sum_{r = 1} ^{8} \mathsf{8Pr}$ such possibilities for $n = 8$. This sums to exactly [109600](https://oeis.org/A007526). For each subset $s^*$ of $S$, find the edit distance to target string $t$ using the [standard DP algorithm](https://...
null
A $k$-tree is recursively defined as follows: $K_k$ is a $k$-tree and any $k$-tree on $n+1$ vertices is obtained by joining a vertex to a $k$-clique in a $k$-tree on $n$ vertices. I have only seen some counting results for $n$-th order $k$-trees, like in the article below. - A. Gainer-Dewar, Γ-species and the...
It can be considered constant as long as it is mentioned in the problem name. The intuition behind this is that since $j$ is in the name of the problem, different values of $j$ imply different problems, and hence, we can design a different algorithm for each, i.e. the algorithm itself can depend on $j$. --- Note ...
Here is a dynamic programming algorithm. Given a graph $G = (V, E)$ and two vertices $u, v \in V$. We define the recursive function $C:V\rightarrow \mathbb{N}$, such that $C(w)$ is the number of paths from $w$ to $v$. Note that we are looking for the value of $C(u)$. We set $C(v) = 1$ and $C(w)=0$ for each vertex $w \n...
It is correct that different sources provide different ways for telling whether an algorithm satisfies a property or not, because there's not standard way for deciding so. Let me point out an example: Peterson's Algorithm for arbitrarilly many processes is proved correct (satisfies mutual exclusion) in three different ...
For a size N>=1 (an input variable) I need an algorithm to generate all variations (no duplicates allowed) of natural numbers greater than zero. For N=1, this is trivial: ``` [1], [2], [3], ... ``` For N=2, I think of having rounds with an increasing limit L where the first element starts from 1 to L and th...
null
I understand that *Time Complexity is the measure of how an algorithm scales with respect to the input size*.<br> Let us say an algorithm is having a runtime of O($3^n$) + O($n^{20}$) <br> In order to identify the Non-Dominant term, I followed my intuition for a sample of values:<br> $3^n$ = {1, 3, 9, 27, ...} for...
How to identify Non-Dominant term among exponential O(3^n) and polynomial O(n^20) while understanding Time Complexity of an algorithm?
|algorithms|time-complexity|
No, when we talk about dominant terms in big-O notation we talk about asymptotic domination, i.e. how terms scale as $n \to \infty$. To see this you can think about the limit: $$\lim_{n \to \infty}\frac{f(n)}{g(n)} = C \ .$$ If this value is $C \in \mathbb{R}$, then we have that $f(n)=O(g(n))$ and so the sum $O(f(n...
No, when we talk about dominant terms in big-O notation we talk about asymptotic domination, i.e. how terms scale as $n \to \infty$. To see this you can think about the limit: $$\lim_{n \to \infty}\frac{f(n)}{g(n)} = C \ .$$ If this value is $C \in \mathbb{R}$, then we have that $f(n)=O(g(n))$ and so the sum $O(f(n...
As a first observation, if you can do it for $N=2$, then you can do it for any $N$ using the same process. Think of the case $N=2$ as "diagonalising" two copies of the infinite list for $N=1$ by just dropping duplicates. Then you can do $N=3$ by "diagonalising" a copy of $N=2$ with a copy of $N=1$. The details are l...
Complexity of checking whether the vertex has more neighbors of blue or red color
Somehow turn the opaque lambdas <!-- language-all: ml --> ```python current_cont = lambda result: current_cont(current_value * result) ``` into transparent data ``` current_cont = Compose( current_cont, Mult(current_value)) ``` then use the fact that ``` Compose( Compose( a_cont, Mult(val)), Mult(current...
null
This problem is from *Cracking the Code Interview*: > An array A contains all the integers from Oto n, except for one number > which is missing. In this problem, we cannot access an entire integer > in A with a single operation. The elements of A are represented in > binary, and the only operation we can use to ...
Optimizing findMissingNumber algorithm to O(N)
|algorithms|optimization|runtime-analysis|
This problem is from *Cracking the Code Interview*: > An array A contains all the integers from Oto n, except for one number > which is missing. In this problem, we cannot access an entire integer > in A with a single operation. The elements of A are represented in > binary, and the only operation we can use to ...
null
If the logical address and the page size are power of two, then we can separate the virtual address into two parts: page number and offset. Is this still valid if the virtual address is not power of two?
What if the size of the logical address is not power of two?
|operating-systems|memory-management|paging|
null
null
null
null
null
null
null
null
all, I was wondering if my intuitive understanding of why the halting problem is undecidable is actually correct? TLDR: Halting problem is undecidable because it leads to infinite recursion and never stops. Elaborating: At the bottom, I have attached an example of how I have seen the proof presented in a few b...
Infinite Recursion as the Intuitive Foundation for the Halting Undecidability Proof
|turing-machines|computability|automata|undecidability|halting-problem|
Let's say you have two strings: `a` and `b` with GCD `c`. Why is it that `len(GCD) = gcd(len(a), len(b))`?
finding the length of the GCD of two strings
|algorithms|data-structures|algorithm-analysis|strings|
We have a bipartite graph consisting of parts $A$ and $B$. Each vertex $i$ of part $A$ has weight $w_i$ and capacity $c_i$. We say a vertex $i$ in part $A$ is satisfied if at least $c_i$ adjacent edges to it are chosen. Now, the goal is to choose some edges of this graph such that each vertex in $B$ is adjacent to at m...
What is the name of this matching problem?
|np-complete|np-hard|approximation|weighted-graphs|bipartite-matching|
Problem: we have an undirected graph. Each vertex $v$ has a weight of $w_v$. On each vertex $v$, a nonnegative number $a_v$ is written, and on each edge $e$, a nonnegative number $b_e$ is written. We call an edge "activated" if both of its endpoints are chosen. Now, we want to choose a maximum weighted set of vert...
What is the name of this extension of the maximum independent set problem?
|np-complete|np-hard|approximation|weighted-graphs|
Problem: we have an undirected graph. Each vertex $v$ has a weight of $w_v$. For each vertex $v$, a nonnegative number $a_v$ is given, and for each edge $e$, a nonnegative number $b_e$ is given. We call an edge "activated" if both of its endpoints are chosen. Now, we want to choose a maximum weighted set of vertic...
Good day everyone, I'm currently trying to carry out the PetersonNP (a.k.a. FilterLock) correctness proof (mutual exclusion). I've found several proof sketches on concurrency books but I'm interested in the one shown in `Distributed Algorithms` (by Nancy Lynch). I find it more convincing because lemmata required for ...
I eventually found the solution for the first problem I proposed. Lemma 10.5.3.2 CAN be proved by induction, but it requires additional lemmata for doing so. I was misled by the note on page 292, specifically by the mention of "strengthening". It is common to say that a theorem is strengthened when its inductive hypot...
$\newcommand{\D}{\langle D \rangle}$ No, your argument does not prove the undecidability of the halting problem. For one, your pseudocode for $H$ doesn't appear to even attempt to decide the Halting problem. All it does is simulate its arguments and yield the result. That is what a universal Turing machine does, ...
The most direct procedural way that I have found to determine whether two regular expressions $R_0$ and $R_1$ are equivalent is the following: 1. Convert $R_0$ and $R_1$ to NFAs $N_0$ and $N_1$. 2. Convert $N_0$ and $N_1$ to DFAs $D_0 = (Q_0, \Sigma, \delta_0, q_0, F_0)$ and $D_1 = (Q_1, \Sigma, \delta_1, q_1, F_...
We have a bipartite graph consisting of parts $A$ and $B$. Each vertex $i$ of part $A$ has weight $w_i$ and capacity $c_i$. We say a vertex $i$ in part $A$ is satisfied if at least $c_i$ adjacent edges to it are chosen. Now, the goal is to choose some edges of this graph such that each vertex in $B$ is adjacent to at m...
We have $c$ arrays of positive integers, named $j[1],j[2],j[3]..,j[c]$. We know that the length of $j[i]$ is $c-i+1$. In addition, the sum of the numbers of $j[i]$ is greater than or equal to the sum of numbers of $j[y]$ if $i \leq y$. Moreover, we have $k$ tuples, each with a length of at most $c$. If we use a tuple $...
No, you only gained intuition about why the code `H` *you* wrote is not the halting oracle. What about all other possible attempts of implementing `H`? (Warning: do *not* try to argue that they too must enter an infinite loop, because that is blatantly false.)
null
I want to prove that a problem is in NP. I have a witness (of polynomial size), and a verifier that runs in polynomial time. However, this verifier uses exponential space, becuase it has to generate strings of exponential size. Is this allowed?
If I want to prove that a problem is in NP, can the vertifier use exponential space?
|np|decision-problem|
If your verifier (a Turing machine) runs in polynomial time then it must also use polynomial space since you can write at most one tape cell (or a constant number of tape-cell in case of multi-tape machines) per time-step. In other words $\mathsf{P} \subseteq \mathsf{PSPACE}$.
The book "Introduction to Information Retrieval" [talks about term-document incidence matrix][1] for retrieving documents that contain/not-contain certain tokens drawn from a query. This representation naturally lends itself to retrieving documents in response to a query. However, considering the document-term [bool...
ir - Using document-term [Boolean] incidence matrix for answering a query
|algorithms|information-retrieval|
null
>Show that the second smallest of $n$ elements can be found with $n+\lceil\lg n\rceil-2$ **comparisons** in the worst case. (Hint: Also find the smallest element.) [1] I tried but I have no idea how to, e.g. I best I could do is ``` second_smallest(A,n) initialize a FIFO queue q of size 2 such that it'll ...
Minimum number of comparisons to find $2$nd smallest element
|algorithms|algorithm-analysis|runtime-analysis|search-algorithms|statistics|
null
>Show that the second smallest of $n$ elements can be found with $n+\lceil\lg n\rceil-2$ **comparisons** in the worst case. (Hint: Also find the smallest element.) [1] I tried but I have no idea how to, e.g. the best I could do is ``` //assume n>=2 //A: array of size n //returns second smallest in A //0 i...
Assume that all elements are distinct (if not, replace each element with a pair $(element, position)$ and perform the comparisons lexicographically) and consider a rooted binary tree $T$ in which each vertex has either $0$ or two children and every level, except possibly the last, is completely filled. Arbitrarily asso...