instruction stringlengths 0 29.8k ⌀ |
|---|
any reference on what kind of problem it is and what algorithm can solve this in $n^2\log n$?
for 5 as d, the numbers 4 and 3 and 0 would work. so i think there should be zero in the array.
maybe use naive approach($O(n^4)$) memoize the raising to power 2 and adding up the results to decrease the running time?
... |
any reference on what kind of problem it is and what algorithm can solve this in $n^2\log n$?
for 5 as d, the numbers 4 and 3 and 0 would work. so i think there should be zero in the array.
maybe use naive approach($O(n^4)$) and memoize the raising to power 2 and adding up the results to decrease the running tim... |
null |
null |
null |
null |
# Question Background
A finite-state machine can be defined as a 5-tuple as follows (Sipser, pg. 35):
[![Definition of Finite Automaton][1]][1]
The image below (taken from [the Wikipedia article on combinational logic][2]) seems to suggest that combinational logics can be used to define formal grammars that de... |
What is the formal definition of a combinational logic? |
|formal-languages|automata|formal-grammars|regular-expressions|computation-models| |
The reason for simple paths for the longest path problem is simple (pun not intended):
- either there is a cycle of positive weight, and therefore the longest path is not really defined as it could have an infinite weight;
- or all cycles have non-positive weight, and the longest path is a simple path.
As for weig... |
# Question Background
A finite-state machine can be defined as a 5-tuple as follows (Sipser, pg. 35):
[![Definition of Finite Automaton][1]][1]
The image below (taken from [the Wikipedia article on combinational logic][2]) seems to suggest that combinational logics can be used to define formal grammars that de... |
Yes, the problem is in $\mathbf{P}$. For every vertex $u\in A$, let $M(u)$ be the set of the two vertices in $B$ that is connected with $u$. For every vertex $v\in B$, let $N(v)=\{u\in A|(u,v)\in E\}$. We construct another undirected graph $G'=(V',E^*)$, whose vertex set is $V'=B$. For every $v_1,v_2\in B\,(v_1\ne v_2)... |
null |
null |
null |
The OP has indicated in the comments that they are only interested in a specific time $t$. De Casteljau's algorithm can be described as follows:
- Input: order $N$, points $A_0,\ldots,A_N$, time $t \in (0,1)$.
- Calculate $\overline{A_i A_{i+1}} = A_i(1-t) + A_{i+1}t$ for $0 \leq i \leq N-1$.
- Calculate $\overlin... |
Direct evaluation of the Bernstein polynomials can be done in time linear in $N$, using the recurrence
$$B(t;i,N)=\frac t{1-t}\frac{N-i+1}iB(t;i-1,N),\\B(t;0,N)=(1-t)^N.$$
This can be used to compute the interpolant in time $O(N)$, with $O(1)$ temporary storage. |
I came across this question when studying for an exam:
given a min-heap that has no primary numbers in it, is there an algorithm that can get and delete the minimum of that heap in O(log* n) ?
The answer simply said no because in this case we can sort an array in o(n log n) which we’ve learned isn’t possible ... |
Is there an algorithm that can get the minimal element of a min-heap in O(log* n)? |
|data-structures|sorting|arrays|heaps| |
I am a research scholar, and I currently work in parameterized algorithms. My current work involves proving that a problem is FPT for the parameter *distance to clique*. Although it is known that computing a *distance to clique* of size $k$ can be done in FPT time using a simple branching algorithm, I couldn't figure o... |
Computing distance to clique in FPT time |
|np-hard|parameterized-complexity| |
null |
I came across this question when studying for an exam:
given a min-heap that has no prime numbers in it, is there an algorithm that can get and delete the minimum of that heap in O(log* n) ?
The answer simply said no because in this case we can sort an array in o(n log n) which we’ve learned isn’t possible wi... |
I came across this question when studying for an exam:
given a min-heap that has no prime numbers in it, is there an algorithm that can get and delete the minimum of that heap in O(log* n) ?
The answer simply said no because in this case we can sort an array in o(n log n) which we’ve learned isn’t possible wi... |
I came across this question when studying for an exam:
given a min-heap that has no prime numbers in it, is there an algorithm that can get and delete the minimum of that heap in O(log* n) ?
The answer simply said no because in this case we can sort an array in o(n log n) which we’ve learned isn’t possible wi... |
null |
It took some time but I finally found how to derive the above equation. This thing requires the knowledge of continuous Markov chains. I learned about them from these two videos which was enough to understand the concept.
* [Video 1][1]
* [Video 2][2]
Now the derivation is [here on Wikipedia][3]. Basically, our ... |
null |
Because **users** of matrices think in terms of the matrix _dimensions_ rather than the number of elements. Because that's related to the "size" of their problem in some way. E.g., you have _n_ linear equations to solve, you're working in an _n_-dimensional space, ...
IOW matrices aren't interesting to work with a... |
One aspect I'd like to stress in addition to the other answers (already covered to some extent there):
With the `O(n)` notation we express how the run time / memory consumption / ... changes if we change the "input size". But it's completely up to you how you define the term "input size", so you have to document thi... |
null |
null |
Consider the following full hypergraph $H$ (or [abstract simplicial complex](https://en.wikipedia.org/wiki/Abstract_simplicial_complex)) of dimension $2$, represented as a simplicial complex (nodes are in black, $2$-edges in red, $3$-edges are turqoise triangles):
[![enter image description here][1]][1]
(or, algebr... |
There are n! permutations how an array of n numbers could be arranged. To sort an array, you need to rearrange items so that they are in sorted order, and for every permutation a different rearrangement is needed. Every decision you make cuts the number of possibilities by half in the best case. Therefore any compariso... |
Since you are asking in Computer Science, I very much recommend George Dantzig's "Linear Programming and Extensions". It explains linear programming in a way that a normal human being (like me) can understand. The link has links to three .pdf files of this book.
https://www.rand.org/pubs/reports/R366.html
PS. D.W... |
I just copied my answer from a similar question: Since you are asking in Computer Science, I very much recommend George Dantzig's "Linear Programming and Extensions". It explains linear programming in a way that a normal human being (like me) can understand. The link has links to three .pdf files of this book.
https... |
In Strassen's algorithm, we calculate the time complexity based on n being the number of rows of the square matrix. Why don't we take n to be the total number of entries in the matrices (so if we were multiplying two 2x2 matrices, we would have n = 8 for the four entries in each matrix)?
Then, using the naïve method ... |
null |
You don't memoize "raising to the power of two". Looking up these powers in a table will take ten times longer than just multiplying.
You want $d^2 = a^2 + b^2 + c^2$ or $d^2 - a^2 = b^2 + c^2$.
You take all pairs of two integers x, y in the array and calculate x^2 + y^2 and store that into array A, and calcula... |
If only single precision arithmetic is available:
You replace a with a mod 360, and b with b mod 360. That can be done _exactly_. You can force a, b into the ranges -180 <= a, b <= +180.
Calculating (a * b) mod 360 would have a huge rounding error. Single precision standard floating point has a 24 bit mantissa. ... |
null |
I misunderstood what you meant by distance to clique.
Take the complement graph $\overline G$ of $G$. Then what is $D$ called? What is $V \setminus D$ called? |
null |
I'm reading Nielsen and Chuang. On page 142 the integer factoring decision problem is introduced: The integer factorization problem can be reduced to a decision problem:
Given a composite integer m and l < m, does m have a non-trivial
factor less than l?
For a given witness x < l this problem can be checked in ... |
Integer factorization: Why can't we use the test algorhitm to create an algorhitm to decide the factoring decision problem in polynomial time? |
|decision-problem| |
We have a weighted and undirected graph.
I want to find the shortest path between two vertices with Dijkstra algorithm.
But in the path, the weight of the edges should be increased and decreased one by one.
For example, in the below graph, the answer is the third path:
[![enter image description here][1]][1]
My ... |
find the shortest path between two vertices with Dijkstra (Increase and deacrese wieght one by one) |
|graphs|shortest-path|weighted-graphs|dijkstras-algorithm| |
I think I found the solution by myself: It is called Pseudo-polynomial time - the time scales polynomial in the value of the number but not in the length. |
Some integer multiplication algorithms do use lookup tables.
The [IBM 1620 Model I "CADET"][1] lacked a conventional ALU:
addition and subtraction used a 100 digit table; multiplication used a 200 digit table. (Many joked that CADET stood for "Can't Add, Doesn't Even Try").
The [IBM 1620 Model II][2] had a simpl... |
Is there a well-known algorithm for modular multiplication of floating-point numbers?
I would like to multiply some large angle in single precision (6-7 significant digits) and wrap it back to 360 degrees, without losing too many significant digits.
float r = fmodf(a * b, 360);
My current approach is to sp... |
If $\sum_{i=0}^{n-1}b_i>k\sum_{i=0}^{n-1}a_i$ then $b_n = \lfloor ka_n\rfloor$, else $b_n = \lceil ka_n \rceil$. This requires only one pass through $\{a_n\}$. |
I'm trying to solve this time complexity: ()=2(−2)+ but having some challenges addressing the (-2) component. Any insights on this complexity?
Ended up with a section [2^2(1) + 2^(3)(2) + 2^(4)(3) +... + 2^(k+1)(k)]. Does it follow any existing number series?
Thanks. |
Algorithm Asymptotic Analysis |
|time-complexity|recurrence-relation| |
In SQL: Use the GROUP BY and COUNT operators. |
null |
The backstory
-------------
I have spectrograms of certain repeating sounds. The background of the spectrograms are black and could easily be made transparent if that would help. The sounds are easily distinct from the background. As shown below, each sound is a series of connected pixels of various colors.
![ex... |
null |
The $r$ first rows include $T_r=\dfrac{r(r+1)}2$ elements and the linear index corresponding to $(r,c)$, with $0\le c\le r$, is $i:=T_r+c$.
The $T_r$ are called the *triangular numbers*.
----------
Retrieving the row and column from the linear index is a little more tricky.
For given $i$, we have
$$\frac... |
null |
I am creating a tool for validating, parsing, and interpreting flowchart diagrams on [diagrams.net][1], and it is necessary to give users an opportunity to define a set of rules for the diagram. So, in the end, I want to achieve something like ANTLR for diagrams with the following features:
- Some kind of DSL for d... |
null |
I am creating a tool for validating, parsing, and interpreting flowchart diagrams on [diagrams.net][1], and it is necessary to give users an opportunity to define a set of rules for the diagram. So, in the end, I want to achieve something like ANTLR for diagrams with the following features:
- Some kind of DSL for d... |
The problem statement is pretty straightforward: given an array of integers and a window size, return an array of doubles of the median of each window.
$arr = 1, 3, 5, 10, 6, 9, 2$ and $k = 3$ would yield a result of $3, 5, 6, 9, 6$.
Using [std::priority_queue][1] (in C++) for the heap implementation, there's a *... |
null |
so this is the question , I have to minimize this DFA
[![enter image description here][1]][1]
this is How I did it
[![][2]][2]
but when I checked for answers , this is what it was,
[![enter image description here][3]][3]
can someone please explain to me what mistake I made? I have been wondering about t... |
find the minimization of the dfa |
|automata|finite-automata|compilers| |
null |
As the title states, given a bipartite undirected graph $G=(X\cup Y,E)$ where $|X|=|Y|=n$ and every vertex $v\in V$ satisfies $d(v)=k$
The general goal of the proof is to show that under these terms, the graph has a perfect matching (a subset of edges where all edges are disjoint in vertices, and the edges in said s... |
Proving that for a bipartite graph with $d(v)=k$for $\forall v\in V$ , $|S|\leq|n(S)|$ $\forall S\subseteq V=X\cup Y$ |
|matching|bipartite-matching|bipartite-graph| |
**Hint:**
Set $n=2m$ and the recurrence turns to
$$T(2m)=2T(2(m-1))+2m$$ which can be written like a usual recurrence
$$S(m)=2S(m-1)+2m.$$
After solving for $S(m)$, you get $T(n)=S(\frac n2)$.
----------
As the recurrence only involves numbers of the same parity, there are in fact two independent seq... |
Suppose $S\subseteq V$.
Consider all edges with one endpoint in $S$ (and the other endpoint of course in $n(S)$), i.e., $E_S=\{(s,t): (s,t)\in E, s\in S\}$. Since $d(v)=k$ for all vertex $v$, we have
$$ |E_S| = k|S|.$$
Consider all edges with one endpoint in $n(S)$, i.e, $E_{n(S)}=\{(s,t): (s,t)\in E, t\in n(s)\... |
As the title states, we are given a bipartite undirected graph $G=(X\cup Y,E)$ such that every vertex $v\in V$ satisfies $d(v)=k$ for a constant $k$.
The general goal of the proof is to show that under these terms, the graph has a perfect matching (a subset of edges where all edges are disjoint in vertices, and the ... |
For a regular bipartite graph with vertices $X\cup Y$, prove that $|S|\leq|n(S)|$ $\forall S\subseteq X$ |
Suppose $S\subseteq X$. Then $n(S)\subseteq Y$.
Consider all edges with one endpoint in $S$.
Since there are $k$ edges that start with any particular point in $S$ and all these edges are different for points in $S$, the number of those edges is $k|S|$.
Similarly, the number of all edges with one endpoint in $... |
## General description ##
I have an optimization problem in which I need to schedule events and each of the events needs to be scheduled exactly once. The "cost" of scheduling one event depends on all of the events that have been scheduled before. So given a list of events $[e_1, e_2, ... e_n]$, the goal is to find ... |
None of these two automata is correct. The main reason is the following:
**You forgot the INITIAL STATE and the FINAL STATE.**
Please, don't forget to indicate those, this is a very common mistake, but without those, a correct automaton becomes an incorrect automaton.
Otherwise, the automaton seems correct, an... |
**Hint:**
Set $n=2m$ and the recurrence turns to
$$T(2m)=2T(2(m-1))+2m$$ which can be written like a usual recurrence
$$S(m)=2S(m-1)+2m.$$
After solving for $S(m)$, you get $T(n)=S(\frac n2)$.
----------
As the recurrence only involves numbers of the same parity, there are in fact two independent seq... |
null |
A lookup table for integer entries up to $n$ has size $O(n^2\log n)$. For $b$ bits numbers, this is $O(b\,2^{2b})$.
FFT's are usually implemented with double precision floating-point arithmetic. With proper scaling, fixed-point and sacrificing a lot of accuracy, you might do with $b=20$ or so ($50$ Gb)... |
If I understand you correctly, it seems like the solution is to simply skip the frontier nodes that does not conform to the condition you have described.
> My idea: Remove the paths that do not meet the condition of the problem and then find the shortest paths with Dijkstra
I think you're on the right direction. ... |
null |
Consider the [Kadane's algorithm][1] for finding maximum subarray within an array:
def max_subarray(numbers):
"""Find the largest sum of any contiguous subarray."""
best_sum = 0
current_sum = 0
for x in numbers:
current_sum = max(0, current_sum + x)
... |
Does an algorithm's space complexity include input? |
|algorithms|space-complexity|python|space-analysis| |
I am a research scholar currently working in parameterized algorithms. I am studying the complexity of the problem (say $P$) for $\Delta_{10}$ graphs and was able to provide a reduction from a known NP-complete problem. Here, i have that $P$ is NP-complete on $\Delta_{10}$ graphs. It is obvious that there is no FPT alg... |
Constant value NP-complete vs W[1]-hard |
|np-hard|parameterized-complexity| |
It depends on the chosen convention. I often prefer the convention that considers that the input is not part of the space complexity, for different reasons:
- the space complexity of a function answer the question "do I have enough memory to finish my computation?". In that aspect, I consider that when calling a fu... |
Suppose I would like to generate n clauses, in 3-CNF form, that would give a unique solution for m variables (m<n).
Example: for m=6, I've got **{a,b,c,d,e,f} = 111010**
How to generate these n 3-CNF clauses while minimizing this number of clauses (to avoid redundancies)?
What would be the minimum number of clau... |
Generate a minimum number of clauses in 3-CNF form that give a unique solution |
|3-sat| |
I am a research scholar currently working in parameterized algorithms. I am studying the complexity of a problem (say $P$) for $\Delta_{10}$ graphs and was able to provide a reduction from a known NP-complete problem. Hence, i have that $P$ is NP-complete on $\Delta_{10}$ graphs. It is obvious that there is no FPT (fix... |
For simplicity, I assume that such a clause contains exactly $3$ litterals, and that those litterals are on different variables.
To create such a clause, you can do the following:
- choose the $3$ variables that appear in the clause. There are $\binom{m}3$ such choices;
- there are $2^3=8$ possibilities to creat... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.