instruction
stringlengths
0
29.8k
⌀
Array access is O(1) implies a fixed index size, which implies O(1) array traversal?
|complexity-theory|
Consider this piece of code: for i in range(len(nums)): dfs(nums[:i]+nums[i+1:], curr+[nums[i]], res) Note that `curr+[nums[i]]` creates a new list, and on the bottom level, each of the $n!$ new lists will have size $n$. Hence $\mathcal{O} (n! \cdot n)$ total complexity. On the ot...
It's a good question. From a pragmatic perspective, we tend not to worry about it. From a theoretical perspective, see the [transdichotomous model](https://en.wikipedia.org/wiki/Transdichotomous_model). In particular, a standard assumption is that there is some integer $M$ that is large enough (i.e.,, larger than ...
It's a good question. From a pragmatic perspective, we tend not to worry about it. From a theoretical perspective, see the [transdichotomous model](https://en.wikipedia.org/wiki/Transdichotomous_model). In particular, a standard assumption is that there is some integer $M$ that is large enough (i.e., larger than t...
It's a good question. From a pragmatic perspective, we tend not to worry about it. From a theoretical perspective, see the [transdichotomous model](https://en.wikipedia.org/wiki/Transdichotomous_model). In particular, a standard assumption is that there is some integer $M$ that is large enough (i.e., larger than t...
null
null
I am currently stuck on this problem, it is from a very highly competitive contest and so it is highly difficult as well. Below is the statement: ``` There are 2 lists of integers with the same length. Pick an integer from each list and calculate the absolute value of their sum. Return the minimum value for th...
Minimum absolute sum of 2 elements from 2 different lists
null
I am currently stuck on this problem, it is from a very highly competitive contest and so it is highly difficult as well. Below is the statement: ``` There are 2 lists of integers with the same length. Pick an integer from each list and calculate the absolute value of their sum. Return the minimum value for th...
Firstly, I recommend you, not to visualize science and math as separate theories. Basically, to induce any kind of new scientific approach, there must be some mathematical model working underneath it.. as to mention math would be providing a background framework Similarly, in the case of Turing machine or the con...
Firstly, I recommend you, not to visualize science and math as separate theories. Basically, to induce any kind of new scientific approach, there must be some mathematical model working underneath it.. as to mention math would be providing a background framework Similarly, in the case of Turing machine or the con...
It says the constraints are 1) Odd number of A's and 2) At most 4 B's let's start the expression ->string may start with both A & B ======>(A+B) ->say the first letter of the string be A ======>we need kernels should contain even A's to make it odd ========>of kind(_a_a_) ====...
I found the following proof concerning the correctness of a bft resulting in shortest path: [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/lgVRA.jpg The key is that if we assume that we have a shorter path, we get a contradicition. I however do not fully understand with what the conse...
Correctness of bft resulting in shortest path
|algorithms|shortest-path|correctness-proof|breadth-first-search|tree-traversal|
**Short answer:** the Turing Machine is a fundamental concept in the Theory of Computability. Like the prime decomposition is a fundamental concept in the Theory of Numbers.
null
The contradiction is that we're assuming **the first time we've seen $w$** is through the node we're expanding, $v$. However, if there were a shorter path, then the second-to-last node in that path must be some other node, $v'$. Since the path is shorter, $dist[v'] < dist[v]$. But if that's the case then $v'$ should'...
null
I found the following proof concerning the correctness of a breadth-first traversal resulting in shortest path: [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/lgVRA.jpg source: https://people.eecs.berkeley.edu/~daw/teaching/cs170-s03/Notes/lecture6.pdf The key is that if we assume th...
> If this is wrong, can we always write a program whose CFG is planar without loss of function? Yes, we can. Suppose we have an arbitrary CFG $G$, which is a finite graph. > It is known that any finite graph can be embedded into a three-dimensional space. - Wikipedia Let's say for our CFG, we have a 3D e...
Let a sequence of $n$ elements. If all pairs of consecutive elements are equal, then by transitivity all elements are equal. By contradiction, if they are not all equal, then there is certainly a pair of consecutive elements that differ. Hence $$\bigwedge_{i=0}^{n-1} (A_i=A_{i+1})$$ settles the query, in $n-1$ ...
Let a sequence of $n$ elements. If all pairs of consecutive elements are equal, then by transitivity all elements are equal. By contradiction, if they are not all equal, then there is certainly a pair of consecutive elements that differ. Hence $$\bigwedge_{i=0}^{n-1} (A_i=A_{i+1})$$ settles the query, in $n-1$ ...
Let a sequence of $n$ elements. If all pairs of consecutive elements are equal, then by transitivity all elements are equal. By contradiction, if they are not all equal, then there is certainly a pair of consecutive elements that differ. Hence $$\bigwedge_{i=0}^{n-1} (A_i=A_{i+1})$$ settles the query, in $n-1$ ...
Let a sequence of $n$ elements. If all pairs of consecutive elements are equal, then by transitivity all elements are equal. By contradiction, if they are not all equal, then there is certainly a pair of consecutive elements that differ. Hence $$\bigwedge_{i=0}^{n-1} (A_i=A_{i+1})$$ settles the query, in $n-1$ ...
As D(n) denotes the max degree of any node, the highest degree of any child of the deleted node can be D(n)-1, and there can be at most D(n) children of the deleted node. Now after merging all the children of the deleted node to the root list, the highest degree of any node is D(n)-1. Now the question is, how many ...
null
The cost of array access would be for example $c_1$ if the array size is less than $2^{64}$, $c_2$ if the array size is less than $2^{128}$, $c_3$ if the array size is less than $2^{256}$ and so on. Since $2^{128}$ exceeds the total size of all hard drives on earth, and $2^{256}$ vastly exceeds the number of bits that ...
My question is generalizable to arrays of any type but I'll use strings to keep it short. We take a couple of strings as an input. Let's denote them ${S_1,...S_n}$. (Ex: "ABEF" and "CDE"). The output $U$ must fulfill the following conditions: - The output must contain the entire "vocabulary" of all of the inputs...
When solving numerical problems with circles, one often has to sample these at numerous points, not necessarily in a uniform way. Evaluating the $(\cos\theta,\sin\theta)$ values can represent a significant fraction of the cost, as they are transcendental functions. We can get rid of these functions by rational subst...
Alternative parameterizations of the circle
|computational-geometry|numerical-algorithms|algebra|
null
When solving numerical problems with circles, one often has to sample these at numerous points, not necessarily in a uniform way. Evaluating the $(\cos\theta,\sin\theta)$ values can represent a significant fraction of the cost, as they are transcendental functions. We can get rid of these functions by rational subst...
null
null
I am wondering if it is known whether probabilistic Turing machines are more powerful than deterministic ones, in the sense that they can solve problems faster on average, or can solve problems that deterministic Turing machines cannot? That is, if a Turing machine can "flip coins", does this allow it to do things it ...
Are deterministic Turing machines as powerful as probabilistic Turing machines?
|turing-machines|
I am wondering if it is known whether probabilistic Turing machines are more powerful than deterministic ones, in the sense that they can solve problems faster on average, or can solve problems that deterministic Turing machines cannot? That is, if a Turing machine can "flip coins", does this allow it to do things it ...
null
I have a question regarding oracles. If I have the complexity class $P^A$ (with $P \subseteq A$), what is it's relationship to the class $A$? I mean it should be trivial that $A \subseteq P^A$ for all $A$. But the other way is interesting. As far as I know, there are some $A$ such that $P^A = A$ (e.g. $P$ or ...
Why isn't $P^A = A$?
|complexity-theory|time-complexity|complexity-classes|oracle-machines|
This is a famous open problem in computer science theory. In particular, it comes down to whether [BPP](https://en.wikipedia.org/wiki/BPP_(complexity)) = P. It is widely conjectured and suspected that BPP = P, or in other words that randomness does significantly increase the power of computer algorithms. However, we...
This is a famous open problem in computer science theory. In particular, it comes down to whether [BPP](https://en.wikipedia.org/wiki/BPP_(complexity)) = P. It is widely conjectured and suspected that BPP = P, or in other words that randomness does not significantly increase the power of computer algorithms. However...
null
The answer is that almost all the data that the CPU works on ends up in various levels of the cache. It's not like text goes into L4, and images go into L3, audio into L2 and video into L1. The memory controller in the CPU will manage the data in the cache, moving it between levels according to various rules of thum...
The CPU in a computer is a very general purpose device. The same CPU might be used in a gaming PC, or in a server, or in a spacecraft. So, when they design CPUs, they don't design them for a specific function; you won't find a CPU with a special electrical connection for connecting to the inertial guidance system of a ...
A solution that will often take not much more than n operations (but no guarantee): 1. In constant time find the range of both arrays, like -7 .. 6 and -2 .. 9 in the example. 2. Calculate the number of sums (16 in this case). 3. Make a guess for the smallest absolute difference say 2 in this case. 4. Creat...
After several hours of frustration, I finally realized that the definition of two-three trees aren't standard (my lecture notes, [this][1] video, [this][2] other video, and [Wikipedia][3]) are different. My lecture notes, for example, maintains that keys are stored only in the leaves, while most other implementations s...
What is the gold-standard description of the 2-3 tree (search, insert, delete)?
|binary-trees|binary-search-trees|
|complexity-theory|computation-models|
null
I want to prove that $\mathcal M =\{a^ib^jc^k \mid \min(i,j)\le k\le\max(i,j)\}$ is not a CFL. Using the pumping lemma, let $p$ be the constant, then I choose $w=a^pb^pc^p$. When I separate to cases, looking at the homogeneous case, by choosing either $w_0$ or $w_2$ I can't disprove the lemma, because the number ...
How to prove the language of words $a^ib^jc^k$ where $\min(i,j)\le k\le\max(i,j)$ is not context-free?
|formal-languages|context-free|formal-grammars|pushdown-automata|pumping-lemma|
#### Idea [The pumping lemma for context-free languages](https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages) is not useful since M satisfies it with pumping length $p=1$. Instead, we will use [Ogden's lemma](https://en.wikipedia.org/wiki/Ogden%27s_lemma) to "pump" a carefully-chosen word in $\mathc...
I was going through my Operating Systems book and in the disadvantages, they wrote that there is no user interaction between the user and computer in uni-programming and multi-programming systems and I asked why? to myself. There was no material or maybe I could not see or understand the idea that why there is no user ...
Why there is no user interaction between uni-programming and multi-programming systems?
|scheduling|cpu|
#### Idea [The pumping lemma for context-free languages](https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages) is not useful since M satisfies it with pumping length $p=2$. Instead, we will use [Ogden's lemma](https://en.wikipedia.org/wiki/Ogden%27s_lemma) to "pump" a carefully-chosen word in $\mathc...
null
i just want to know why the techniques we use to solve the 2-SAT problems cannot be used to solve the 3-SAT problem. So the techniques that i know that help solve 2-sat are the naive on where you just take one variable in the formula and give it a truth value and go on from there by deleting clauses where the variable ...
Why do the 2-SAT techniques do not work for 3-SAT?
|complexity-theory|3-sat|2-sat|
User interaction loosely can be thought of as responding to a user's request while the machine is performing some work. Uni-programmed systems(in the older days) as the name suggests can perform only one task at a time, as only one task could reside in main memory. To process user inputs, you at least need to have an i...
User interaction loosely can be thought of as responding to a user's request while the machine is performing some work. Uni-programmed systems(in the older days) as the name suggests can perform only one task at a time, as only one process could reside in main memory. To handle user inputs, you at least need to have an...
as the title says: is there a TM $T(m;n)=q$ where $q\not=m$ and $T_q(0)=T_m(n)$? it seems "obvious" that there is such a TM but if there is then the function $Q(n) = 1 + T(n;n)$ is not computable because it's the diagonal of $T$ plus one (it is not in the list of all computable function) so there is no TM that...
Is there a TM $T(m;n)=q$ where $q\not=m$ and $T_q(0)=T_m(n)$?
|turing-machines|halting-problem|
**An $\epsilon$-tester** given an input and a property, is defined as follows: If the input holds the property then the tester should accept with probability at least $ \frac 2 3$. Otherwise if the input is more than $\epsilon$ far from holding the property then the tester should reject with probability at least $\fra...
Lower bound for ϵ-tester with one-sided error for the "2-injective" property of functions
|algorithms|algorithm-analysis|lower-bounds|property-testing|
I want to solve the problem of finding a shortest path on a directed weighted graph from a certain node to *any* of a specified set of destination nodes (preferably the closest one, but that's not that important). The standard (I believe) way to do this with the A* algorithm is to use a distance-to-closest-goal heurist...
Any-goal bidirectional A* pathfinding reference
|reference-request|shortest-path|a-star-search|
#### Idea [The pumping lemma for context-free languages](https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages) is not useful since M is "pumpable" with pumping length $p=2$. Instead, we will select a word in $\mathcal M$ that has less number of $a$'s and almost equal number of $b$'s and $c$'s, using ...
Suppose I have the following structure definition in C: struct node { int value; struct node *parent, *left, *right; } If I want to represent a specific node inside a tree, all I need is a pointer to such node, which allows me to traverse the tree using the parent and children's link. ...
Is possible to have a "pointer" to a tree node in a functional language?
|trees|functional-programming|
null
I'm reading "Program=Proof" by Samuel Mimram, and they use a notation for defining a formal language that I'm not familiar with. Here is how **"Program=Proof"** defines a **formal language of Propositional Logic**: > <img src="https://i.stack.imgur.com/aup5E.png" width="500"/> Here is how **"Program=Proof"** d...
Formal language rewrite rules: strange notation
|formal-languages|formal-grammars|logic|lambda-calculus|
If a function type is representable by [exponentiation](https://www.euclideanspace.com/maths/discrete/types/byType/exponent/index.htm), does it follow that function application is represented by the right inverse, roots? It would seem that roots consume a function's input to return the output, and logarithms consume a ...
Is the root function computationally equivalent to function application?
|type-theory|mathematical-foundations|curry-howard|
Big-O notation can be tricky because it hides details. Big-O describes a way to measure a function related to complexity. That function may be "number of memory accesses," which would explain the O(1) complexity. However, if you were on a machine supporting large heterogenous memory spaces, that may hide a complexit...
If a function type is representable by [exponentiation](https://www.euclideanspace.com/maths/discrete/types/byType/exponent/index.htm), does it follow that function application is represented by the right inverse, roots? It would seem that roots consume a function's input to return the output, and logarithms consume a ...
This is the definition of root and logarithms. And the usual notation for the inverse of a function $f$ is $f^{-1}$, which satisfies $f^{-1}(f(x))=x$ and $f(f^{-1}(y))=y$ $\log_a(x)=f^{-1}(x)$ where $f(x)=a^x$ $\sqrt x=f^{-1}(x)$ where $f(x)=x^a$. Function composition, which is denoted by $h=f\circ g$, creates a n...
as the title says: is there a TM $T(m;n)=q$ where $\forall n \forall m \exists q\space T_q(0)=T_m(n)$? it seems "obvious" that there is such a TM but if there is then the function $Q(n) = 1 + T(n;n)$ is not computable because it's the diagonal of $T$ plus one (it is not in the list of all computable function) ...
is there a TM $T(m;n)=q$ where $\forall n \forall m \exists q\space T_q(0)=T_m(n)$?
Yes, I think that's basically the intent. I guess the book is trying to write grammars without grammatical symbols. For me, it's abuse of notation, but that's pretty common. Because there is no formal notation for grammatical symbols, the grammar doesn't really express the fact that $A$ and $B$ are *formulas*, $X$ i...
null
Yes, I think that's basically the intent. I guess the book is trying to write grammars without grammatical symbols. For me, it's abuse of notation, but that's pretty common. Because there is no formal notation for grammatical symbols, the grammar doesn't really express the fact that $A$ and $B$ are *formulas*, $X$ i...