instruction
stringlengths
0
29.8k
⌀
I have to analyze how every sorting algorithm's complexity would change if it had to sort a linked list and which of all of them is the most efficient. I find everywhere that merge sort is the most efficient one for linked lists, but I don't understand why counting sort isn't better. I think it would still be O(n). Am ...
Isn't counting sort a better sorting algorithm for linked lists rather than merge sort?
|sorting|
null
Counting sort is a very particular kind of sort which you can only apply in particular circumstances. * If the elements you're sorting are floating-point numbers instead of integers, counting sort doesn't work. * If the elements you're sorting take their values in a huge range with more possible elements than actual ...
null
I've implemented a ranking system (based on a score), using a Map<Player,Score> and an improved BST<Score, Set<Player>>. So now I can compute "rank of a player" in O(log(n)) time, "top xxx players", insert/update/remove in O(log(n)) time. Now I want to improve by data structure to remember the "best rank" of each ...
A one-counter automaton is a finite-state machine that is augmented with a single counter. The finite-state machine can issue a command to increment or decrement the count, or to test whether the counter is zero or not. The halting problem for one-counter automata is [decidable](https://cs.stackexchange.com/q/7574/...
``` public void m1(int n) { sum = 0; for (int i = n/2; i <= n; i++) { for (int j = 1; j <= n; j = 2 * j) { for (int k = 1; k <= n; k = k * 2) { sum++; } } } } ``` So, I know that the innermost loop and second loop are $\log(n)$ and the ou...
null
In literature, Convolutional Neural Nets (CNNs) are presented as a special case of Deep Neural Nets (DNNs) (e.g., [here](https://arxiv.org/abs/1703.09039)). I do not understand how the convolutional layer can be implemented through a layer of neurons though. As far as I understand, a $n \times m$ kernel is used to calc...
Is a Convolutional Neural Net a special case of DNN? If so, how can the convolutional layer be modelled?
|machine-learning|neural-networks|
null
You're reading too much into the phrasing 'special case'. You already accurately understand the sense in which a CNN can be considered as a special case of a DNN; it is a DNN where many of the weights are repeated. Here people are probably referring to the model that is produced by the training procedure: every CNN c...
Suppose $L$ is regular and we define $L'=\{x:\exists y\in L \wedge \text{ y be a subsequence of x}\}$. Could we conclude that $L'$ is regular or not? I think it's not regular because if $L=a^*b^*c^*$ then $L'$ could be $a^nb^nc^n$ so it can't be regular.
You are comparing apples and orange-colored bicycles here. [*Merge Sort*](https://wikipedia.org/wiki/Merge_sort) is a [*stable*](https://wikipedia.org/wiki/Sorting_algorithm#Stability) [*Comparison Sort*](https://wikipedia.org/wiki/Comparison_sort). As such, it only requires that there must be a [*Total Preorder*](h...
null
Language C is non-trivial if both C and its complement are non-empty. If A is non-trivial and B is trivial, there cannot be a reduction from A to B.
null
I am working on a project and came across the following problem I have to solve. Imagine we have a time series data `Ts` which is an array of pair, say each element is `(Xi, Yi)`. The length of this array is constant `N` but is updated regularly. Each update consists of two steps, 1. We remove `Ts[0]` 2. Add a n...
I've implemented a ranking system (based on a score), using a Map<Player,Score> and an improved BST<Score, Set\<Player\>>. So now I can compute "rank of a player" in O(log(n)) time, "top xxx players", insert/update/remove in O(log(n)) time. Now I want to improve my data structure to remember the "best rank" of eac...
I would need efficient pari gp code to test whether an integer $n$ is $k$-smooth, that is, all of $n$'s prime factors are at most $k$. I don't need the factors, just the yes/no answer. The regime would be $10^{60} < n < 10^{100}$ and $10^8 < k < 10^{10}$.
smoothness test
|algorithms|arithmetic|
I was referring to the textbook Artificial Intelligence: A modern approach 3rd by Stuart Russell and Peter Norvig. what to prove about the general "graph search": (Here I assume "within a factor of b" means multiplier $b$ instead of [addition $\pm b$][1] based on the complexity context. So if time complexity is $O(b...
An integer is $k$-smooth if its prime factors are at most $k$. In the case where $k$ is not tiny (say $10^8 < k < 10^{10}$), are there algorithms to test for $k$-smoothness, other than trying every prime up to $k$?
The standard approach is to use a factoring algorithm designed to find small factors. The state-of-the-art algorithm for that is [elliptic curve factoring](https://en.wikipedia.org/wiki/Lenstra_elliptic-curve_factorization) (ECM). Its running time is a function of the size of the smallest factor, so it is particularl...
I was reading the NeRF paper recently (https://arxiv.org/pdf/2003.08934.pdf), and under the positional encoding section, I see that the authors propose usage of the following function for transforming the input $$ \gamma (p) = (sin(2^0 \pi p), cos(2^0 \pi p), sin(2^1 \pi p), ..., sin(2^{L-1} \pi p), cos(2^{L-1} \pi...
Explanation for the expression of positional encoding in NeRFs
|machine-learning|artificial-intelligence|neural-networks|
This question is kind of a follow-up to a [question](https://cs.stackexchange.com/questions/165395/the-complement-of-a-particular-language) asked a few days ago. Both of the non-linear complements of linear languages found were also not context free. So the question is this: Is there some linear $L$ such that $\overl...
Is there a linear language $L$ such that $\overline{L} \in \texttt{Type-2} \setminus \texttt{Lin}$?
|formal-languages|context-free|formal-grammars|linear-languages|
null
There is nothing wrong. Counting sort is definitely better in the sense of having a lower time complexity if the integers have a fixed range. And they very likely had a fixed range when you generated the data, even if you didn't realize it. But remember what a lower time complexity means: It will eventually be faste...
null
I can't understand why do we have to use NFA to prove that concatenation operation is closed. According to sisper's book it says that we can't determine where to split the string, i.e. where to determine that we now have to transition from string of one language to another language. I still don't have a clear understan...
Why can't we prove closure under concatenation using DFA?
|regular-languages|finite-automata|nondeterminism|
My only copy of Sipser is the third edition. Here is the relevant quote, after Theorem 26, closure under concatenation of the regular languages. > To prove this theorem, let’s try something along the lines of the proof of the union case. As before, we can start with finite automata $M_1$ and $M_2$ recognizing the r...
null
An integer is $k$-smooth if its prime factors are at most $k$. In the case where $k$ is not tiny (say $10^8 < k < 10^{10}$), are there algorithms to test for $k$-smoothness, other than trying every prime up to $k$? Context: (1) The largest component $p^a$ of an odd perfect number is known to be greater than $10...
Our problem is similar to [this](https://cs.stackexchange.com/questions/93959/optimal-flow-in-a-network-with-non-constant-edges-weights), but it details various approaches we can make. The problem also was formulated [operation research](https://or.stackexchange.com/questions/11603/numerical-infeasibility-for-movi...
Our problem is similar to [this](https://cs.stackexchange.com/questions/93959/optimal-flow-in-a-network-with-non-constant-edges-weights), but it details various approaches we can make. The problem also was formulated [operation research](https://or.stackexchange.com/questions/11603/numerical-infeasibility-for-movi...
null
Crank disclaimer: I don't doubt the undecidability of the halting problem, but one proof confuses me. We have seen this folklore proof of the halting problem on several occasions. Assume a HALTING SOLVER ($HS$) exists with argument program $P$ and it returns true iff $P$ halts. Let SMART PROGRAM ($SP$) do th...
What is wrong with this finite tape attack on the folklore proof of the halting problem?
|halting-problem|
Your confusion comes from not being careful enough with the quantifiers regarding the tape bound. Let's keep track of memory requirements in the construction. Let's assume that $HS$ uses up to $M(s)$ many cells of the tape for inputs of size $s$, and moreover, let us assume that the code of $HS$ has size $h$. Then $...
You are comparing apples and orange-colored bicycles here. [*Merge Sort*](https://wikipedia.org/wiki/Merge_sort) is a [*stable*](https://wikipedia.org/wiki/Sorting_algorithm#Stability) [*Comparison Sort*](https://wikipedia.org/wiki/Comparison_sort). As such, it only requires that there must be a [*Total Preorder*](h...
null
I am interested in circuits that reduce $2^n-1$ input bits into their sum, represented as an $n$ bit integers. For $n=2$, this is a full adder, which can be implemented with 5 gates of 2 inputs in various ways. Alternatively, it can be directly implemented using 2 gates of 3 inputs (a parity gate and a majority gate)...
What are the shortest circuits to sum bits?
|circuit-complexity|
Suppose I have a function $f: \mathbb{R}^n\rightarrow\mathbb{R}$. All I know about the function is, I have a set of pairs of vectors ($\vec{v}_a$, $\vec{v}_b$) for which I know which one is greater (i.e. I know that $f(\vec{v}_a)>f(\vec{v}_b)$). I want to find the minimum of the function (or at least a good approximati...
|circuit-complexity|hamming-weight|
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}]}
Given are n gene sequences (words over the alphabet {A, T, C, G}), each of length m. Find a gene sequence (of length m) that minimizes the maximum distance to all given gene sequences. Here, distance is measured as the number of positions at which the sequences differ. Show that the following problem is not efficien...
Proof Closer String/Consensus String/Center String is NP-hard
|np-complete|np|strings|p-vs-np|
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}],"DeleteType":1}
Suppose I want to prove that $NP \cap coNP = P$. Since clearly $P\subseteq NP \cap coNP$, I need to prove the opposite direction, i.e., *every* problem in $NP \cap coNP$ has a polynomial-time algorithm. Is there a shorter way to prove this equality than arguing about *all* problems in $NP \cap coNP$? One obvious way...
Proof that $NP \cap coNP = P$
|np-complete|co-np|
I am interested in circuits that reduce $2^n-1$ input bits into their sum, represented as an $n$ bit integers. For $n=2$, this is a full adder, which can be implemented with 5 gates of 2 inputs in various ways. Alternatively, it can be directly implemented using 2 gates of 3 inputs (a parity gate and a majority gate)...
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}]}
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}],"DeleteType":1}
We are all familiar with Bitonic Sort. The computations are predetermined and data-independent. [![bitonic sort][1]][1] [1]: https://i.stack.imgur.com/GrGK7.png Let's say we have a table ```A = [ 1,3,2,5,6,3,3,21 ]```. The output after performing the sort is: ```A [ 1,2,3,3,3,5,6,21 ]```. Observe that...
Is bitonic sort order preserving on keys with the same value?
|algorithms|algorithm-analysis|
No. Consider an input of $n$ ones followed by $n$ zeroes to the bitonic network. This input is only affected by the network in the middle stage, where the order of elements is flipped. Thus the elements do not keep their relative order. Rather, for this input, the order is flipped. However, the order is not fl...
A recursive bucket sort can have time complexity O(n*log(k)/log(n)). The space needed is O(n).
I am trying the understand the following statement from the book of Grotschel, Lovasz and Schrijver: [![enter image description here][1]][1] They define an optimization problem whose solution is a nonnegative real vector. If we add a constraint that all elements of the vector must be integers, then the problem is...
How does the half-integer spanning-tree problem contain the TSP?
|reductions|minimum-spanning-tree|traveling-salesman|
I am working on a problem that involves distributing a set of N supplements across a predefined number of meals (M) in a way that maximizes the total number of positive interactions and minimizes negative interactions between the supplements. Each interaction between the supplements is known beforehand (positive, neutr...
Covering a graph with M cliques maximizing total edges weight
|algorithms|graphs|optimization|combinatorics|partitions|
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}]}
null
Worst-case bounds on running time are usually not very informative for SAT solvers. In particular, on problem instances that arise in practice, often SAT solvers run a lot faster than the bounds would suggest. And the bounds are not very informative at helping us choose between two solvers or two algorithms, or ident...
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...
Theoretical origin of acquire semantics only for reads?
|concurrency|synchronization|theory|
You can't. The function could be anything. For example, consider $$f(x) = \begin{cases} g(x) &\text{if }x \ne \alpha\\ -10^{100} &\text{if } x = \alpha \end{cases}$$ where $\alpha \in \mathbb{R}^n$ is some obscure point (maybe very far from the origin). Then any reasonable algorithm might never evaluate $f$...
So far we don't know of any problem that can be proven to be complete for $NP \cap coNP$. See https://cstheory.stackexchange.com/q/49/5038 and https://mathoverflow.net/q/34889/37212 for extended discussion of some of the challenges, related results, and a few entry points into the literature. Related: https://cs.st...
One approach is to solve this with tools from operations research and combinatorial optimization, and specifically, to view this as an instance of ILP or SAT. Let $x_{c,i}$ be a variable that will be true (i.e., 1) if supplement $i$ is assigned to meal $c$, or false (0) otherwise. Let $y_{c,i,j} = x_{c,i} \land x_{...
I was referring to the textbook Artificial Intelligence: A modern approach 3rd by Stuart Russell and Peter Norvig. what to prove about the general "graph search": (Here I assume "within a factor of b" means multiplier $b$ instead of [addition $\pm b$][1] based on the complexity context. So if time complexity is $O(b...
We know that $\widetilde{O}(f(n))$" — $O$ with a tilde above it — which means $O(f(n) \text {polylog}(f(n)))$, i.e., $O(f(n) (\log f(n))^k)$ for some $k$. Also I have seen in [Wikipedia](https://en.m.wikipedia.org/wiki/Big_O_notation) that $n2^n=\widetilde{O}(2^n).$ My question is that if $poly(n)2^{xn}=2^{yn}$ ...
What is the difference between $O$ and $\widetilde{O}$?
|asymptotics|big-o-notation|polynomials|
We know that $\widetilde{O}(f(n))$ — $O$ with a tilde above it — which means $O(f(n) \text {polylog}(f(n)))$, i.e., $O(f(n) (\log f(n))^k)$ for some $k$. Also I have seen in [Wikipedia](https://en.m.wikipedia.org/wiki/Big_O_notation) that $n2^n=\widetilde{O}(2^n).$ My question is that if $\text{poly}(n) \space 2...
We know that $\widetilde{O}(f(n))$ — $O$ with a tilde above it — which means $O(f(n) \text {polylog}(f(n)))$, i.e., $O(f(n) (\log f(n))^k)$ for some $k$. Also I have seen in [Wikipedia](https://en.m.wikipedia.org/wiki/Big_O_notation) that $n2^n=\widetilde{O}(2^n).$ My question is that if $\text{poly}(n) \space 2...
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...
null
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...
**Preface** (long): Letʼs consider an inter-processor synchronization using a pure spinlock (avoid queues and task switching). While a spinlock is held, the data protected by it can be read or written. All these operations shall be finished (reads - values moved to the processor, writes - values exposed to other pro...