instruction stringlengths 0 29.8k ⌀ |
|---|
null |
The method used in practical scenarios depends on the scenario (and on the programmer). There are several possible issues influencing the choice of implementation:
1. Whether the algorithm is known to the programmer.
1. Ease of coding (it's easiest if it's already implemented in some library you can use).
1. Sp... |
Determining whether two monotone functions given as programs intersect is non-computable. Similarly, determining the first intersection under the promise that it exists is "arbitrarily hard" (definitely not polytime).
Given a program $P$, define a function $f_P$ which, for input $n$, is $1$ if $P$ stops after $n$ st... |
Perhaps this is a question for stackoverflow because its practical nature, but I am not aware of any general method to relate recurrence relations and recursive functions.
Having as an example this $recurrence$ $relation$
$2a_n=3a_{n-1}-2a_{n-2}$
static float a(int n)
{
if((n==0)... |
Can a recurrence relation be translated to a composite function of itself? |
|recurrence-relation|recursion|recursion-theory| |
|complexity-theory|np-complete|reductions| |
|data-structures|efficiency|linked-lists| |
Perhaps this is a question for stackoverflow because its practical nature, but I am not aware of any general method to relate recurrence relations and recursive functions.
Having as an example this recurrence relation:
$\qquad \begin{align}a_0 &= a_1 = 1 \\ 2a_n &= 3a_{n-1}-2a_{n-2}\end{align}$
I would like to... |
|recurrence-relation|recursion| |
static float f(int n,int m)
{
if((n==1)||(m==0)) return (1,1);
return ((3*n - 2*m)/2,n);
}
That way $\underbrace{f\circ f\circ \dots \circ f}_{\text{n times}} (1,0)=(a_n,a_{n-1})$.
Is that what you wanted? |
If I understand your question correctly, the function
$\qquad f(x) = \langle( \frac{1}{2} \cdot (3x[1] - 2x[2]) , x[1] )\rangle$,
with $\langle \cdot \rangle : \mathbb{N}^2 \to \mathbb{N}$ an encoding of tuples so that $a = \langle b, c \rangle \iff a[1] = b \land a[2] = c$, does the job in the sense that
$\qq... |
If I understand your question correctly, the function
$\qquad f(x) = \langle \frac{1}{2} \cdot (3x[1] - 2x[2]) , x[1] \rangle$,
with $\langle \cdot \rangle : \mathbb{N}^2 \to \mathbb{N}$ an encoding of tuples so that $a = \langle b, c \rangle \iff a[1] = b \land a[2] = c$, does the job in the sense that
$\qqua... |
Some frontmatter: I'm a recreational computer scientist and employed software engineer. So, pardon if this prompt seems somewhat out of left field -- I routinely play with mathematical simulcra and open problems when I have nothing better to do.
While playing with the [Riemann hypothesis][1], I determined that the ... |
|reference-request|compilers|semantics| |
I'm looking for resources on getting started with [program analysis][1].
The only book I've found on the topic is the [Nielson & Nielson][2] book.
Other than that, it seems like there are only "compiler" books where "program analysis" would be a chapter, or something along those lines.
Do people know of any o... |
Trying to take "high priority" i.e. high degree vertices over their neighbors will not work in all cases. This algorithm chooses $n-1$ for $C_n$ ([Cycle Graph](http://en.wikipedia.org/wiki/Cycle_graph) on $n$ vertices). It should choose either $(n-1)/2$ or $n/2$ if its odd or even. It also fails for [Perfect Graphs](ht... |
I'm trying to find a polynomial time algorithm for finding the minimum vertex cover for a graph. I've written the algorithm below; I know this problem is $\mathsf{NP}$-hard, which means there are probably some graphs for which this algorithm will not work.
I need some help in finding the flaw in this algorithm and a... |
null |
I can't cite an historical reference, but I would suspect a "half adder" is called that because you can combine two of them (with an `or` gate combining the carries) to make a "full adder". |
I have recently came across Half adders & Full Adders in my Logic Network Lectures, I have some what understand the theory & I can do pretty much well, But I am still unable to understand the reason , why they called them in that name? I mean, Is there any reason to be name 'half adder' as 'half adder'? |
Why does the name half adder is used to represent the half adder? |
|untagged| |
null |
I have recently came across half-adders and full adders in my Logic Network lectures. I have somewhat understood the theory, but I am still unable to understand the reason why they called them in that name? I mean, is there any reason why half-adders have the name ‘half-adders’? |
Why is the name half-adder used to represent the half-adder? |
|terminology|circuits| |
With a full adder, you can get all outputs from (0,0) to (1,1). With a half adder, you can never get (1,1), which makes it, in a way, incomplete.
Also, in practice a full adder is used more than a bare half adder. For example, addition of binary numbers (one of the most common operations needed by a microprocessor) ... |
null |
null |
Thank you posting such an interesting problem.
Presuming you want no two intervals to intersect, here is a possible solution.
We first sort the intervals by their right end point. Suppose the sorted order is
Int_1, Int_2, ... , Int_n.
Now for each interval, we try to compute the size of the largest possibl... |
I need an efficient algorithm that takes input a collection of intervals and outputs the largest subset of non-intersecting intervals.
i.e. Given a set of intervals I = {I1, I2, ..., In}, we need to output a set of intervals O = {O1, O2, ..., Ok} such that
- O is a subset of I
- For any i <> j, Oi and Oj are... |
Algorithm to return largest subset of non-intersecting intervals |
|untagged| |
I need an efficient algorithm that takes input a collection of intervals and outputs the largest subset of non-intersecting intervals.
i.e. Given a set of intervals $I = \{I_1, I_2, \ldots, I_n\}$, we need to output a set of intervals $O = \{O_1, O_2, \ldots, O_k\}$ such that
- $O$ is a subset of $I$.
- For ... |
|algorithms|optimization|integers|intervals|set-cover| |
Thank you posting such an interesting problem.
Presuming you want no two intervals to intersect, here is a possible solution.
We first sort the intervals by their right end point. Suppose the sorted order is
$I_1, I_2, \ldots, I_n$.
Now for each interval, we try to compute the size of the largest possible no... |
Just a quick question,
If i were to alter the general DFS algorithm to do this:
minDFS(Vertex v)
{
if (!v.getVisted())
{
v.setVisited();
Vertex temp = findClosestVertex();
graph.addEdge(v, temp);
minDFS(temp);
}
}
Would I e... |
DFS miniumum spanning tree |
|algorithms|graphs|spanning-trees| |
null |
null |
I understand that destination-based routing builds the "route" from the destination backwards to the source (e.g. if using a spanning tree, then the tree is routed at the destination). With source-based routing the opposite is true: the route is build from the source onwards towards the destination.
However I don't ... |
Destination-based vs source-based routing |
|routing| |
|algorithms|distributed-systems|shortest-path|routing| |
null |
**Definition:** A preserved invariant of a state machine is a predicate, $P$, on
states, such that whenever $P(q)$ is true of a state, $q$, and $q \rightarrow r$ for some state, $r$,
then $P(r)$ holds.
**Definition:** A line graph is a graph whose edges are all on one path.
**Definition:** Formally, a state ma... |
A procedure for Topological sort, proof for its correctness |
|graph-theory|proof-techniques|finite-automata| |
No. Consider the counterexample $C_4$
$V = \{1,2,3, 4\}, E = \{ \{1,2\}, \{2,3\}, \{3, 4\}, \{1,4\} \}$
with $c(1,2) = 1, c(2,3) = 100, c(3,4) = 1, c(1,4) = 2$.
Obviously the MST is the one not containing $\{2,3\}$, but if your algorithm starts at 1, it goes to 2, then to 3 and then to 4 and finds a suboptimal... |
No. Consider the counterexample $C_4$
$V = \{1,2,3, 4\}, E = \{ \{1,2\}, \{2,3\}, \{3, 4\}, \{1,4\} \}$
with $c(1,2) = 1, c(2,3) = 100, c(3,4) = 1, c(1,4) = 2$.
Obviously the MST is the one not containing $\{2,3\}$, but if your algorithm starts at 1, it goes to 2, then to 3 and then to 4 and finds a suboptimal... |
No. Consider the counterexample $C_4$
$V = \{1,2,3, 4\}, E = \{ \{1,2\}, \{2,3\}, \{3, 4\}, \{1,4\} \}$
with $c(1,2) = 1, c(2,3) = 100, c(3,4) = 1, c(1,4) = 2$.
Obviously the MST is the one not containing $\{2,3\}$, but if your algorithm starts at 1, it goes to 2, then to 3 and then to 4 and finds a suboptimal... |
null |
null |
Like Geier said, processors can't directly handle values smaller than a byte. So a boolean type that was actually implemented as just a single bit would in most cases be inefficient. The processor needs to do a bit of extra work to extract just that one bit.
The reason that the boolean type exists is more about se... |
Why do most programming languages (if not all) lack a 2-bit data type?
A **boolean** is a single bit with the values being **either** *true* or *false*.
Why is there no native, corresponding type where the values can be either *true*, *false*, *neither* or *both*? This data type can of course be constructed insid... |
Why is there no two-bit data type? |
|typing| |
Assume there was a database system that had a data type called `VARINT` or some variant that allowed instead of fixed-length `INT`s regardless of value, a `1` would only take 1 `BIT` (`1`), `2` would take 2 `BIT`s (`10`), etc.
In this perfect world, a `VARINT` could be used to `autoincrement` a `PRIMARY` column. Ho... |
VAR autoincrement with constant space consumption for super large tables |
|integers|database-theory|performance| |
**This is an open problem.**
---
Possibly some weak form of 3SUM-hardness could be proved by adapting a result from Mihai Pǎtrașcu's STOC 2010 paper "[Towards Polynomial Lower Bounds for Dynamic Problems](http://people.csail.mit.edu/mip/papers/mp-3sum/paper.pdf)". First, let me define a sequence of closely related... |
Unfortunately there aren't many textbooks on the topic. I think the best way to learn program analysis today is to survey different courses that are available, play with a few implementations and then look at a few research papers for your specific needs. What follows is a very small sampling of what's out there. Since... |
You can also consider an algebraic graph theoretic approach. The diameter $\text{diam}(G)$ is the least integer $t$ s.t. the matrix $M=I+A$ has the property that all entries of $M^t$ are nonzero. You can find $t$ by $O(\log n)$ iterations of matrix multiplication. The diameter algorithm then requires $O(M(n) \log n)$ t... |
No. Consider the counterexample $C_4$
$V = \{1,2,3, 4\}, E = \{ \{1,2\}, \{2,3\}, \{3, 4\}, \{1,4\} \}$
with $c(1,2) = 1, c(2,3) = 100, c(3,4) = 1, c(1,4) = 2$.
Obviously the MST is the one ST not containing $\{2,3\}$, but if your algorithm starts at 1, it goes to 2, then to 3 and then to 4 and finds a subopti... |
There is an $O(n \log n)$ time algorithm (which in some models is optimal, because of the bounds for the element distinctness problem).
We first sort the intervals by their right end point. Suppose the sorted order is
$I_1, I_2, \ldots, I_n$.
Now for each interval, we try to compute the size of the largest possi... |
The reason is that architectures offer the types most often used. If you look at real programs, they handle characters (mostly implemented as 8 bit bytes), much more often integers (for array indices, much computation, things like file sizes). Approximations for real numbers are also important. Boolean values as such ... |
null |
Suppose all costs on edges are distinct. How many minimal spanning trees are possible?
I dont know if this question is supposed to be easy or hard, but all I can come up with is one, because kruskal's, and any other greedy algorithm should choose all the smallest weighted edges first. and if all weights on all edges... |
Minimum spanning trees question |
|greedy-algorithms| |
Consider Kruskal's or Prim's algorithms to get minimal spanning trees. They consider arcs in increasing order of cost. If all costs are different, the order in which they are added is fixed, and so is the spanning tree constructed. It is unique in this case. |
I have this question:
Input:
G(V, E) = an undirected graph
k which is ∈ N
Question:
Is there k nodes in G such that no nodes are connected by an edge?
I want to prove that this is NP-hard by reducing it from a known NPC problem which is Vertex-Cover.
However I don't know exactl... |
How to prove NP-hard? |
|np-complete|proof-techniques|np-hard|check-my-proof|np| |
I have this question:
Input:
G(V, E) = an undirected graph, V={v1, v2, ..., vn} (V = set of nodes, E = set of edges)
where there is a path connecting v1 and vn.
Question:
What is the maximum number of nodes you can visit when starting from v1 and ending at vn.
(including v1 and ... |
I have this question:
Input:
G(V, E) = an undirected graph, V={v1, v2, ..., vn} (V = set of nodes, E = set of edges)
where there is a path connecting from v1 to vn.
Question:
What is the maximum number of nodes you can visit when starting from v1 and ending at vn.
(including v1 ... |
**This is an open problem.**
---
Possibly some weak form of 3SUM-hardness could be proved by adapting a result from Mihai Pǎtrașcu's STOC 2010 paper "[Towards Polynomial Lower Bounds for Dynamic Problems](http://people.csail.mit.edu/mip/papers/mp-3sum/paper.pdf)". First, let me define a sequence of closely related... |
_Recently, I asked a [question](http://math.stackexchange.com/q/334581/17111) on Math SE. No response yet. This question is related to that question, but more technical details toward computer science._
Given two DFAs $A = (Q, \Sigma, \delta, q_1, F_1)$ and $B = (Q, \Sigma, \delta, q_2, F_2)$ where the set of states... |
Difference between the languages accepted by two DFAs with different initial state/accepting states? |
|formal-languages|reference-request|finite-automata| |
Assuming I understand your definition, your problem is the optimisation version of LONGEST PATH:
>**LONGEST PATH**<br/>
>*Input*: A graph $G=(V,E)$, an integer $k$.<br/>
>*Question*: Is there a path with at least $k$ vertices in $G$
This problem is NP-complete, there's a fairly obvious reduction from HAMILTONIA... |
b. As operation $1$ cannot be performed, $H$ must be a DAG. Consider a topological sort of $H$. As $3$ cannot be performed, if $u$ precedes $v$ in the topological sort, there is a path from $u$ to $v$. Start at the initial vertex in the sort and keep moving forward until we find a vertex which has more than one outgoin... |
I am stuck with one of my homework problem, i.e.,
There are 3 processors, P1, P2, P3. P1 can execute only one job while other two can execute any number of jobs parallel.
if there are n jobs, each consisting of 3 parts, and each part is processed by respective processor(eg. part 1 by P1) and part 2 can be executed o... |
Algorithm that takes set of n jobs and determines the the jobs should be processed so that the total time is minimized |
|algorithms|dynamic-programming| |
I am stuck with one of my homework problem, i.e.,
There are 3 processors, P1, P2, P3. P1 can execute only one job while other two can execute any number of jobs parallel.
if there are n jobs, each consisting of 3 parts, and each part is processed by respective processor(eg. part 1 by P1) and part 2 can be executed o... |
Since $A,B$ are strongly connected, then if $q_1\neq q_2$, there exist words $p_1,p_2$ such that $\delta(q_1,p_1)=q_2$ and $\delta(q_2,p_2)=q_1$.
Consider case 2, then $w\in L(A)$ iff $p_2w\in L(B)$, and $x\in L(B)$ iff $p_1 x\in L(A)$. So you can add a prefix to switch between languages.
Consider case 3, then ag... |
Since $A,B$ are strongly connected, then if $q_1\neq q_2$, there exist words $p_1,p_2$ such that $\delta(q_1,p_1)=q_2$ and $\delta(q_2,p_2)=q_1$.
Consider case 2, then $w\in L(A)$ iff $p_2w\in L(B)$, and $x\in L(B)$ iff $p_1 x\in L(A)$. So you can add a prefix to switch between languages.
Consider case 3, then ag... |
null |
Since $A,B$ are strongly connected, then if $q_1\neq q_2$, there exist words $p_1,p_2$ such that $\delta(q_1,p_1)=q_2$ and $\delta(q_2,p_2)=q_1$.
Consider case 2, then $w\in L(A)$ iff $p_2w\in L(B)$, and $x\in L(B)$ iff $p_1 x\in L(A)$. So you can add a prefix to switch between languages.
Consider case 3, then ag... |
null |
Since $A,B$ are strongly connected, then if $q_1\neq q_2$, there exist words $p_1,p_2$ such that $\delta(q_1,p_1)=q_2$ and $\delta(q_2,p_2)=q_1$.
Consider case 2, then $w\in L(A)$ iff $p_2w\in L(B)$, and $x\in L(B)$ iff $p_1 x\in L(A)$. So you can add a prefix to switch between languages.
Consider case 3, then ag... |
I am facing problem in understanding the KMP algorithm as given in the book "Introduction to Algorithm" by Coremen et. al.:
![enter image description here][1]
![enter image description here][2]
With respect to the above algorithm, I have following question:
1- In both the algorithms, where exactly (wh... |
Unable to understand control flow in KMP algorithm |
|search-algorithms| |
I am facing problem in understanding the KMP algorithm as given in the book "Introduction to Algorithm" by Coremen et. al.:
![enter image description here][1]
![enter image description here][2]Chapter 32.
With respect to the above algorithm, I have following question:
1- In both the algorithms, wher... |
null |
Suppose all costs on edges are distinct. How many minimal spanning trees are possible?
I dont know if this question is supposed to be easy or hard, but all I can come up with is one, because Kruskal's, and any other greedy algorithm should choose all the smallest weighted edges first. Then, if all weights on all edg... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.