instruction
stringlengths
0
29.8k
⌀
|database-theory|databases|
Problem definition ------------------ I have a directed graph $G = (V,E)$, with positive weights $w(e)>0\:s.t\:\forall e \in E$ I would like to find the longest walk (i.e. edges and nodes may be repeated) in terms of most accumulated weight, under the condition that once an edge $e$ is traversed, its weight wil...
Longest (weight-wise) walk In a directed graph with weights becoming negative after traversing once
|algorithms|graphs|weighted-graphs|
Without any special knowledge about the distribution of data, you cannot do better than that. In the worst case, you have to read every element of $B$. There can be $\Theta(n)$ elements of $B$. So, every correct algorithm must take at least $\Omega(n/\log n)$ time in the transdichotomous model, where you can read an...
null
A Reed-Solomon code applied to 512-byte (4096-bit) sectors can support up to $n=2^{4096}$ drives in an array, of which any fraction may be parity drives. The limits of real-world RAID setups come from practical considerations, not theory. RAID can defend against the random failure of up to $t$ drives, but it can't d...
null
Given two sequences $ a = (a_1, a_2, ..., a_n)$ and $b = (b_1, b_2, ..., b_n)$ you define the similarity $S(a,b)$ as : $$S (a,b) = \frac{1}{n}\sum_{k=1}^{n} \frac{|(\{a_i | i \in [1,k]\} \cap \{b_i | i \in [1,k]\}|}{k}. $$ If instead you had $$S(a,b) = \frac{1}{n}\sum_{k=1}^{n} \frac{|(\{a_i | i \in [1,k]\...
null
Given an array $A=\{\frac{S_1}{K_1},\frac{S_2}{K_2},...,\frac{S_n}{K_n}\}$ whose any $S_i$ and $K_i$ are positive floating-point, and an positive floating-point $R$, how to select a set of element $C=\{\frac{S_{p_1}}{K_{p_1}},\frac{S_{p_2}}{K_{p_2}},...,\frac{S_{p_m}}{K_{p_m}}\}$ such that the absolute value of the dif...
How to select a subset from the array $A=\{\frac{S_1}{K_1},\frac{S_2}{K_2},...,\frac{S_n}{K_n}\}$ such taht the subset can meet this requirement?
|algorithms|
null
Hint: Try the special case where $K_1=K_2=\cdots=K_n$. What can you say about that case?
The special case where $K_1=K_2=\cdots=K_n$ is as hard as the subset-sum problem, which is NP-hard -- so your problem is NP-hard as well. A plausible approach is to use integer linear programming. Let $x_i$ be a zero-or-one integer variable. You are looking for $x_i$ such that $$-\epsilon \sum_i x_i K_i \le \su...
I designed an algorithm where, at some point, I need to compute the product of a list of integers $n_1,\dots,n_m$ (possibly, there are repetitions in the list). The integers themselves do not depend on $m$ but can be, somehow, arbitrarily large. When analyzing the algorithm, I wondered whether I should - or not - co...
Complexity of multiplication when computing product of $m$ integers
|complexity-theory|time-complexity|integers|multiplication|
if we have $f(n)=f(n-7)$ and $f(2)=3$ can we conclude that $f(n) \in \theta(1)$? what if we also have $f(1)=2$
if we have f(n)=f(n-7) and f(2)=3 can we conclude that $f(n) \in \theta(1)$
|algorithms|data-structures|
if we have $f(n)=f(n-7)$ and $f(2)=3$ can we conclude that $f(n) \in \theta(1)$? what if we also have $f(1)=2$?
if we have $f(n)=f(n-7)$ and $f(2)=3$ can we conclude that $f(n) \in \theta(1)$
if we have $f(n)=f(n-7)$ and $f(2)=3$ can we conclude that $f(n) \in \theta(1)$?
Since $f(n)=f(n-7)$, $f$ can take at most $7$ different values: $f(0),f(1),f(2),f(3),f(4),f(5)$ and $f(6)$ (the others values are obtained by translation) So, obviously, $\forall n$, $|f(n)| \leq \max_{i=0}^6 |f(i)| = C$ and you indeed have $f \in \theta(1)$.
null
null
$$f(n)=f(n-7)$$ implies $$f(n)=f(n\bmod7)$$ and the function is periodic, hence perforce $\Theta(1)$, regardless the particular values of $f(n\bmod7)$.
For your $f_1$, you need to solve the recurrence $$T(n)=\begin{cases}n<k\to T(1)\\n\ge k\to T(f_1(\frac n2) + f_1(\frac n3) - f_1(\frac n5))+T(\frac n2)+T(\frac n3)+T(\frac n5).\end{cases}$$ This mandates the resolution of the recurrence on $f_1$ itself, probably not the easiest thing. ---------- Your sec...
null
Is an infinite set of RE languages create a language that is also RE? I think it's true, and my first intuition is to try induction to prove this statement. Am I on the right way? Thanks!
Is infinite union of RE a RE?
|formal-languages|computability|automata|
The statement is not true; any language $L$ can be written as the (countably infinite) union of singleton languages which each just contain one word of $L$. Also, even if the statement was true, one could not prove it using (regular) induction. This is because the _finite_ union of RE languages is indeed RE. My go-t...
I designed an algorithm where, at some point, I need to compute the product of a list of integers $n_1,\dots,n_m$ (possibly, there are repetitions in the list). The integers themselves do not depend on $m$ but can be, somehow, arbitrarily large. EDIT: right now, I'm using a naive for loop: ``` prod=1 for n_i in l...
This is a real world problem, which due to some specific aspects of it I am having a hard time finding relevant literature for it. I am looking for either an algorithm, or a pointer to relevant paper(s) describing a solution. I'm assuming one was already published, but I am just fumbling with my search terms. Pro...
Finding optimal paths for multiple agents
|algorithms|graph-traversal|traveling-salesman|
I'm finding it difficult to understand why due to the pigeonhole principle, 2 distinct words must go to the same state in a DFA. Is it that if there are n words and m states, where there are more words than states (n > m), that 2 words must end up in the same state? Is this somewhere along the right path?
Why must 2 distinct strings go to the same state in a DFA?
|regular-languages|finite-automata|
Right now i am looking at the following statement, but i cant grasp why it is correct. Can somebody help?<br/> "If we look at F0 uniformly distributed (and, say, pairwise independent) elements of [0, 1], we expect about t of them to be smaller than t/F0." Kind Regards, Ilian
Probabilty of Elements being smaller than a specific value
|complexity-theory|probability-theory|probabilistic-algorithms|
{"Voters":[{"Id":155269,"DisplayName":"Tufty21"}]}
{"Voters":[{"Id":155269,"DisplayName":"Tufty21"}]}
Consider defining indicator random variables $X_1, X_2, ..., X_{F_0}$ such that $$ X_i = \begin{cases} 1 \text{ if } x_i < \frac{t}{F_0} \\ 0 \text{ otherwise } \end{cases} $$ Then, we can count the number of elements $< \frac{t}{F_0}$ as follows $$ [ \text{# of Elements} < \frac{t}{F_0} ]= \sum_{i=1...
What is the complexity class of: given a graph G, is the graph has a maximal clique of size k? k is integer less than or equal the number of graph vertices. A related question, Given a Graph G, Find a maximal clique of size k. This is np because it is polynomially verifiable. Right? The essential question if t...
Complexity class
|complexity-theory|graphs|
If you cut the interval in 5 pieces of length 1/5 and pick one then you would expect an element drawn uniformly at random to have chance 1/5 to belong to it. So for an interval of length 3/N the chance is 3/N. Hence you would expect 3 out of N draws to belong to it. Apply this to the interval with boundary 0 and 3/N.
null
I'm working on a resource allocation problem, where there are $n$ different Items and $m$ different tasks ($n\geq m$). Also, The profit of assigning subset $I=\,(\, |I|\leq n)$ of items to task $j$ is calculated by $f(I;j)$. If no item is assigned to task $j$, then the profit is calculated as $f(\emptyset;j)$. The obje...
Heterogenous Resource Allocation Using Dynamic Programming
|time-complexity|dynamic-programming|resource-allocation|
Count the number of strings reaching each state. If you have m states, and none is reached by two or more strings, then the total number of strings is at most m. If the number of strings is greater than m then one state is reached in two or more ways. You can use the same argument if no state is reached by more tha...
You can't avoid an exponential running time. It takes $m \cdot 2^n$ space even to write down $f$, and any correct algorithm needs to read every entry of that, so any correct algorithm must take at least $\Omega(m \cdot 2^n)$ time.
consider the following function $$ \begin{align*} f(m,n) &= \begin{cases} k & \text{if program $m$ halts on input $n$ after $k$ steps} \\ m & \text{if program $m$ loops on input $n$} \\ \end{cases} \end{align*} $$ can you find an algorithm for this function?
can you find an algorithm for this function?
|turing-machines|computability|halting-problem|
As part of a college project, I need to compare the speed of arithmetic operations directly in binary on different processors. Example: At what speed will binary addition be performed on an Intel Core I5-12400 processor? Initially, I had the idea to write a program myself that would perform the appropriate tests...
I need to test the speed of performing arithmetic operations on binary numbers
|arithmetic|cpu|binary|
I am a teacher of undergrad graph theory and we tend to invent some weird (and false) characterizations of trees and recently I stumbled upon this one. Is the following true? $G$ is a tree if and only if $G$ is connected and between each pair of vertices of same degree, there is an unique path connecting them. I...
Equivallent characterization of trees?
|graphs|trees|
null
null
You can't avoid an exponential running time. It takes $m \cdot 2^n$ space even to write down $f$, and any correct algorithm needs to read every entry of that, so any correct algorithm must take at least $\Omega(m \cdot 2^n)$ time. It is possible to solve the problem in $O(m \cdot 4^n)$ time, using dynamic programmi...
You can't avoid an exponential running time. It takes $m \cdot 2^n$ space even to write down $f$, and any correct algorithm needs to read every entry of that, so any correct algorithm must take at least $\Omega(m \cdot 2^n)$ time. It is possible to solve the problem in $O(m \cdot 4^n)$ time, using dynamic programmi...
There are two possibilities: Either you write code in a language where you can see the assembler instructions that are produced. Or you go through processor manuals and figure it out. Now on basically every processor one addition, subtraction, and, or, xor operation will be performed in one cycle - the result is av...
The halting problem is a very well known undecidable problem. Suppose your function $f$ is computable. Then the following algorithm can solve the halting problem: ``` Input: code m and input n Output: true if program m halts on input n, false otherwise Let k = f(m, n) if k ≠ m: return true else: simul...
null
For example, are there worst case Decidable(but non primitive recursive or other insane time complexity)problems that have a polynomial average case complexity? If so Are there undecidable worst case problems that have polynomial time average case algorithms? Is there a limit on the arithmetical hierarchy where there c...
Are there arbitraraly hard worst case problems with polynomial time average case complexity?
|algorithms|polynomial-time|average-case|
null
For example, are there worst case Decidable(but non primitive recursive or other insane time complexity)problems that have a polynomial average case complexity? If so Are there undecidable worst case problems that have polynomial time average case algorithms? Is there a limit on the arithmetical hierarchy where there c...
Sure. Let $L_0$ be a hard language (decidable but not primitive recursive, or whatever) and $L_1$ be in $P$. Define $$L = \{ 1^n || x : x \in L_0, |x|=n \in \mathbb{N} \} \cup \{ w||x : x \in L_1, |w|=|x|=n \in \mathbb{N}, w \ne 1^n \}.$$ Then the average-case complexity of $L$ (under an appropriate uniform dis...
null
You don't really need to learn an entire new language. Here's a 1-line program in C (running on Linux): $ cat test.c int main() { register long i; for (i=-10L*1000*1000*1000; i<0; ++i); } $ gcc test.c $ time ./a.out real 0m5.064s user 0m5.056s sys 0m0.008s It t...
This is a real world problem, which due to some specific aspects of it I am having a hard time finding relevant literature for it. I am looking for either an algorithm, or a pointer to relevant paper(s) describing a solution. I'm assuming one was already published, but I am just fumbling with my search terms. Pro...
The problem is NP-hard: the special case of $N=1$ is the traveling salesman problem. Therefore, you can't expect any efficient algorithm that will always work. A reasonable approach in practice is to use integer linear programming (ILP). This is basically an operations research problem, which makes widespread use ...
"Speed" does not have a well-defined meaning at that level. Basic CPU instructions have a *latency* (or in general, more than one) and a *throughput*. Different ways of measuring the "speed" could result in either the latency or the throughput or, if not done carefully, neither. Arbitrarily executing instructions witho...
I am a teacher of undergrad graph theory and we tend to invent some weird (and false) characterizations of trees and recently I stumbled upon this one. Is the following true? $G$ is a tree if and only if $G$ is connected and between each pair of vertices of same degree, there is an unique path connecting them. I...
What is the complexity of determining whether a graph has a maximal clique of a given size?
I'm currently in need of the inverse operation of the concatenation of 2 regular languages. Formally, for 3 regular languages $A,B,C$ such that $A \cdot B = C$ only $A$ and $C$ are known and $B$ should be the smallest language that fulfills the equation. The smallest-language requirement is necessary for my pra...
Inverse operation to concatenation for regular languages
|regular-languages|finite-automata|regular-expressions|
I am a teacher of undergrad graph theory and we tend to invent some weird (and false) characterizations of trees and recently I stumbled upon this one. Is the following true? $G$ is a tree if and only if $G$ is connected and between each pair of vertices of same degree, there is an unique path connecting them. I...
null
The standard NP-completeness reduction for Independent Set is from 3-SAT. In this reduction, you there is an independent set of size $|C|$ where $C$ is the set of clauses, if and only if the 3-SAT instance is a yes-instance. By construction, there cannot be any larger independent sets. Therefore, you can trivially...
If you cut the interval in 5 pieces of length 1/5 and pick one then you would expect an element drawn uniformly at random to have chance 1/5 to belong to it. So for, say t =3, an interval of length 3/N the chance is 3/N. Hence you would expect 3 out of N draws to belong to it. Apply this to the interval with boundary 0...
I'm currently in need of the inverse operation of the concatenation of 2 regular languages. Formally, for 3 regular languages $A,B,C$ such that $A \cdot B = C$ only $A$ and $C$ are known and $B$ should be the smallest language that fulfills the equation. The smallest-language requirement is necessary for my pra...
This seems to be a correct characterization of trees, here is my proof of it (hope there is no mistake). Let $G = (V, E)$ an undirected graph. Denote $(P)$ the property "$G$ is connected and between each pair of vertices of same degree, there is an unique path connecting them." Suppose there exists a graph verify...
Let $A=\{$ M is a TM, $s\in \mathbb{N}$ and $\exists x\in\Sigma^*$ s.t M rejects $x$ in at most $s$ steps $\}$. I want to define its complement, so how do I negate "$\exists x\in\Sigma^*$ s.t M rejects $x$ in at most $s$ steps"? Is it: $\forall x \in \Sigma^*$ M accepts $x$ in at most $s$ steps? Thanks a lo...
Complement of a language definition
|complexity-theory|formal-languages|regular-languages|logic|
null