instruction
stringlengths
0
29.8k
⌀
Here is one straightforward algorithm. I'm not sure what the worst case running time is, but it is at most $O(n\log n)$. 1. Compute the list $[k\oplus a,\ldots,k\oplus b]$. 2. Split the resulting list into _obvious_ intervals, by merging adjacent entries whenever they form an interval, and creating a new interval ...
Let $\oplus$ be bitwise xor. Let $k,a,b$ be non-negative integers. $[a..b]=\{x\mid a\leq x, x\leq b\}$, it is called a integer interval. What is a fast algorithm to find $\{ k\oplus x\mid x\in [a..b]\}$ as a union of set of integer intervals. One can prove that $[a+k..b-k]\subseteq \{ k\oplus x\mid x\in [a..b]\...
Here's an efficient solution based on BDDs 1. Find $n$ such that $k,a,b < 2^n$. Create $n$ boolean variables, one for each position in an $n-bit$ number 2. Write out a boolean formula representing every number in that interval. For example, if $n=4$ (so that we are only considering possible inputs in $[0..15]$), ...
Here's an efficient solution based on BDDs 1. Find $n$ such that $k,a,b < 2^n$. Create $n$ boolean variables, one for each position in an $n-bit$ number 2. Write out a boolean formula representing every number in that interval. For example, if $n=4$ (so that we are only considering possible inputs in $[0..15]$), ...
Here is one straightforward algorithm. I'm not sure what the worst case running time is, but it is at most $O(n\log n)$, **where $n=b-a$.** 1. Compute the list $[k\oplus a,\ldots,k\oplus b]$. 2. Split the resulting list into _obvious_ intervals, by merging adjacent entries whenever they form an interval, and creat...
Here's an efficient solution based on BDDs 1. Find $n$ such that $k,a,b < 2^n$. Create $n$ boolean variables, one for each position in an $n-bit$ number 2. Write out a boolean formula representing every number in that interval. For example, if $n=4$ (so that we are only considering possible inputs in $[0..15]$), ...
Here's an efficient solution based on BDDs 1. Find $n$ such that $k,a,b < 2^n$. Create $n$ boolean variables, one for each position in an $n-bit$ number 2. Write out a boolean formula representing every number in that interval. For example, if $n=4$ (so that we are only considering possible inputs in $[0..15]$), ...
|algorithms|graphs|optimization|linear-programming|
|algorithms|integers|
Yep, it's true. I can describe Turing machine made of endless paper, alphabet and instructions, but in Russian language only, so I can only give you this [link][1] to Wiki page about Turing machine - complete language you are talking about. [1]: http://en.wikipedia.org/wiki/Universal_Turing_machine
The machine you describe would be turing complete with the addition of an assignment operator (you need this to take advantage of memory), and at least one comparison operator (which could be folded into the jump, like a jump-if-(not)-zero). (Note that an increment operator is necessary - either as a primitive, or appr...
The more abstract answer which captures the requirements on both imperative-style programming (suitable for hardware register machines) and functional-style programming (suitable for dataflow and graph reduction machines) is that your language must be able to 1. represent bit strings of arbitrary lengths 2...
I overheard a conversation on the topic and the conclusion that one gent came to was that in order to be Turing complete, given one has infinite storage, all one needs is a conditional control structure and a jump instruction. Is this true? If it is true, and Turing completeness requires that the language that ...
What are the minimum requirements for a language to be considered Turing Complete?
|programming-languages|
|computability|programming-languages|turing-completeness|
> **Possible Duplicate:** > [Are there minimum criteria for a programming language being Turing complete?](http://cs.stackexchange.com/questions/991/are-there-minimum-criteria-for-a-programming-language-being-turing-complete) <!-- End of automatically inserted text --> I overheard a conversation on the topic and ...
{"OriginalQuestionIds":[991],"Voters":[{"Id":41,"DisplayName":"Kaveh"},{"Id":69,"DisplayName":"Patrick87"}]}
According to your description: 1. Each node in the network can relay a certain amount of traffic per time unit. 2. Each link has a certain capacity. In order to convert your problem to an instance of network flow problem, one can do the following transformation. In the underlying graph of network, $G = (V,E)$,...
Here is one straightforward algorithm. I'm not sure what the worst case running time is, but it is at most $O(n\log^2 n )$, where $n=\max(a,b,k)$. 1. Compute the list $[k\oplus a,\ldots,k\oplus b]$. 2. Split the resulting list into _obvious_ intervals, by merging adjacent entries whenever they form an interval, an...
null
According to your description: 1. Each node in the network can relay a certain amount of traffic per time unit. 2. Each link has a certain capacity. In order to convert your problem to an instance of network flow problem, one can do the following transformation. In the underlying graph of network, $G = (V,E)$,...
Historically, the term "strongly typed programming language" came into use in the 70's in reaction to the existing widely used programming languages, most of which had type holes. Some examples: - In Fortran, there were things called "COMMON" storage areas, which could be shared across modules, but there were no c...
This should be a comment to the nice answer by @JamesKoppel but it is too large for a comment: I don't think that the size of the BDD for $[a \ldots b]$ is $O(\log (b-a))$ because even to test if the $n$ Boolean input variables are equal to a fixed constant requires linear size BDD size in the number of variables, i...
null
For directed negative edges: Since a negative edge makes that distance appear shorter, the true shortest path could end up not being given as the answer. Hence the problem. For non-directed negative edges: You could enter an infinite loop trying find the "shortest path" as the negative edge creates a distance that g...
Short answer is that Dijkstra is a greedy algorithm, meaning we assume that we have made the best choice possible in every step of the algorithm. With negative edges, this is no longer possible and thus a greedy algorithm will not suffice. **Here's an analogy:** (that might help, or confuse even more) Take a convex ...
Yes, not deleting the node is the obvious and accepted solution to negative edges. The trick here is that for whatever historical reasons, and as part of a diabolical scheeme to better confuse you, we use a different name for this modified algorithm: [Bellman-Ford algorithm](https://en.wikipedia.org/wiki/Bellman-For...
A slight variant to Dijkstra algorithm will work on a graph with negative weight, without negative cycle (Competitive Programming 2, Steven Halim). For a general graph (which may contain negative cycle), use [Bellman-Ford][1] algorithm, which has worse time complexity, but guarantees termination, and allow detection of...
Most books explain the reason the algorithm doesn't work with negative edges as nodes are deleted from the priority queue after the node is arrived at since the algorithm assumes the shortest distance has been found. However since negative edges can reduce the distance, a future shorter distance might be found; but sin...
Using Dijkstra's algorithm with negative edges?
|untagged|
Recently I sort of stumbled on a problem of finding an efficient topology given a weighted directed graph. Consider the following scenario: 1. Node 1 is connected to 2,3,4 at 50 Mbps. Node 1 has 100 Mbps network card. 2. Node 3 is connected to 5 at 50 Mbps. Node 3 has 100 Mbps card. 3. Node 4 is connected to N...
null
Yes, not deleting the node is the obvious and accepted solution to negative edges. The trick here is that for whatever historical reasons, and as part of a diabolical scheme to better confuse you, we use a different name for this modified algorithm*: [Bellman-Ford algorithm](https://en.wikipedia.org/wiki/Bellman-For...
This is an example in my lecturer notes. Is this function with time complexity O(n*log(n)). Because the worse case is the funtion goes into `else` condition, and 2 nested loop with time complexity of log(n) and n, so it is O(n*log(n)). Am I right? int j = 3; int k = j * n / 345; if(k > 100){ ...
What is the time complexity of this function?
|time-complexity|
|shortest-path|
null
The time-complexity is essentially going to be on the order of the number of times that `k` is incremented in the nested `for` loop. There is some extra stuff going on, but if you think about it, that's just playing with constant factors. How many times will `k` be incremented? When `i = 1`, `k` is incremented once....
The time-complexity is essentially going to be on the order of the number of times that $k$ is incremented in the nested `for` loop. There is some extra stuff going on, but if you think about it, that's just playing with constant factors. How many times will $k$ be incremented? When $i = 1$, $k$ is incremented once....
This is an example in my lecture notes. Is this function with time complexity $O(n \log n)$?. Because the worst case is the funtion goes into `else` branch, and 2 nested loops with time complexity of $\log n$ and $n$, so it is $O(n \log n)$. Am I right? int j = 3; int k = j * n / 345; if(k > 100){ ...
L1 * L2 is NP-hard. Proof: Let L be a language in NP, let f be a reduction of L to L1 and let w2 be in L2. Define g(x) = (f(x), w2). Now g is a polynomial time many-to-one reduction of L to L1*L2 because clearly: x in L <==> (f(x), w(2)) in L1*L2
if l1 is in NP-HARD, so for every L2!=empty set, l1*l2 is in np-hard. when: l1*l2={(w1,w2) , w1 in L1 and w2 in L2} Is it true or false and why? I can't approve it but I also don't find counter example.
np-hard closure
|untagged|
If I understand your definitions, this can be done in linear time with constant space. This is obviously the lowest bound, because we need to at least read the entire input. The answer given in [this question](http://cs.stackexchange.com/questions/2079/determine-missing-number-in-data-stream) satisfies. It's impo...
In Cormen et. al., *Introduction to Algorithms*, I don't get a line in the proof of Lemma 26.1 which states that the augmented flow $f\uparrow f'$ is a flow in $G$ and is s.t. $|f\uparrow f'| =|f|+|f'|$. In the third edition this is pp. 717-718, and p. 653/Lemma 26.2 in second ed. My confusion: When arguing *flow-c...
CLRS - Maxflow Augmented Flow Lemma 26.1 - don't understand use of def. in proof
|algorithms|network-flow|
|complexity-theory|
|complexity-theory|time-complexity|algorithm-analysis|runtime-analysis|
|algorithms|graphs|shortest-path|
|algorithms|graphs|random-walk|
|algorithms|graphs|
If I understand your definitions, this can be done in linear time with constant space. This is obviously the lowest bound, because we need to at least read the entire input. The answer given in [this question](http://cs.stackexchange.com/questions/2079/determine-missing-number-in-data-stream) satisfies. It's impo...
The time-complexity is essentially going to be on the order of the number of times that $k$ is incremented in the nested `for` loop. There is some extra stuff going on, but if you think about it, that's just playing with constant factors. How many times will $k$ be incremented? When $i = 1$, $k$ is incremented once....
If I understand your definitions, this can be done in linear time with constant space. This is obviously the lowest bound, because we need to at least read the entire input. The answer given in [this question](http://cs.stackexchange.com/questions/2079/determine-missing-number-in-data-stream) satisfies. It's impo...
**Note:** The notations and definitions below are borrowed from the third edition of the book. To answer this question, first, observe that if $(u,v) \notin E$, then $f(u,v) = f'(u,v) = 0$. Furthermore, since $f'(v,u) \le c_f(u,v) = f(u,v)$, we also obtain that $f'(v,u) = 0$. This simply implies that $(f \uparrow f'...
**Note:** The notations and definitions used below are borrowed from the third edition of the book. To answer this question, first, observe that if $(u,v) \notin E$, then by flow definition, $$f(u,v) = f'(u,v) = (f \uparrow f')(u,v) = 0 \, .$$ Furthermore, since $f'(v,u) \le c_f(u,v) = f(u,v)$, it is obtained ...
In Cormen et. al., *Introduction to Algorithms* (3rd ed.), I don't get a line in the proof of Lemma 26.1 which states that the augmented flow $f\uparrow f'$ is a flow in $G$ and is s.t. $|f\uparrow f'| =|f|+|f'|$ (this is pp. 717-718). My confusion: When arguing *flow-conservation* they use the definition of $f\upa...
I've finished most of the material in Corman's Intro to Algorithms book and I am looking for an algorithms book that covers material beyond Corman's book. Are there any recommendations? NOTE: I asked this on stackoverflow but wasn't all too happy with the answer.
Book for algorithms beyond Corman
|books|
null
null
Time complexity of mentioned algorithm is $O(1)$, because for $K>100$ you have a constant operation (println), and you know: $j=3,k = 3 \cdot n / 345 \implies 100 = 3\cdot n / 345 \implies n=11500$, means for $n\ge 11500$ your algorithm has a constant running time (also other part is constant, because just for $n<11500...
suppose we have a direct graph $G=(V,E)$ and two nodes $A$ and $B$. I would like to know if there are already algorithms for calculating the following decision problem: "Are there at least two paths between $A$ and $B$ of the same length? " How about the complexity? can i solve it in polytime? Thanks in andva...
Finding at least two paths of same length in a direct graph
|graphs|
Time complexity of mentioned algorithm is $O(1)$, because for $K>100$ you have a constant operation (println), and you know: $j=3,k = 3 \cdot n / 345 \implies 100 = 3\cdot n / 345 \implies n=11500$, means for $n\ge 11500$ your algorithm has a constant running time (also other part is constant, because just for $n<11500...
Suppose we have a directed graph $G=(V,E)$ and two nodes $A$ and $B$. I would like to know if there are already algorithms for calculating the following decision problem: "Are there at least two paths between $A$ and $B$ of the same length?" How about the complexity? Can I solve it in polytime?
I've been given the following problem: Given a data structure $M$ that is based on comparisons and supports the following methods on a group of numbers $S$: * $\text{Insert}(x)$ – add $x$ to $S$ * $\text{Extract_min}()$ – remove the minimal element in $S$ and return it We can implement with a heap the above ...
|algorithms|data-structures|binary-trees|search-trees|
Suppose we have a directed graph $G=(V,E)$ and two nodes $A$ and $B$. I would like to know if there are already algorithms for calculating the following decision problem: > Are there at least two paths between $A$ and $B$ of the same length? How about the complexity? Can I solve it in polynomial time?
Finding at least two paths of same length in a directed graph
null
If $L_1$ is NP-hard, $L_1 \cdot L_2$ is NP-hard for every $L_2 \neq \emptyset$, where $\qquad \displaystyle L_1 \cdot L_2 = \{(w_1,w_2) \mid w_1 \in L_1, w_2 \in L_2\}$ Is it true or false and why? I can't prove it but I also don't find counter example.
|complexity-theory|np-hard|
$L_1 \cdot L_2$ is NP-hard. **Proof:** Let $L$ be a language in NP, let $f$ be a reduction of $L$ to $L_1$ and let $w_2$ be in $L_2$. Define $g(x) = (f(x), w_2)$. Now $g$ is a polynomial time many-to-one reduction of $L$ to $L_1 \cdot L_2$ because clearly: $x \in L \quad \Longleftrightarrow\quad (f(x), w(2)) \in ...
EDIT: As pointed out by Saeed Amiri, this is actually $O(1)$, since for asymptotically large $n$, the `else` branch isn't actually taken; the `if` part is executed, which is trivially constant time. The rest of this answer, which I leave for reference, would be correct if, for instance, the condition were `k < 100`. So...
Okay, finally got you the complexity you were looking for, and what's best, I found it in the literature: ##Complexity **Delete**: $\bf\mathcal{O}(1)$ **Delete-min**: $\bf\mathcal{O}(1)$ **Find-min**: $\bf\mathcal{O}(1)$ **Insert**: $\bf\mathcal{O}(log\ n)$ ##Reference > **IF MELD** is allowed to take ...
|algorithms|graphs|random-walks|
null
I cannot seem to find an answer to this question with Google, so I am going to ask here: is it required for a good neighbourhood function that it in principle (i. e. by recursively considering all neighbours of a certain solution - which is not practical) can reach all possible solutions?
Neighbourhood in local search metaheuristic
|optimization|heuristics|
I cannot seem to find an answer to this question with Google, so I am going to ask here: is it required for a good neighbourhood function that it in principle (i. e. by recursively considering all neighbours of a certain solution - which is not practical) can reach all possible solutions? EDIT: My question is wheth...