instruction
stringlengths
0
29.8k
⌀
Given a word $\sigma_2 \sigma_4 \sigma_6\dots$, nondeterministically guess $\sigma_1 \sigma_3 \sigma_5 \dots$ and check (in polynomial-time) whether $\sigma_1 \sigma_2\sigma_3\sigma_4\sigma_5\dots \in L$. If that's the case, accept. Otherwise reject.
I am wondering if there is an "official" name for a *directed* graph where we cannot re-enter a vertex once we leave it to a *different* vertex. Here's an example of one such graph, where once you leave a given vertex to a different one, there is no way to come back to the same vertex. [![graph example][1]][1] ...
Is there a name for a directed graph where we cannot re-enter a vertex that we leave (to a different vertex)?
|dynamic-programming|directed-graphs|
> You are going on a trip from point $s$ to point $f$, in the way there > are $n$ hotels, $p_1, p_2,..., p_n$ each denotes the number of $km$ > from $s$. You must complete the trip by at most $t$ days ($t<n$) while > stopping at one of the hotels each night. The cost of each day is > $d^2$, where $d$ is the number ...
Is there linear solution for the hotel problem
|dynamic-programming|subset-sum|
I've started with thinking of a bucketsort/radix sort variation, only to be disproved by a colleague. here's the problem: Given an array with $k$ distinct elements, it is known that the smallest element appears once, the 2nd smallest element appears twice, the 3rd smallest element appears 4 times, the 4th smalles...
Sorting array with k distinct elements, each appearing double the times the previous one appears
|algorithms|time-complexity|sorting|
I need to find the production rules for the following language: $L = \{ \{ a,b \}^* ,n(a) = n(b) \}$ Well, the first thing I could come up with is $S \to aSb | \epsilon$ But this only covers the situation where all symbols $a$ precede $b$.So I tried to add all rules containing only one symbol of $a$, $b$,...
Context-free grammar for language $L = \{ \{ a,b \}^* ,n(a) = n(b) \}$
|formal-languages|automata|context-free|formal-grammars|
I need to find the production rules for the following language: $L = \{ \{ a,b \}^* ,n(a) = n(b) \}$ Well, the first thing I could come up with is $S \to aSb | \epsilon$ But this only covers the situation where all symbols $a$ precede $b$.So I tried to add all rules containing only one symbol of $a$, $b$,...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundant then the strings like $abba$ not possible to generate. Therefore your complete grammar is $S \to aS...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundant then the strings like $abba$ is not possible to generate. Therefore your complete grammar is $S \to...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundants then the strings like $abba$ is not possible to generate. Therefore your complete grammar is $S \t...
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array. 2. Copy the majority elements backwards into the original array. 3. Remove the majority elements from the temporary array. Python implementation including test ([...
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array. 2. Copy the majority elements backwards into the original array. 3. Remove the majority elements from the temporary array. Python implementation including test ([...
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array (e.g., using [Boyer-Moore](https://en.m.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm)). 2. Copy the majority elements backwards into the original arr...
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array (e.g., using [Boyer-Moore](https://en.m.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm)). 2. Copy the majority elements backwards into the original arr...
Stable sort an array with k distinct elements, each appearing double the times the previous one appears
I've started with thinking of a bucket sort/radix sort variation, only to be disproved by a colleague. Here's the problem: Given an array with $k$ distinct elements, it is known that the smallest element appears once, the 2nd smallest element appears twice, the 3rd smallest element appears 4 times, the 4th smalle...
I wonder if there is an algorithm which takes multiple (source,target) pairs and a max_depth parameter and returns all or some of the paths found with those pairs? Thinking of Dijkstra's algorithm, it would start from each start node and then in each iteration it would also check other pairs' tables to see if there ...
null
null
In the problem of pair-sum we are given a multiset $A$ and a number $\alpha$. We are asked to find whether there is a pair ($2$ numbers) of $A$ s.t. their sum is $\alpha$. Here all numbers are small/constant, $O(1)$, sum of $2$ small numbers requires $O(1)$ actions and their size is $O(1)$ bits for representation. I...
Limited tapes-version TM for pair sum
I am learning complexity theory with a background in mathematics, and I want to better understand why certain reductions are polynomial-time computable. Let me give two examples of my worries. **Example 1: The Cook–Levin reduction.** In the proof of the Cook–Levin theorem (say in Arora–Barak or Sipser), give...
Worrying about details: high-level arguments about polynomial-time computability
|turing-machines|reductions|
I need to find the production rules for the following language: $L = \{u \in \{a, b\}^* \mid |u|_a = |u|_b\}$ Well, the first thing I could come up with is $S \to aSb | \epsilon$ But this only covers the situation where all symbols $a$ precede $b$.So I tried to add all rules containing only one symbol of ...
Context-free grammar for language $L = \{u \in \{a, b\}^* \mid |u|_a = |u|_b\}$
The way you convince yourself of those claims is that you figure out how to write out an explicit proof of them. This same issue occurs with every mathematical proof. Every mathematical proof has some aspects that are described in detail in the proof and some claims or statements that are not explained in further det...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundants then the strings like $abba$ is not possible to generate, that's why you need to add $SS.$ Therefo...
null
- Take the median and the median of the first half. - In the subset between these, take the median and the median of the first half*. Repeat the line above until the subset is a singleton. The bounds between which the medians are taken are successively $[0,n), [0,\frac n2)$ $[\frac n4,\frac n2), [\frac ...
- Take the median and the median of the first half. - In the subset between these, take the median and the median of the first half*. Repeat the line above until the subset is a singleton. The bounds between which the medians are taken are successively $[0,n), [0,\frac n2)$ $[\frac n4,\frac n2), [\frac ...
Say I have a bipartite graph G with vertex set A and B when |A|=|B|=n and edge set E. Then how do I determine whether the graph has unique matching efficiently.
Unique matching in bipartite graph with equal vertices
|graphs|bipartite-graph|
Unique perfect matching in bipartite graph
By other words, can anyone explain how indirect addressing works? I red MARIE's LoadI X over and over and still didnt understand the logic behind it. LoadI X loads the value which is stored at address of the address X into the AC Thanks for any answer.
How the indirect addressing works?
|functional-programming|
Unique perfect matching in unweighted bipartite graph
- Take the median and the median of the first half*. - In the subset between these, take the median and the median of the first half*. Repeat the line above until the subset is a singleton. The bounds between which the medians are taken are successively $[0,n), [0,\frac n2)$ $[\frac n4,\frac n2), [\frac...
Let the variable X contain the value 0xABC, assumed to be a valid memory address, and let the address of X be 0xDEF. Then X denotes the value of what is stored at 0xDEF and *X (indirect addressing) is the value of what is stored at 0xABC (not said here). ---------- Without indirect addressing, there would prob...
I and several colleagues answered this question [here][1] with a necessary and sufficient criterion for when the language $L_{x=y}$ (all words having an equal number of occurrences of $x,y$) is regular. We also show the same for fewer $x$ than $y$, and more $x$ than $y$. [1]: https://arxiv.org/pdf/1804.11175.pdf...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundants then the strings that does starts and ends with same symbol like $abba$ is not possible to generate, th...
This question is about the second frequency algorithm described in N. Alon, T. Matias, and M. Szegedy The space complexity of approximating the frequency moments. Specifically, I am asking about the stochastic algorithm for the second moment. It seems its usage it very much limited. The storage required is proport...
Usage cases of AMS algorithm
|probabilistic-algorithms|
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array (e.g., using [Boyer-Moore](https://en.m.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm)). 2. Copy the majority elements backwards into the original arr...
null
Say I have a bipartite graph G with vertex set A and B when |A|=|B|=n and edge set E. Then how do I determine whether the graph has unique matching efficiently. I am not sure but the permanent of adjacency matrix will give the number of perfect matching. But it will take O(n^4) can it be done in O(n+e) if not what is t...
Say I have a bipartite graph G with vertex set A and B when |A|=|B|=n and edge set E. Then how do I determine whether the graph has unique matching efficiently. I am not sure but the permanent of adjacency matrix will give the number of perfect matching. But it will take O(n^3) can it be done in O(n+e) if not what is t...
Find the maximum element, then partition the array into two buckets, smaller and equals. Apply the algorithm recursively to the smaller bucket. Here is an example implementation in Python: ```python def algorithm(data): if not data: return [] pivot = max(data) smaller = [x for x in data if x...
I sat on that same issue for a couple weeks and wracked my brain over it. I finally found someone who posted the solution in Python. I was able to convert it to Visual Basic for my self and it works perfectly. Here is the code if you still need it. Function Compare(Guess As String, Target as String) As String...
Find the maximum element, then partition the array into two buckets, smaller and equals. Apply the algorithm recursively to the smaller bucket. Here is an example implementation in Python: ```python def quicksort(data): '''stable out-of-place quicksort with maximum element for pivot''' if not data: ...
Find the maximum element, then partition the array into two buckets, smaller and equals. Apply the algorithm recursively to the smaller bucket. Here is an example implementation in Python: ```python def quicksort(data): '''stable out-of-place quicksort with maximum element for pivot''' if not data: ...
Given a Boolean formula over $n$ variables in CNF and a partial assignment to it, all the algorithms I can think of to evaluate the assignment run in time $\Theta(n^2)$. Is it possible to do it in $O(n)$? I'd say no, because otherwise SAT would be in NTIME(n) and we know that P is different from NTIME(n), but maybe thi...
Time-complexity of evaluating a CNF formula
|complexity-theory|time-complexity|satisfiability|sat-solvers|boolean-complexity|
My question is motivated by [this][1] one I am looking for a reference in which the definition of an $f$-speedup is provided. Let's assume that we have an algorithmic problem to solve. This problem takes an integer $n$ as input to describe it and provides as output a bit string providing the answer we are expecti...
Definition of an $f$-speedup
|complexity-theory|
We know that $3SAT \in NP$, and the definition of $NP$ is as follows: $NP$ is the class of languages that have polynomial time verifiers. But I have a question: >what does **input** mean for the $3SAT$ question? Is it the number of variables $n$ or the number of clauses $m$, Let's take an example, given a ...
what does **input** mean for the $3SAT$ question? Is it the number of variables $n$ or the number of clauses $m$
|complexity-theory|satisfiability|3-sat|sat-solvers|
To the best of my knowledge there is no such notion in the parallel computing community. The closest definition that I can think of is the following, that you will find in the book "Introduction to Parallel Algorithms" by C. Xavier and S. S. Iyengar (beware: its not actually used in practice): Asymptotic Real Speedu...
The *speedup* is the ratio of the running times of two "programs", in the same conditions. This follows a statistical distribution that is a function of the input size, which you can characterize with asymptotic $O$ and $\Omega$ bounds, as usual. E.g. the speedup of QuickSort over InsertionSort is $\Omega(1)$ and $O...
null
The input is just a Boolean formula $\phi$. $|\phi|$ depends on the way in which $\phi$ has been encoded.
null
The topic cover broad range of work, It should start with 1- CPU-GPU Architecture, you can compare the latest one with the previous one in comparison section and show how it contribute towards the performance. Performance is not only based on CPU-GPU, next point should be 2- SDRAM , explain the concept of SDRAM, ...
Copy the elements into a temporary array. As long as the temporary array isn't empty, repeat this: 1. Find the majority value in the temporary array (e.g., using [Boyer-Moore](https://en.m.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm) (or, as Rainer's answer reminds, simply `max` in our case, but I...
Find the maximum element, then partition the array into two buckets, smaller and equals. Apply the algorithm recursively to the smaller bucket. Here is an example implementation in Python: ```python def quicksort(data): '''stable out-of-place quicksort with maximum element for pivot''' if not data: ...
Consider a version of Mergesort that returns an array of lists. Each list in the array groups all element with the same value (and stores them in the same order as they appear in $A$). Clearly each array has at most $k$ elements. Moreover, two arrays of $m$ elements each can be merged in time $O(\min\{m,k\}) = O(\mi...
null
Consider a version of Mergesort that returns an array of lists. Each list in the array groups all element with the same value (and stores them in the same order as they appear in the original array). Clearly each array has at most $k$ elements. Moreover, if we are given two sorted arrays, each of which stores $m$ el...
I've already posted in the Math StackExchange section, but nobody answered. I’m wondering if, given a planar graph $G$ And two vertices $v,u$, is there an efficient algorithm to know if adding the edge $(v,u)$ to $G$ makes the graph non-planar? I’m thinking something that runs in $O(1)$ for every query, even if i...
Add an edge to a planar graph and preserving the planarity
|graphs|trees|planar-graphs|
Neither. The input is the Boolean formula $\phi$. You are probably asking what is the *length* of the input, as computational complexity tries to express the running time of the algorithm as a function of the length of the input. The length of $\phi$ depends on how it is encoded, but typically the length will depend...
I've started with thinking of a bucket sort/radix sort variation, only to be disproved by a colleague. Here's the problem: > Given an array with $k$ distinct elements, it is known that the > smallest element appears once, the 2nd smallest element appears twice, > the 3rd smallest element appears 4 times, the 4t...
null
The question [defining a context-free grammar for $\{\in\{0,1\}^*:\#_0(w)=\#_1(w)\}$](https://cs.stackexchange.com/questions/22729/defining-a-context-free-grammar-for-w-in-0-1-0w-1w) restricts its answers to one particular grammar and the proof for its correctness is somewhat involved. Here I would like to show a diffe...
No. You can't even do it in $O(n^2)$ time, if $n$ is the number of variables. The formula might be much longer than $\Theta(n^2)$ (it might have many more clauses than that), and obviously any correct algorithm will have to read the entire formula (at least in the worst case), so the running time of any correct algori...
I am trying to find an algorithmic solution to a thought experiment that occurred to me recently. Please excuse me if the question is a bit naïve as I am not a CS expert. ___ Basically I have a tree with $n$ nodes, each of which is assigned a label $l\in\{0,\ldots,k\}$. More than one node can have the same label....
Is there a solution to the following thought experiment / problem involving trees?
|algorithms|trees|
I am trying to find an algorithmic solution to a thought experiment that occurred to me recently. Please excuse me if the question is a bit naïve as I am not a CS expert. ___ Basically I have a tree with $n$ nodes, each of which is assigned a numeric label $l\in\{0,\ldots,k\}$, $k\in\mathbb{Z}, k\geq0$. More than...
By your above mentioned grammar $S \to aSb|bSa|abS|baS|Sab|Sba|\epsilon$ has four redundants $abS,baS,Sab,Sba$ and one missing term is $SS.$ Because if you use $S \to aSb|bSa|\epsilon$ only after removing redundants then the strings that does starts and ends with same symbol like $abba$ is not possible to generate(but...
I am trying to find an algorithmic solution to a thought experiment that occurred to me recently. Please excuse me if the question is a bit naïve as I am not a CS expert. ___ Basically I have a tree with $n$ nodes, each of which is assigned a numeric label $l\in\{0,\ldots,k\}$, $k\in\mathbb{Z}, k\geq0$. More than...
{"OriginalQuestionIds":[102635],"Voters":[{"Id":91753,"DisplayName":"John L."},{"Id":79440,"DisplayName":"Nathaniel"},{"Id":683,"DisplayName":"Yuval Filmus","BindingReason":{"GoldTagBadge":"formal-languages"}}]}
You need to check all pairwise relations (by explicit computation of the $\gcd$s) and fill a graph. Then compute the *transitive closure* of the graph, in a modified way (to account for the $n$ constraint). https://en.wikipedia.org/wiki/Transitive_closure#Algorithms
To pop an element off of a priority queue, the worst-case complexity is: O(logN) where N is the number of elements. Now if you do K pop operations on the priority queue, the number of elements decreases. So the cost of these K operations would be: O(logN) + O(log(N-1)) + O(log(N-2)) + O(log(N-3))......
What is the amortized cost of pulling top K elements from a priority queue?
|time-complexity|amortized-analysis|priority-queues|