instruction stringlengths 0 29.8k ⌀ |
|---|
Consider normalized DFT (discrete Fourier transform) — a transform with input $x = (x_0,\dots,x_{n-1})$ and output $y=(y_0,\dots,y_{n-1})$ s.t.
$$y_j = \frac1{\sqrt{n}} \sum_{l=0}^{n-1} x_l \omega^{jl}, \tag{1}$$
where $\omega$ is a primitive $n$-th root of unity (e.g. $\omega = e^{-2\pi i/n}$). It is described by a ... |
Can FFT for prime $n$ be implemented as a composition of $O(n\log(n))$ $2\times 2$ unitaries? |
|algorithms|complexity-theory|computation-models|fourier-transform|fast-fourier-transform| |
Scheduling jobs with the same release time and different due dates on a single machine |
Can FFT for prime $n$ be implemented as a product of $O(n\log(n))$ $2\times 2$ unitaries? |
null |
The concept of [reinforcement learning][1] is what you're looking for.
> Reinforcement learning (RL) is an area of machine learning concerned with how intelligent agents ought to take actions in an environment in order to maximize the notion of cumulative reward.
As for code examples, [this collection of algorith... |
You may want to have a look at [SCCharts](https://github.com/kieler/semantics/wiki/Syntax), which extend FSMs (a.o.) with hierarchy and named sub-machines. |
null |
null |
[Equivalence](https://en.wikipedia.org/wiki/Logical_equivalence): Not every SAT instance can be expressed as a system of linear equations. For instance, $x_1 \lor x_2$ cannot be expressed as a system of linear equations.
(Why not? Systems of linear equations have the following property: if $x_1,x_2$ is a solution ... |
# Use local moves: rotations and local swaps
You can use 2 moves: rotations and local swaps. Both can be implemented in $O(1)$ assuming you keep a list of pointers to all non-leaf nodes and each node has 3 pointers: parent, left, and right.
## Rotation
1. Pick any non-leaf non-root node `B`.
2. Let `A = *B.pare... |
Consider normalized DFT (discrete Fourier transform) — a transform with input $x = (x_0,\dots,x_{n-1})$ and output $y=(y_0,\dots,y_{n-1})$ s.t.
$$y_j = \frac1{\sqrt{n}} \sum_{l=0}^{n-1} x_l \omega^{jl}, \tag{1}$$
where $\omega$ is a primitive $n$-th root of unity (e.g. $\omega = e^{-2\pi i/n}$). It is described by a ... |
I was exploring a problem of label flipping in the target column:
**Problem:**
I have a data frame with just two columns: *Predicted probability* | *Target*. *Target* column is binary (contains only 0 and 1) --- the actual target values. *Predicted probability* column contains outputs from my model. I calculate the... |
Impact of label flipping on ROC-AUC score |
|machine-learning|statistics|performance| |
I was exploring a problem of label flipping in the target column:
**Problem:**
I have a data frame with just two columns: *Predicted probability* | *Target*. *Target* column is binary (contains only 0 and 1) --- the actual target values. *Predicted probability* column contains outputs from my model. I calculate the... |
null |
Are there (interesting) situations where we can decrease the time complexity of a program by increasing its ordinal complexity?
For example, is it possible to find a primitive recursive function such that:
- The fastest primitive recursive program to compute it runs in $O(f(N))$.
- The fastest non primitive recu... |
Are there situations where we can decrease the time complexity of a program by increasing its ordinal complexity? |
|complexity-theory|time-complexity|turing-machines|recursion|primitive-recursion| |
Are there (interesting) situations where we can decrease the time complexity of a program by increasing its ordinal complexity?
For example, is it possible to find a primitive recursive function such that:
- The fastest primitive recursive program to compute it runs in $O(f(N))$.
- The fastest non primitive recu... |
Let us assume, we have a FSM (to be precise, an epsilon-NFA) in which I've got redundant structures.
I am looking for a framework that allows to factor out the redundant part into some kind of subautomaton, respectively a more canonical representation and naming of this kind of NFA.
As illustration I've got the... |
This is not very awesome trick but demonstrates usage of `\G` construct supported in Java regex - zero-width match at position where last match was found.
Example: how to insert separator after every three characters:
```
"abcdefgh".replaceAll("(?<=\\G.{3})"," ")
```
yields
```
"abc def gh"
```
|
null |
How to find an algorithm to calculate the best move for this graph based strategy game? |
null |
```
int q(int n)
{
if (n <= 0) return 0;
return 1-q(q(n-1));
}
```
I'm not sure how to approach this. I tried representing the time complexity as a function $T(n)$ and then use repeated substitutions:
So I got $T(n)=C+T(T(n-1))$ where $C$ is a constant representing a constant amount of lines we ... |
Time complexity of function |
|time-complexity| |
First observe $q(n)$ always returns either $0$ or $1$. This can be proven formally by induction.
If $n \le 0$ this is immediate. If $n=1$ then the return value is $q(q(0)) = 1-q(0) = 1$.
Suppose now that the claim holds up to some $n \ge 1$ and consider $q(n+1)$.
The return values is $1-q(q(n))$ which is either $... |
First observe $q(n)$ always returns either $0$ or $1$. This can be proven formally by induction.
If $n \le 0$ this is immediate. If $n=1$ then the return value is $q(q(0)) = 1-q(0) = 1$.
Suppose now that the claim holds up to some $n \ge 1$ and consider $q(n+1)$.
The return value is $1-q(q(n))$ which is either $1... |
I wanted to ask a simple question:
Assume I have a function whose time complexity is given by the following function:
$T(n)=\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+...+\frac{1}{n^2}$.
Would it be correct to say that the time complexity of the function is $Θ(1)$ because $T(n)$ is represented by a convergent series? |
Time complexity of a convergent series |
|time-complexity| |
The literature that I have reviewed shows examples of calculations of known approximation algorithms such as the Christofides' algorithm for the TSP. However, I have not been able to find information regarding the calculation of the approximation factor of an algorithm that has a loop inside. Is this possible? Does som... |
Calculating approximation factor of an algorithm with a while loop |
|algorithms|approximation|traveling-salesman| |
For every sufficiently large $n$ (here $n \ge 1$ suffices), $T(n)$ is both lower bounded by a positive constant (e.g., $1$) and upper bounded by another positive constant (e.g., $\pi^2/6$). Therefore it is correct to say that $T(n) = \Theta(1)$. |
Jeff Ericson in his ["Algorithms"](https://jeffe.cs.illinois.edu/teaching/algorithms) states three conditions:
1. **Greedy choice:** There is an optimal solution that includes the choice the algorithm makes.
2. **Inductive structure:** The smaller subproblem that remains after fixing the choice by the algorithm i... |
There is a very nice theory on when greedy algorithms work in general. It is based on the abstract concept of matroids. A detailed [explanation](https://jeremykun.com/2014/08/26/when-greedy-algorithms-are-perfect-the-matroid) is given by Jeremy Kun. |
A common issue with CPU performance is that pipelining requires the knowledge of what will come next, and what comes next can only be known once a branch condition is evaluated, so that instructions in the branch can be preloaded.
As such, CPUs employ branch predictors to predict which branch will be taken so that t... |
Can a branch be pipelined with certainty if the branch condition can be known significantly before the actual branch? |
|cpu|cpu-pipelines| |
null |
Try to systematically reformulate the query into tuple calculus.
This is effectively a normalization operation on the natural language statement. Recasting it into tuple calculus makes it much longer, but unambiguous and much closer to relational algebra.
Use the fact that $\forall = \neg\exists\neg$.
Once you'... |
Try to systematically reformulate the query into [tuple calculus][1] (or [domain calculus][2]).
This is effectively a normalization operation on the natural language statement. Recasting it into tuple calculus makes it much longer, but unambiguous and much closer to relational algebra.
Use the fact that $\forall... |
Okay, as discussed in the comments, I will be assuming that the programming language has something like a "break" statement, which completely skips all the remaining iterations of a loop, spending $O(1)$ time on them, no matter how many iterations were remaining.
Let $M$ be an abstract machine (a Turing machine, a R... |
null |
You have at least the following 2 options.
## Option 1: use local moves
You can use 2 moves: rotations and local swaps. Both can be implemented in $O(1)$ assuming you keep a list of pointers to all non-leaf nodes and each node has 3 pointers: parent, left, and right.
### Rotation
1. Pick any non-leaf non-root ... |
The literature that I have reviewed shows examples of calculations of known approximation algorithms such as the Christofides' algorithm for the TSP. However, I have not been able to find information regarding the calculation of the approximation factor of an algorithm that has a loop inside. Is this possible? Does som... |
Calculating approximation factor of a TSP algorithm |
Various PowerPCs had a count register that was part of the branch unit, with an instruction “decrement and branch if non-zero”. Setting the count register had significant latency, but the “decrement and branch if non-zero” was _not_ predicted. The processor handled it like an unconditional branch. Or like a no-operatio... |
The literature that I have reviewed shows examples of calculations of known approximation algorithms such as the Christofides' algorithm for the TSP. However, I have not been able to find information regarding the calculation of the approximation factor of an algorithm that has a loop inside as the one in the example b... |
A common issue with CPU performance is that pipelining requires the knowledge of what will come next, and what comes next can only be known once a branch condition is evaluated, so that instructions in the branch can be preloaded.
As such, CPUs employ branch predictors to predict which branch will be taken so that t... |
It is great if you can construct cases where the optimal solution is known. In that case generate a million cases and check if they find the expected result.
Or find a mate who implements a different algorithm independently. Generate a million random cases with no known result, run both algorithms, and every time y... |
I'm working my way through the graph section of *Introduction to Algorithms* by CLRS (3e.) and I came across the following proof:
**Lemma 22.2**
Let $G = (V, E)$ be a directed or undirected graph, and suppose that BFS is run on $G$ from a given source vertex $s \in V$. Then upon termination, for each vertex $v \i... |
Confusion about Lemma for Breadth-first search (BFS) proof of correctness |
|algorithms|graphs|graph-traversal|breadth-first-search| |
I'm working my way through the graph section of *Introduction to Algorithms* by CLRS (3E,4E) and I came across the following proof:
**3E: Lemma 22.2**
Let $G = (V, E)$ be a directed or undirected graph, and suppose that BFS is run on $G$ from a given source vertex $s \in V$. Then upon termination, for each vertex... |
Various PowerPCs had a count register that was part of the branch unit, with an instruction “decrement and branch if non-zero”. Setting the count register had significant latency, but the “decrement and branch if non-zero” was _not_ predicted. The processor handled it like an unconditional branch. Or like a no-operatio... |
Consider normalized DFT (discrete Fourier transform) — a transform with input $x = (x_0,\dots,x_{n-1})$ and output $y=(y_0,\dots,y_{n-1})$ s.t.
$$y_j = \frac1{\sqrt{n}} \sum_{l=0}^{n-1} x_l \omega^{jl}, \tag{1}$$
where $\omega$ is a primitive $n$-th root of unity (e.g. $\omega = e^{-2\pi i/n}$). It is described by a ... |
The [delay slot][1] is one realisation of this idea. On many first-generation RISC CPUs (e.g. MIPS, PA-RISC, SPARC), the next instruction after a branch is *always* executed. Some special-purpose machines (e.g. DSP) have *multiple* delay slots. If no useful work can be done, the instructions following a branch can be f... |
To answer this conclusively, we'd need to know more about how you intend to describe your NFAs with (named?) sub-NFAs.
If the directed graph obtained by having your (sub-)NFAs as nodes and your dashed arrows as directed edges has no cycles, then a copy semantics would necessarily give a finite traditional NFA and re... |
No, unless P=NP.
Cook-Levin showed SAT is an NP-complete problem. Solving a system of linear equations is a polynomial time problem. Also, Schaefer's Dichotomy Theorem says that SAT problems can divided into P or NP-complete classes.
cf. [*Introduction to Mathematics of Satisfiability*][1]
[1]: https://isi... |
null |
null |
null |
I was exploring a problem of label flipping in the target column:
**Problem:**
I have a data frame with just two columns: *Predicted probability* | *Target*. *Target* column is binary (contains only 0 and 1) --- the actual target values. *Predicted probability* column contains outputs from my model. I calculate the... |
You can do these observations:
- $n\le0\to0$;
- $n=1\to1-q(q(0))=1-q(0)=1$;
- $n=2\to1-q(q(1))=1-q(1)=0$;
- $n=3\to1-q(q(2))=1-q(0)=1$;
- $n=4\to1-q(q(3))=1-q(1)=0$;
- $\cdots$
The pattern is obvious. From this, a call for $n>0$ involves $2n$ recursive calls (of which the last two are with argument... |
You can do these observations:
- $n\le 0\to q(n)=0$;
- $n=1\to q(n)=1-q(q(0))=1-q(0)=1$;
- $n=2\to q(n)=1-q(q(1))=1-q(1)=0$;
- $n=3\to q(n)=1-q(q(2))=1-q(0)=1$;
- $n=4\to q(n)=1-q(q(3))=1-q(1)=0$;
- $\cdots$
The pattern is obvious. From this, a call for $n>0$ involves $2n$ recursive calls (of which... |
{"Voters":[{"Id":16034,"DisplayName":"Yves Daoust"}],"DeleteType":1} |
You can do these observations:
- $n\le 0\to q(n)=0$;
- $n=1\to q(n)=1-q(q(0))=1-q(0)=1$;
- $n=2\to q(n)=1-q(q(1))=1-q(1)=0$;
- $n=3\to q(n)=1-q(q(2))=1-q(0)=1$;
- $n=4\to q(n)=1-q(q(3))=1-q(1)=0$;
- $\cdots$
The pattern is obvious. From this, a call for $n>0$ involves $2n$ recursive calls of which ... |
{"Voters":[{"Id":16034,"DisplayName":"Yves Daoust"}]} |
Let $G = (V, E)$ be a graph with edge weights $w: E \rightarrow \mathbb{R} \cup \{\infty\}$.
Let $P := \{(a_i, b_i, w_i)\}$ be a set of tuples of nodes $a_i, b_i \in V$ with shortest distance $w_i$ from $a_i$ to $b_i$.
We want to update the weights of a subset of edges $E' \subseteq E$, and then efficiently update ... |
How to compute the updated shortest paths given a set of edge insertions efficiently? |
|shortest-path| |
|graphs|shortest-path| |
|graphs|shortest-path|dynamic-graphs| |
null |
null |
|graphs|shortest-path|dynamic-graphs|dynamic-algorithms| |
null |
null |
|algorithms|graphs|optimization|shortest-path|dynamic-algorithms| |
|graphs|data-structures|shortest-path|efficiency|dynamic-algorithms| |
null |
null |
I occurred this in [this problem][1].
You can submit your code in the online judge.
[1]: https://ac.nowcoder.com/acm/contest/65157/F |
{"Voters":[{"Id":156238,"DisplayName":"138 Aspen"}],"DeleteType":1} |
Is it possible for a language (or machine or system) to be universal or turing complete, when there is no possibility to write a program for it that halts?
Lets say we create a new language, brainfuck-nonstop, that like brainfuck with a single change: When the program pointer reaches the end, it goes back to the sta... |
Does a language/maschine/system need to be able to halt to be universal? |
|turing-completeness| |
Consider two large numbers $a$ and $b$ of which some, not necessarily prime factors, are known. This means $a = a_1 \cdot \dots \cdot a_n$ and $b = b_1 \cdot \cdots \cdot b_m$. Interest lies in their quotient
$$
\frac a b = \frac {a_1 \cdots a_n} {b_1 \cdots b_m}
$$
of which is also known that it is a (positive) in... |
Division of Large Numbers with Known Factors |
|algorithms|reference-request|arithmetic| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.