instruction
stringlengths
0
29.8k
⌀
$T(n)=5T(n/3)+n^2$ Consider this to be the running time of a program. How could we interpret then numbers 5 and 3. My Thoughts: 5 times will mean that the problem is divided into 5 subproblems each of size n/3 and then probably to get the solution to the main problem it required $n^2$ steps I am not ...
Interpreting the time complexity of a program from function
|algorithms|runtime-analysis|
null
Suppose given $n$ points on axis. Also each points colored with a color from set of colors $C$ that contains $k$ distinct colors. We try cover $k$ colors with unit length intervals such that we use minimum number of unit intervals. I think this problem is NP-hard and we can reduce from set cover problem. But I get s...
Is this spicific problem NP-hard?
|algorithms|np-complete|
Suppose given $n$ points on axis. Also each points colored with a color from set of colors $C$ that contains $k$ distinct colors. We try cover $k$ colors with unit length intervals such that we use minimum number of unit intervals. Also when $k=3$ are there polynomial solution? I think this problem is NP-hard and we...
Suppose given $n$ points on axis. Also each points colored with a color from set of colors $C$ that contains $k$ distinct colors. We try cover $k$ colors with unit length intervals such that we use minimum number of unit intervals. Also when $k=3$ are there polynomial solution I read [this link][1] but I can't understa...
You are right. This could be a problem solved using a divide-and-conquer strategy such that the data set is recursively processed in five subsets, each a third of the data, while the split and the merge phases cost $n^2$ altogether.
Suppose we are given $n$ points on the real line, where each point is colored with a color from set $C=\{c_1,c_2,...,c_k\}$ that contains $k$ distinct colors. We try to cover the $k$ distinct colors with as few unit length intervals as possible. I think this problem is NP-hard and we can reduce from set cover proble...
null
null
You may be interested in the algorithm presented in this paper: [Finding all the elementary circuits of a directed graph][1]. Donald B. Johnson. SIAM J. COMPUT. Vol. 4, No. 1, March 1975 > **Abstract.** An algorithm is presented which finds all the elementary circuits-of a directed graph in time bounded by `O((n ...
If $k$ is part of the input problem is NP-hard and you can indeed reduce from the set-cover problem. Let $x_{1}, \dots, x_k$ be the items and $S_1, \dots, S_m$ be the sets. Create a color for each item. Then, for each set $S_i$, create $|S_i|$ points on the real line at coordinates $2i + \frac{1}{|S_i|}, 2i + \frac...
If $k$ is part of the input problem is NP-hard and you can indeed reduce from the set-cover problem. Let $x_{1}, \dots, x_k$ be the items and $S_1, \dots, S_m$ be the sets. Create a color for each item. Then, for each set $S_i$, create $|S_i|$ points on the real line at coordinates $2i + \frac{1}{|S_i|}, 2i + \frac...
This is purely an accidental property of the English lexicon. In French and other languages, *software* is apparently a countable noun. In English, [it is not][1]: you cannot not say *a software* any more than you can say *a hardware* or *a garbage*. You say *a program* or *an application* instead. [1]: http...
This is purely an accidental property of the English lexicon. In French and other languages, *software* is apparently a countable noun. In English, [it is not][1]: you cannot not say *a software* any more than you can say *a hardware* or *a garbage*. You say *a program* or *an application* instead. This is due t...
null
I have seen the solution to the knapsack problem and understand it. But I am trying to come up with a dynamic programming solution to the following problem, which is a modified a version of the knapsack. Consider a store with n boxes, each containing m items, and we could only choose one item out of each ...
Modified knapsack problem with multiple boxes to choose from
|dynamic-programming|knapsack-problems|
null
If $k$ is part of the input problem is NP-hard and you can indeed reduce from the set-cover problem. Let $x_{1}, \dots, x_k$ be the items and $S_1, \dots, S_m$ be the sets. Create a color for each item. Then, for each set $S_i$, create $|S_i|$ points on the real line at coordinates $2i + \frac{1}{|S_i|}, 2i + \frac...
For $i=0,\dots,n$ and $v=0, \dots V$ define $OPT[i,v]$ as the maximum value that can be attained by selecting at most one item from each of the first $i$ boxes (and no items from the remaining boxes) when the knapsack volume is $v$. Let $v_{i,j}$ and $w_{i,j}$ be the value and the weight of the $j$-th item in the $i...
If int a=250; int b =3; int c = (a + b/2)/b * b; why doesn't c equal 251 but rather 249? How is it that c is smaller than a when we are adding? Doesn't the divide by b and multiply by b cancel out? I thought c= Int(250+1.5)=251.
(Java) If int a=250; int b =3; int c = (a + b/2)/b * b; why doesn't c equal 251 but rather 249?
|arithmetic|
Operations are executed in order of precedence. When two operations have the same preference, they are evaluated from left to right. In your specific case: - `b/2` is evaluated first and it evaluates to $1$ (notice the integer division). - `a+3` is evaluated next, yielding $251$. - `251/b` is next, yielding $83$. -...
Let's discuss your confusion with precedence and associativity. Among all the operators Parentheses has highest precedence. That's why $()$ is evaluated first. And then inside $()$ we see two operators $+$ and $/.$ Consequently $/$ has highest precedence than $+$ operator. That's why $/$ is evaluated first then $+$...
I dont know if this is any important IRL, but I am trying to understand lines below. >4K words of main memory (this implies 12 bits per address). >4M X 16 means the memory is 4M long (4M = 2^2 X 2^20 = 222 words) and it is 16 bits wide (each word is 16 bits) So, how it is really calculated, what does 4K/4M re...
Finding bits per address in memory
|computer-architecture|
I dont know if this is any important IRL, but I am trying to understand lines below. >4K words of main memory (this implies 12 bits per address). >4M X 16 means the memory is 4M long (4M = 2^2 X 2^20 = 222 words) and it is 16 bits wide (each word is 16 bits) So, how bits per address is really calculated, what...
The sketches of the sub-tree before and after the left rotation are clear. "In order for the traversal order not to change (after the rotation), we need to have" $$\begin{aligned} &postOrder(a), postOrder(b), postOrder(c), y, x \\ =\ &postOrder(a), postOrder(b), x, postOrder(c), y. \end{aligned}$$ Suppose $...
Is this specific problem NP-hard?
|algorithms|complexity-theory|np-complete|np-hard|complexity-classes|
null
Suppose we are given $n$ points on the real line, where each point is colored with a color from set $C=\{c_1,c_2,\ldots,c_k\}$ that contains $k$ distinct colors. We try to cover the $k$ distinct colors with as few unit length intervals as possible. I think this problem is NP-hard and we can reduce from set cover pro...
Covering all colors with unit intervals
|algorithms|np-complete|np-hard|
I dont know if this is any important IRL, but I am trying to understand lines below. >4K words of main memory (this implies 12 bits per address). >4M X 16 means the memory is 4M long (4M = $2^2 \times 2^{20} = 2^{22}$ words) and it is 16 bits wide (each word is 16 bits). So, how bits per address is really c...
In computer science, the following suffixes are commonly used: - K (Kilo): $2^{10}$ - M (Mega): $2^{20}$ - G (Giga): $2^{30}$ - T (Tera): $2^{40}$ The next one is P (Peta), but it is not in common usage. Usually these suffixes are accompanied by another unit, for example KB (Kilobyte, or $2^{10}$ bytes) or MHz...
If ```java int a = 250; int b = 3; int c = (a + b/2)/b * b; ``` Why doesn't `c` equal 251, but rather 249? How is it that `c` is smaller than `a` when we are adding? Doesn't the `divide by b` and `multiply by b` cancel out? I thought `c= int(250+1.5)=251`
Java | If a=250, b=3, c=(a + b/2)/b * b, Why doesn't c equal 251 but rather 249?
|arithmetic|integers|java|
null
Let's discuss your confusion with precedence and associativity. Among all the operators Parentheses has highest precedence. That's why $()$ is evaluated first. And then inside $()$ we see two operators $+$ and $/.$ Consequently $/$ has highest precedence than $+$ operator. That's why $/$ is evaluated first then $+$...
Let's discuss your confusion with precedence and associativity. Among all the operators Parentheses has highest precedence. That's why $()$ is evaluated first. And then inside $()$ we see two operators $+$ and $/.$ Consequently $/$ has highest precedence than $+$ operator. That's why $/$ is evaluated first then $+$...
Operations are executed in order of precedence. When two operations have the same preference, they are evaluated from left to right. In your specific case: - `b/2` is evaluated first and it evaluates to $1$ (notice the integer division). - `a+1` is evaluated next, yielding $251$. - `251/b` is next, yielding $83$. -...
Let $A$ be an array sorted in non-increasing order. Let $m$ be a natural number. For example, let $m = 10$. We want to find the index $i$ such that $A[:i]$ contain elements less than or equal to $m$, whereas $A[i:]$ contain elements strictly greater than $m$. We can easily do this using binary search in logarithmic...
Search algorithm with at most a constant $k$ failed accesses
|algorithms|runtime-analysis|search-algorithms|
Let $A$ be an array sorted in non-increasing order. Let $m$ be a natural number. For example, let $m = 10$. We want to find the index $i$ such that $A[:i]$ contain elements less than or equal to $m$, whereas $A[i:]$ contain elements strictly greater than $m$. We can easily do this using binary search in logarithmic...
Let's discuss your confusion with precedence and associativity. Among all the operators Parentheses has highest precedence. That's why $()$ is evaluated first. And then inside $()$ we see two operators $+$ and $/.$ Consequently $/$ has highest precedence than $+$ operator. That's why $/$ is evaluated first then $+$...
null
null
If $k$ is part of the input then the problem is NP-hard and you can indeed reduce from the set-cover problem. Let $x_{1}, \dots, x_k$ be the items and $S_1, \dots, S_m$ be the sets. Create a color for each item. Then, for each set $S_i$, create $|S_i|$ points on the real line at coordinates $2i + \frac{1}{|S_i|}, 2i...
null
null
If I rememeber right, I read somewhere that $NP\subseteq coNP/poly$ is the same as $coNP\subseteq NP/poly$. Is this true? If yes, is there a relatively simple proof for this?
(Why) is $NP\subseteq coNP/poly$ same as $coNP\subseteq NP/poly$?
|complexity-theory|complexity-classes|
If I rememeber right, I read somewhere that $NP\subseteq coNP/poly$ is the same as $coNP\subseteq NP/poly$. Is this true? If yes, is there a relatively simple proof for this? Definitions -- **Class $NP/poly$**. We say that a language $L$ belongs to the complexity class $NP/poly$ if there is a Turing machine $M...
I wonder if there is an algorithm which takes multiple (source,target) pairs and a max_depth parameter and returns all of the paths found with those pairs? Thinking of Dijkstra's algorithm, it would start from each start node and then in each iteration it would also check other pairs' tables to see if there is a pat...
Is there an efficient algorithm for calculating shortest path for multiple (source,target) pairs in a graph?
|graphs|shortest-path|dijkstras-algorithm|
By definition, $$ L \in \mathsf{coNP} \Longleftrightarrow \overline{L} \in \mathsf{NP} \\ L \in \mathsf{coNP/poly} \Longleftrightarrow \overline{L} \in \mathsf{NP/poly} $$ From this you can easily deduce your claim.
{"OriginalQuestionIds":[64093],"Voters":[{"Id":683,"DisplayName":"Yuval Filmus","BindingReason":{"GoldTagBadge":"algorithms"}}]}
null
I'm having problems determining the *productions* for the language $L=\{ a^nb^m | n \le m+3 \}$ I'm very new to this so this example might be a little harder, but everything I try I end up not finding the correct solutions. Some example strings are $\epsilon$, $a$, $aa$, $aaa$, $b$, $ab$, $aab$, $aaab$, $aaaab$, $...
Context-free grammar for $L=\{ a^nb^m | n \le m+3 \}$
|formal-languages|context-free|formal-grammars|
€+(0+1)+0(0+1)+10+0(0+1)(0+1)+10(0+1)+110+(0+1)³(0+1)⁴
I wonder if there is an algorithm which takes multiple (source,target) pairs and a max_depth parameter and returns all of the paths found with those pairs? Thinking of Dijkstra's algorithm, it would start from each start node and then in each iteration it would also check other pairs' tables to see if there is a pat...
null
I'm having problems determining the *productions* for a CFG describing the language $L=\{ a^nb^m | n \le m+3 \}$ where $n,m \ge 0$ I'm very new to this so this example might be a little harder, but everything I try I end up not finding the correct solutions. Some example strings are $\epsilon$, $a$, $aa$, $aaa$...
|formal-languages|automata|context-free|formal-grammars|
null
[![enter image description here][1]][1] $S \rightarrow aSb/A $ $A \rightarrow \epsilon/a/aa/aaa/B$ $B \rightarrow bB/\epsilon$ [1]: https://i.stack.imgur.com/PwPiN.png
Is it possible to create an union of two context-free grammars? I found a PDF material from the university of Iowa where they claim that it's possible but I just don't know how. They had that for grammar G1: $S_1 \rightarrow 0S_11 | \epsilon$ and for grammar G2 $S_2 \rightarrow 1S_20$ Now they created a uni...
Union of two context-free grammars and their productions
|formal-languages|automata|context-free|formal-grammars|
null
In the problem of pair-sum we are given a multiset $A$ and an element $\alpha$. We are asked to find whether there is a pair ($2$ elements) of $A$ s.t. their sum is $\alpha$. This problem is also known as "2-SUM". I'd like to analyse an efficient algorithm for this. The algorithm sorts $A$ and then iterates over th...
Single tape TM for pair sum
|algorithms|time-complexity|turing-machines|linear-complexity|tape-complexity|
null
In the problem of pair-sum we are given a multiset $A$ and a number $\alpha$. We are asked to find whether there is a pair ($2$ numbers) of $A$ s.t. their sum is $\alpha$. This problem is also known as "2-SUM". Here all numbers are small/constant, $O(1)$, sum of $2$ small numbers requires $O(1)$ actions and their size ...
Complement of equality problem of Turing machines is unrecognizable or not-recognizable but How? As per my knowledge it is recognizable if you can decide its accept condition but not reject condition and the opposite is the case with unrecognizable. But in complement-Eq problem of TM if a string/input accepted by one b...
Is complement of equality problem of Turing machines Turing-recognizable?
|turing-machines|turing-recognizable|
null
It's the same as for all NP problems; the optimisation problem is > Find a valid solution $s$ that minimises¹ $f(s)$! and the corresponding decision problem is > Is there a valid solution $s$ with $f(s) \leq k$? You see that the former immediately solves the latter, and you can solve the former by using the...
I've started with thinking of a bucketsort/radix sort variation, only to be disproved by a colleague. here's the problem: Given an array with `k` distinct elements, it is known that the smallest element appears once, the 2nd smallest element appears twice, the 3rd smallest element appears 4 times, the 4th smalles...
Sorting array with k distinct elements, each appearing logarithmic amount of times
|algorithms|sorting|
a friend sent me a question where we're given language $L$ and its subset $E(L)$ such that: $$E(L)=\{E(w)\ |\ w\in L\}\\\text{such that}\\ E(w)=\{w_{even}=\sigma_2\sigma_4\dots\ |\ w=\sigma_1\sigma_2\dots\sigma_{n-1}\sigma_n\}$$ We need to prove that if $L\in P$ then $E(L)\in NP$. ***My Question:*** I'm findi...
How to prove that a subset of a language L is related to NP while L is related to P?
|complexity-theory|formal-languages|np|