instruction
stringlengths
0
29.8k
⌀
null
I am attempting to draw the DFA of this problem but I'm kind of stuck. In another post I saw that the DFA should have 10 states. I'm finding it hard to even understand the question, is the input to the DFA the full string so for example 1001 or is it multiple inputs of length 3 in this example 100 and then 001. I've ma...
I am attempting to draw the DFA of this problem but I'm kind of stuck. In another post I saw that the DFA should have 10 states. I'm finding it hard to even understand the question, is the input to the DFA the full string so for example 1001 or is it multiple inputs of length 3 in this example 100 and then 001. I've ma...
I am attempting to draw the DFA of this problem but I'm kind of stuck. In another post I saw that the DFA should have 10 states. I'm finding it hard to even understand the question, is the input to the DFA the full string so for example 1001 or is it multiple inputs of length 3 in this example 100 and then 001. I've ma...
null
I am attempting to draw the DFA of this problem but I'm kind of stuck. In another post I saw that the DFA should have 10 states. I'm finding it hard to even understand the question, is the input to the DFA the full string so for example 1001 or is it multiple inputs of length 3 in this example 100 and then 001. I've ma...
Suppose I have this c++ code: ``` for(int i=0; i<n*n*n; i++) { for(int j=0; j<n*n; j++) { if(i>n && j<n) { for(int k=0; k<n*n*n*n; k++) s++; } } } ``` I need to find its time complexity. What I tried doing is: I tried determining the times the i...
Time complexity of algorithm with three loops and if statement
|algorithms|time-complexity|algorithm-analysis|big-o-notation|
I found the proof of this theorem from https://www.csie.ntu.edu.tw/~lyuu/complexity/2011/20120103s.pdf. Here is the screenshot of the construction of probabilistic Turing machine RP. (https://i.stack.imgur.com/76pyK.png) The idea of proof is to show that if 3SAT $\in$ BPP, then 3SAT $\in$ RP. I understand the const...
If NP $\subset$ BPP, then NP $\subset$ RP. Confusion about the correctness of Probabilistic Turing Machine
|complexity-theory|turing-machines|3-sat|
Let's divide it in two parts: when the code enters the **if** and when it does not. 1) The **if** is executed when $n<i<n^3$ and $0\leq j <n$. This means that the values of $i$ which satisfy the condition are $n^3-n-1$, while the values of $j$ which satisfy the condition are $n-1$. For each value of $i$ for which th...
Let's divide it in two parts: when the code enters the **if** and when it does not. 1) The **if** is executed when $n<i<n^3$ and $0\leq j <n$. This means that the values of $i$ which satisfy the condition are $n^3-n-1$, while the values of $j$ which satisfy the condition are $n-1$. For each value of $i$ for which th...
I found the proof of this theorem from https://www.csie.ntu.edu.tw/~lyuu/complexity/2011/20120103s.pdf. Here is the screenshot of the construction of probabilistic Turing machine RP. (https://i.stack.imgur.com/76pyK.png) The idea of proof is to show that if 3SAT $\in$ BPP, then 3SAT $\in$ RP. I understand the const...
Let's divide it in two parts: when the code enters the **if** and when it does not. 1) The **if** is executed when $n<i<n^3$ and $0\leq j <n$. This means that the values of $i$ which satisfy the condition are $n^3-n-1$, while the values of $j$ which satisfy the condition are $n-1$. For each value of $i$ for which th...
null
In the code below, I describe a problem and provide a backtracking implementation in Python that solves it: ```python # Find the combination of k out of n measures that maximizes score # while ensuring that their total cost does not surpass C. # Each measure has a profit of m₁, …, mₙ and a cost of d₁, …, dₙ. #...
Better implementations for this dynamic program to solve optimization problem?
|dynamic-programming|recursion|
Me again. This time I have a more general question. Suppose I have the following code snippet: ``` int f(int k) { int s=0; for(int i=0; i<k*k; i++) { s++; } return 2*k*k; } ``` And the expression is: ```f(n) * f(f(f(n)));``` I am told that the complexity is ```O(n^2) + O(n^2) + O(n^4) ...
Time complexity of algorithm involving function calls
|algorithms|time-complexity|algorithm-analysis|big-o-notation|
f(k) performs k^2 operations. f(n) returns 2n^2, f(f(n)) returns 8n^4, so you calculate f(n) * f(8n^4). This takes about 64n^8 operations and the result is 2n^2 * 128n^8 = 256 n^10. There are O(n^4) other operations which we can ignore because that number is much smaller than 64n^8. The time complexity is O(n^8) or...
Consider the following equivalent way of computing the expression: ``` x_1 = f(n); x_2 = f(x_1); x_3 = f(x_2); return x_1 * x_3; ``` What are the (approximate) magnitudes of the different variables? What is the complexity of each call to `f`? What is the complexity of the multiplication on the last line? Then pu...
Your processor may use read/write instructions to access hardware, in that case some pages will be marked as uncached, so a read of 4 bytes will directly read from an address that is most likely not connected to RAM. Otherwise: I have never seen instructions that let you control this, the default is obviously going...
A short and direct answer to this question is "NO" because master can't be applied because `b = 1`. and master method needs a>=1 and `b>1` not equal
[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/BJamk.png So this is the language that I need to prove is irregular via pumping lemma, however I am completely stuck with this and seeking some advice. The other ones I have done during my tutorial are much more simple but struggling a bit...
Contradiction via pumping lemma
|formal-languages|regular-languages|automata|pumping-lemma|
Suppose towards a contradiction that $L$ is regular and let $p$ be its pumping length. Consider the word $w = cb^{4+p}c^{7+p} \in L$. By the pumping lemma, $w$ can be written as $xyz$ with $|xy| \le p$ and non-empty $y$ such that $xy^iz \in L$ for all $i \ge 0$. By our choice of $w$ either $y = cb^k$ for some non-...
Suppose towards a contradiction that $L$ is regular and let $p$ be its pumping length. Consider the word $w = cb^{4+p}c^{7+p} \in L$. By the pumping lemma, $w$ can be written as $xyz$ with $|xy| \le p$ and non-empty $y$ such that $xy^iz \in L$ for all $i \ge 0$. By our choice of $w$ either $y = cb^k$ for some non-...
LogLog/HyperLogLog provides a great way for estimating the cardinality of the set of $n$ objects. At its simplest, you hash all $n$ objects into binary strings, find the largest number of leading 0's $z$ in $O(n)$ time (and basically $O(1)$ space), and $2^z$ is your estimate for the cardinality. In practice, instead of...
Windowed LogLog/HyperLogLog algorithm to get a count of the cardinality of the set of the last $k$ elements?
|algorithms|sets|randomized-algorithms|probabilistic-algorithms|counting|
What is a good structure for pumping lemma contradiction?
Pumping lemma by contradiction
[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/BJamk.png So this is the language that I need to prove is irregular via pumping lemma, however I am completely stuck with this and seeking some advice. The other ones I have done during my tutorial are much more simple but struggling a bit...
Contradiction via pumping lemma
In role playing games, switching equipment for better is a common procedure. My question is to find an algorithm that can optimize linear combination of stats the equipped gear gives - this is exactly how it works on The-West.net: - Each piece of equipment can be equipped in only one slot (there is approximately 5-1...
I am looking for algorithms (or at least something similar to the problem definition): Given a fully-connected weighted graph G of N nodes, find a square lattice graph (where each node, except for the ones at the edges, is connected to 4 other nodes) such that the sum of weights edges in the lattice is minimal? I...
I am looking for algorithms (or at least something similar to the problem definition): Given a fully-connected weighted graph $G$ with $n$ nodes, find a subset $S$ of edges that form a [square lattice graph](https://en.wikipedia.org/wiki/Lattice_graph) (where each node, except for the ones at the edges, is connected...
|graphs|np-hard|lattices|subgraphs|
Your problem is NP-Hard. Consider the variant of the problem in which you need to delete the edges of a complete graph with $n$ vertices in order to obtain a $1 \times n$ lattice of minimum weight. Since a $1 \times N$ lattice is just a Hamiltonian, this variant is clearly NP-Hard. Indeed, you turn any (not necess...
Your problem is NP-Hard. Consider the variant of the problem in which you need to delete the edges of a complete graph with $n$ vertices in order to obtain a $1 \times n$ lattice of minimum weight. This variant is clearly NP-Hard. Indeed, you turn any (not necessarily complete) graph $G=(V, E)$ into a weighted co...
My experience is that $\log^2 n$ normally means $(\log n)^2$, unless context indicates otherwise. The result follows from the fact that $DSPACE(f(n)) \subseteq DTIME(2^{f(n)})$ (proven by using the fact that if a deterministic algorithm repeats the same state twice, then it loops infinitely).
Your problem is NP-Hard. Consider the variant of the problem in which you need to delete the edges of a complete graph with $n$ vertices in order to obtain a $1 \times n$ lattice of minimum weight. This variant is clearly NP-Hard. Indeed, you turn any (not necessarily complete) graph $G=(V, E)$ into a weighted co...
null
I am not aware of any x86 implementation that supported L1 cache bypassing for cacheable accesses unless one includes NT writes (which go to a special buffer and bypass all caches). However, the [MIPS R8000][1] (or specifically the R8010 FPU) had all FP memory accesses bypass L1, communicating directly with the L2 c...
null
null
How to prove that the heaviest edge in mst is not heavier than heaviest edge of any possible spanning tree? by heaviest edge of any Spanning tree i mean considering any possible Spanning tree, we have to prove that the heaviest edge in mst is not heavier than heaviest edge of that spanning tree.
Proving heaviest edge in mst is not heavier than heaviest edge of any possible spanning tree?
|minimum-spanning-tree|
The language you are considering is $(W^2)^*$, so you could combine standard constructions for the concatenation and the star operation.
I've been reading papers on streaming algorithms and ran across the following question which I haven't been able to answer: Consider the [Dyck language][1] $Dyck(2)$ over the alphabet $A = \{(,),[,]\}$ and let $f_n:A^n\times A^n \to \{0,1\}: f_n(x,y) = 1 \text{ if } xy\in Dyck(2)$ and 0 otherwise. Suppose two parties A...
Communication complexity of Dyck language
|complexity-theory|formal-languages|formal-grammars|communication-protocols|communication-complexity|
I am reading Papadimitriou's *Computational Complexity* and got stuck on part d) of the following exercise (pg. 505) > 20.2.14 A panorama of complexity classes. ... A language $L \subseteq \{0, 1\}^*$ will be called a leaf language. Let A and R be two disjoint leaf languages (the accepting and rejecting leaf langua...
$NL$ Leaf languages and $PSPACE$
|complexity-theory|time-complexity|turing-machines|space-complexity|complexity-classes|
TL;DR: $n \le C(f) \le n+1$. We can easily prove that $C(f) \ge n$. Consider the set of $x \in \{(,[\}^n$. There are $2^n$ such $x$-values. Each matches a different set of $y$-values. So, you need to send at least $n$ bits to distinguish among these $x$-values. Also, we trivially have $C(f) \le 2n$, as there ...
The definition of an oracular complexity class is key to answering this question, it is often defined as: $$ \mathsf{C^{A}=\bigcup_{L_A\in A}C^{L_A}} $$ But how do we define two oracles? Well the union definition ($\mathsf{C^{A,B}}=\mathsf{C^{A\cup B}}$) would imply that a Turing machine has access to only one la...
I would guess that this question is going to make some people wonder how I haven't already found a solution looking through papers -- but I do not see a clear algorithm. In implementing CDCL, I read [this site](https://users.aalto.fi/%7Etjunttil/2020-DP-AUT/notes-sat/cdcl.html), which gives the following definition:...
How to find the learned clause from a UIP cut
|satisfiability|dag|sat-solvers|
Let $e^*$ be the heaviest edge in an MST $T$, and let $A$ and $B$ be the vertices of the two connected components of $T - e^*$. Now, by the cut property, $e^*$ is a cheapest edge with one endpoint in $A$ and one endpoint in $B$. Since any spanning tree $T'$ must have an edge $e$ with one endpoint in $A$ and one i...
consider n houses in a city which each house water can be supplied with either a well or pips from other houses. constucting a well in a house i costs wi and connecting a pipe from house j to i costs c(i,j) which is cost of the making the edge between 2 houses. question is to find an algorithm to find the minimum cost ...
supplying water for all houses of a city with either a well or pipe
|minimum-spanning-tree|dijkstras-algorithm|
Consider $n$ houses in a city which each house's water can be supplied with either a well or pipes from other houses. Constructing a well in a house $i$ costs $w_i$ and connecting a pipe from house $i$ to $j$ costs $c(i,j)$. The question is to find an algorithm to find the minimum cost to provide water to all houses...
null
Consider graph $G=(V,E)$ where $V = \{s, v_1, v_2, \dots, v_n\}$ and there is an edge $(v_i, v_j)$ of weight $c(i,j)$ for all distinct (unordered) pairs $i,j$ with $1 \le i \le n$. Moreover, for each $i=1,\dots,n$, add the edge $(s, v_i)$ of weight $w_i$ . Let $T = (V, E_T)$ be a minimum spanning tree of $G$. Build ...
I would like to use or create a hashing algorithm that takes K inputs from 1 to N and maps them uniquely to different numbers on 1 to N. K can be 1 to N. Ideally I would like the hashing alg to be able to be salted, but I'm not sure that is possible if some of these numbers must be prime. Someone in #algorithms on l...
How to create a 'hashing' function that maps up to 1 to N numbers uniquely to numbers 1 to N
|hash|algebra|
null
Look for “linear congruential random number generator”. If you take a random number generator with range 0 <= r < n that’s basically what you want. And it’s quite fast.
You are omitting some very important details. In the exercise, the Turing machine $N$ is required to halt on all its possible computation paths using exactly $p(n)$ steps, where $n$ is the size of the input, and $p(n)$ is upper bounded by a polynomial. Moreover, each non-deterministic choice is labelled as either $0$ ...
Assume you parsed c b^(m+4) for some m. Show that different m must give different states. You are in a state where c^(m+7) leads to an accepting state. After parsing c b^(m’+4) for m’ ≠ m the same input does not lead to an accepting state, so you are in a different state. Since there are infinitely many different m...
You are omitting some very important details. In the exercise, the Turing machine $N$ is required to halt on all its possible computation paths using exactly $p(n)$ steps, where $n$ is the size of the input, and $p(n)$ is upper bounded by a polynomial. Moreover, each non-deterministic choice is labelled as either $0$ ...
You are omitting some very important details. In the exercise, the Turing machine $N$ is required to halt on all its possible computation paths using exactly $p(n)$ steps, where $n$ is the size of the input, and $p(n)$ is upper bounded by a polynomial. Moreover, each non-deterministic choice is labelled as either $0$ ...
The idea is to use the self-reducibility of SAT to construct a search-to-decision reduction. Suppose that we have in our disposal an oracle that solves SAT, and we wish to use it to find a satisfying assignment to a given satisfiable CNF on variables $x_1,\dots,x_n$. We use the following algorithm: - Substitute $...
There is some printing mistake it seems, the expression S←S−{Ej} must be inside `else` block otherwise `S` will always be empty.Since we are adding the elements in `if` block and removing it at last making no sense. The correct pseudo code looks like below: $i\leftarrow 1 \\ intersections \leftarrow 0\\ S\leftarr...
null
null
null
I am trying to write down a code which would blindly search for a condition using depth first search.I have been thinking of it for quite some time and I cant figure out how to continue. On the one hand the data structure is a tree with each node having n children so in order to tranverse every node of the tree you ...
Trying to implement DFS and I am stuck
|algorithms|trees|recursion|artificial-intelligence|depth-first-search|
The pseudo code for DFS using recursion would look something like this: ``` def DFS(node): if node is visited: return mark node as visited for each child in node: DFS(child) ``` This recursive method works because every time we call the function it goes as deep as it can into th...
I am trying to write down a code which would blindly search for a condition using breadth first search.I have been thinking of it for quite some time and I cant figure out how to continue. On the one hand the data structure is a tree with each node having n children so in order to tranverse every node of the tree yo...
Trying to implement BFS and I am stuck
I am trying to write down a code which would blindly search for a condition using breadth first search.I have been thinking of it for quite some time and I cant figure out how to continue. On the one hand the data structure is a tree with each node having n children so in order to tranverse every node of the tree yo...
null
Consider we use a RAM model with word length w (or if you really want a more exact model, you can use [Knuth's MMIX](https://www-cs-faculty.stanford.edu/~knuth/mmop.html)). Given a number n, we want to compute the most significant digit. For least significant digit, this is pretty easy: $n - 10 \lfloor {n\over{...
Consider we use a RAM model with word length w (or if you really want a more exact model, you can use [Knuth's MMIX](https://www-cs-faculty.stanford.edu/~knuth/mmop.html) [instructions](https://mmix.cs.hm.edu/doc/instructions-en.html)). Given a number n, we want to compute the most significant digit. For least si...
null
for two's complement, reverse bits and add 1(after addition discard carry), so reverse of 00000000=11111111, now add 1, 100000000, discard last carry bit (write result in 8 bits again), we get 00000000. notice that in 2's complement notation, number 0 has one and only 1 representation, while in 1's complement (as you ...
I have the following graph: G =(V,E) and I also have a set of colors C=[0,1,2,3,...,c-1]. (c is equal or smaller than the size of all nodes). I want to know if I can find a coloring procedure that can assign a color to each node(all nodes must be colored) in the way that each node can find all distinctive colors around...