instruction
stringlengths
0
29.8k
⌀
The node weighted Steiner Tree Problem as found in [this compendium][1]: $\textbf{Instance}: \text{Graph } G = (V, E)\text{, set of terminals } S \subseteq V \text{ and a node weight function } w:V \to \mathbb{R}^+$ $\textbf{Solution}: \text{A tree } T = (V_T,E_T) \text{ in } G \text{, such that } S\subseteq V_T ...
Since all vertex weights are equal, minimizing $\sum_{v \in V_T} w(v)$ is equivalent to minimizing $|V_T|$, and since a tree on $x$ vertices has exactly $x-1$, edges, this is equivalent to minimizing $|E_T|$. Therefore your problem [is NP-hard](https://cstheory.stackexchange.com/questions/19477/steiner-tree-problem-...
I have run $k$-means on a large set of high-dimensional data, and now I want to find the distance from a point $x$ to a cluster $C$ (i.e., the distance between $x$ and $y$, where $y$ is the closest point to $x$ that would be assigned to $C$, even though $y$ may not actually be in the dataset). Can this be done efficie...
Efficiently find the distance, or approximate distance, from a point to a cluster, or all clusters, in k-means or another type of clustering
|algorithms|computational-geometry|clustering|
Can an algorithm decide whether any DFA accepts an infinite language? What is its time complexity?
null
I have run $k$-means on a large set of high-dimensional data, and now I want to find the distance from a point $x$ to the Voronoi cell associated with one of the $k$ centroids. (In a previous version of the question, I called this cell a "cluster", but that terminology might be confusing since one might think of a clu...
Efficiently find the distance from a point to the decision boundary for assigning points to a particular $k$-means cluster
Your proof of the halting problem is missing an essential assumption, which may be confusing you: it is essential to assume that $h$ *always halts*, i.e., that $h(x, y)$ does not have to run $x(y)$ in order to return. If you remove this assumption, the proof no longer works. If you can find the exact spot and reason ...
In addition to the answers linked by Rinkesh P. in a comment, here is an approach that directly translates into an efficient algorithm. The DFA accept an infinite language if and only if there is a walk from the starting state to a final state that contains a cycle. To obtain an algorithm consider the directed ...
I have run $k$-means on a large set of high-dimensional data, and now I want to find the distance from a point $x$ to the Voronoi cell associated with one of the $k$ centroids. (In a previous version of the question, I called this cell a "cluster", but that terminology might be confusing since one might think of a clu...
null
If you have a pure lambda-term of type $\forall t.\,t$ in System F, you can conclude by parametricity theorems that this term satisfies the law of natural transformations of type $\forall t.\,\underline 1 \to t$ (where I denote the unit type by $\underline1$). Then you write the naturality law: for an arbitrary functio...
Wadler's paper does not talk explicitly about what to do with arbitrary type constructors. Neither Wadler nor Reynolds explain how to define the relations you denote by $f_F$ and $f_G$. Wadler also doesn't point out the cases when his "free theorems" are naturality laws of the kind you are writing, and the cases whe...
Wadler's paper does not talk explicitly about what to do with arbitrary type constructors. Neither Wadler nor Reynolds explain how to define the relations you denote by $f_F$ and $f_G$. Wadler also doesn't point out the cases when his "free theorems" are naturality laws of the kind you are writing, and the cases whe...
I have been struggling with this contest problem for awhile now which is found at this link: https://people.eecs.berkeley.edu/~hilfingr/programming-contest/pacific-northwest/2009/b.pdf [![https://people.eecs.berkeley.edu/~hilfingr/programming-contest/pacific-northwest/2009/b.pdf][1]][1] Short summary of problem: ...
Recursive DFS Problem
|recursion|depth-first-search|
Wadler's paper does not talk explicitly about what to do with arbitrary type constructors. Neither Wadler nor Reynolds explain how to define the relations you denote by $f_F$ and $f_G$. Wadler also doesn't point out the cases when his "free theorems" are naturality laws of the kind you are writing, and the cases whe...
Here is a simple answer. If you have a pure lambda-term of type $\forall t.\,t$ in System F, you can conclude by parametricity theorems that this term satisfies the law of natural transformations of type $\forall t.\,\underline 1 \to t$ (where I denote the unit type by $\underline1$). Then you write the naturalit...
Here is the puzzle I was asked in an interview There's a List of Employee objects. Update all the objects in the list to be eligibleForHike if at least one employee exists whose salary is less than x; otherwise update all of them in-eligibleForHike in a single iteration/loop **Requirements/Restrictions**: 1. ...
Java set a property of all objects in a List when at least one object satisfies a criteria using a single loop
|optimization|mathematical-programming|program-optimization|optimal-strategy|
null
I'm preparing some material for students about greedy algorithms, and there is one point that confuses me: how Dijkstra's algorithm fits into the greedy framework. I would like to say that we have some optimization problem $\min_{S \in D} f(S)$. E.g.: * For MST, $S$ is a spanning tree and $f(S) = \sum_{e \in S} w(e...
Dijkstra as a greedy algorithm
|optimization|greedy-algorithms|dijkstras-algorithm|
|algorithms|data-structures|optimization|java|program-optimization|
What you have thought is a good start. However, more argument are needed to establish the proposition. **Towards a contradiction** assume both insertion and extraction can be done in $o(\log n)$. Given $n$ items, we can insert all of them into the priority queue and then extract almost min $n$ times to obtain a ...
What you have thought is a good start. However, more arguments are needed to establish the proposition. ------ Given $n$ items, we can insert all of them into the priority queue and then extract almost min $n$ times to obtain a list of all elements. Unfortunately, the obtained list is not sorted unless the minimu...
If you want to compute distance to the closest (different) cluster, then problem is $\Theta(kd)$ as you just need to compute distance to $k$ hyperplanes. However, if you want to compute distance (of a point $p$) to a general cluster, you need to solve a Quadratic program (QP). Voronoi cell is a solution to a set of lin...
null
What you have thought is a good start. However, more arguments are needed to establish the proposition. ------ Given $n$ items, we can insert all of them into the priority queue and then extract almost min $n$ times to obtain a list of all elements. Unfortunately, the obtained list is not sorted unless the minimu...
Yes, instead of the shortest path problem, we should consider the all shortest path problem (ASPP). That must be a correct approach since finding all shortest path problem *could have been* the given problem. You would not even have a choice then. Also, one idea illustrated by Dijkstra's algorithm is it is often ...
This looks very hard to me. I wouldn't be surprised if it is NP-hard. If I had to solve it in practice, my first thought would be to try to solve it using a SAT solver. Formulating this as an instance of SAT is a little tricky, but I outline below one approach you could try. Given $k$, let's figure out whether ...
This looks very hard to me. I wouldn't be surprised if it is NP-hard. If I had to solve it in practice, my first thought would be to try to solve it using a SAT solver or an ILP solver. I outline below how you could do that. Given $k$, let's figure out whether there is a way to solve this using $k$ groups. If ...
Yes, instead of the shortest path problem, we should consider the all shortest path problem (ASPP). That must be a correct approach since finding all shortest path problem *could have been* the given problem. You would not even have a choice then. Also, one idea illustrated by Dijkstra's algorithm is it is often ...
null
I'm wondering about the optimal complexity - or at the very least, some way of achieving non-terrible complexity - of a particular stack variant, that I'm calling a 'nonrepetitive stack'. A nonrepetitive stack is like an ordinary stack, except that a push that would result in a repeated subsequence instead fails, no...
Optimal algorithmic complexity of stack varient?
|time-complexity|data-structures|asymptotics|
What you have thought is a good start. However, more arguments are needed to establish the proposition. ------ Given $n$ items, we can insert all of them into the priority queue and then extract almost min $n$ times to obtain a list of all items. Unfortunately, the obtained list is not sorted unless the minimum i...
null
I'm going to pull my answer from the book *Introduction to the Design and Analysis of Algorithms* by Anany Levitin. Anything in blockquotes is directly from the book. Here's the steps he gives in the book: [![algorithm flow chart][1]][1] **1. Understanding the Problem** > Read the problem’s description care...
As is well-known (and easy to prove), carrying out a sieve of Eratosthenes on the first $N$ integers takes a number of word operations in the order of $N \sum_{p\leq \sqrt{N}} 1/p \sim N \log \log N$, whether one uses it for finding the primes up to $N$ or for factoring the numbers up to $N$. It is also well-known that...
Sieve of Eratosthenes for factorization: bitwise complexity?
|time-complexity|runtime-analysis|reference-request|number-theory|
As is well-known (and easy to prove), carrying out a sieve of Eratosthenes on the first $N$ integers takes a number of word operations in the order of $N \sum_{p\leq \sqrt{N}} 1/p \sim N \log \log N$, whether one uses it for finding the primes up to $N$ or for factoring the numbers up to $N$. It is also well-known that...
I am thinking about the problem of storing traces of games like Chess and Othello in an information-theoretic minimal number of bits. My idea was to think of a game as an ordered tree of possible moves that could be taken. Let's say in one game there are 20 moves available initially, then 8 on the second turn, then...
Storing game traces (e.g. Chess, Othello) in a minimal number of bits
|information-theory|number-theory|board-games|
If the number of possible moves does not depend on the game history (say, at the third move there are always 5 possibilities), then the "mixed-radix" scheme you describe is optimal, as it encodes all integers in the range of the number of possible games. But it is difficult to encode/decode because you need to trace...
If the number of possible moves does not depend on the game history (say, at the third move there are always 5 possibilities), then the "mixed-radix" scheme you describe is optimal, as it encodes all integers in the range of the number of possible games. But it is difficult to encode/decode because you need to trace...
null
If the number of possible moves does not depend on the game history (say, at the third move there are always 5 possibilities), then the "mixed-radix" scheme you describe is optimal, as it encodes all integers in the range of the number of possible games. But it is difficult to encode/decode because you need to trace...
null
According to the [computer organization and design RISC-V 2nd edition 2020](https://www.elsevier.com/books/computer-organization-and-design-risc-v-edition/patterson/978-0-12-820331-6), section 1.5, the instruction set architecture (ISA) affects the clock rate. But I cannot understand how. Since there can be many imp...
How does instruction set architecture affects clock rate?
|computer-architecture|cpu|instruction-set|
I have a grammar which is mostly `LL(1)`, save for the fact that some tokens may be promoted to larger integer types. For example, let take the following grammar ``` S ::= terminal1 S1 S1 ::= integer_16 S2 | integer_32 S3 ``` where `S2` and `S3` can share a common prefix but we assume the above grammar can ...
Grammar where tokens can be transmuted
|formal-grammars|
Consider the following schedule: ```python for k = 1, 2, 3, 4...: T_k = 2^k for all programs p ordered by increasing length: if floor(T_k 2^{-l(p)}) > 0: # equiv to: if l(p) ≤ k run p for T_k 2^{-l(p)} steps # = 2^{k-l(p)} if p has halted (on its own) and the output string matches the targe...
null
According to the [computer organization and design RISC-V 2nd edition 2020](https://www.elsevier.com/books/computer-organization-and-design-risc-v-edition/patterson/978-0-12-820331-6), section 1.5, the instruction set architecture (ISA) affects the clock rate. But I cannot understand how. Since there can be many imp...
Here is the puzzle I was asked in an interview There's a List of Employee objects. Update all the objects in the list to be eligibleForHike if at least one employee exists whose salary is less than x; otherwise update all of them in-eligibleForHike in a single iteration/loop **Requirements/Restrictions**: 1. ...
Update a property of all objects in a List/Collection/Array when at least one object satisfies a criteria using a single loop
null
null
You can use [BFS][1] to find a shortest path as long as you specify what "vertices" and "edges" are in this graph. One way is the following: A *vertex* is an ordered list (call it $L$) of $n$ ordered pairs (representing locations in the grid) such that 1. consecutive pairs are "neighbors", 2. $n$ unique locations ...
This has been completely rewritten today 2022-09-16 to address all of the objections from thousands of reviews in the last 12 months. **Are the halting problem proofs refuted by software engineering ?** void Px(ptr x) { int Halt_Status = Hx(x, x); if (Halt_Status) HERE: goto HE...
null
I have run $k$-means on a large set of high-dimensional data, and now I want to find the distance from a point $x$ to the Voronoi cell associated with one of the $k$ centroids. (In a previous version of the question, I called this cell a "cluster", but that terminology might be confusing since one might think of a clu...
I am running into a problem in which I have names with different romanization methods, and I need to correctly compare them to see which names match. An example is romanized Korean variants: Seong vs Sung vs Song are all romanized variants of the same Korean character. A Levenshtein ratio would say that these are al...
Correctly compare names with different romanization?
|algorithms|natural-language-processing|
You cannot address this without a complete list of character variants. Then you can precompute the legit combinations of all names and perform the comparison against all groups so obtained, keeping the shortest distance. E.g. to match Kyong to Kyung, perform comparisons to Kyung and Kyeong, resulting in 1 substituti...
null
@rici wrote a very good answer. I actually intended to write a comment but I write it as answer instead. I can think of only these reasons: first POSIX as mentioned before. Second a misunderstanding. Third, formal language theory could have influenced it. **For the first reason,** my subjective opinion is, the be...
Also known as CMU 15-455, Spring 2017, Homework 2.4. Before I ask the main questions, let me first give a sketch of my idea. First, recall the definition of big-$O$ and time complexity class $TIME(t(n))$. - **Definition:** Let $f$ and $g$ be functions $f$, $g$: $\mathbb{N}$ $\rightarrow$ $\mathbb{R}^+$. Say that...
Show that $TIME(\sqrt{n})$ = $TIME(1)$
|time-complexity|runtime-analysis|
Also known as CMU 15-455, Spring 2017, Homework 2.4. Before I ask the main questions, let me first give a sketch of my idea. First, recall the definition of big-$O$ and time complexity class $TIME(t(n))$. - **Definition:** Let $f$ and $g$ be functions $f$, $g$: $\mathbb{N}$ $\rightarrow$ $\mathbb{R}^+$. Say that...
Also known as CMU 15-455, Spring 2017, Homework 2.4. Before I ask the main questions, let me first give a sketch of my idea. First, recall the definition of big-$O$ and time complexity class $TIME(t(n))$. - **Definition:** Let $f$ and $g$ be functions $f$, $g$: $\mathbb{N}$ $\rightarrow$ $\mathbb{R}^+$. Say that...
Also known as CMU 15-455, Spring 2017, Homework 2.4. Before I ask the main questions, let me first give a sketch of my idea. First, recall the definition of big-$O$ and time complexity class $TIME(t(n))$. - **Definition:** Let $f$ and $g$ be functions $f$, $g$: $\mathbb{N}$ $\rightarrow$ $\mathbb{R}^+$. Say that...
**Solution**: Have a reference which dictates the `hikeEligibility` which can be `false` by default. Iterate and assign the same reference to all the objects in the collection. If at least one item in the collection meets the criteria, set the value of `hikeEligibility` to `true` public List<Employee> checkAndU...
null
What you have thought is not a bad start. However, more arguments are needed to establish the proposition. ------ Given $n$ items, we can insert all of them into the priority queue and then extract almost min $n$ times to obtain a list of all items. Unfortunately, the obtained list is not sorted unless the minimu...
Suppose we want to create a priority queue with 2 operations: insert and extract almost min. Extract almost min operation selects either the first minimum or a second minimum item from the structure randomly, removes that item from the structure and outputs that item. How can we prove that both of these operations c...
How can we prove that "extract almost minimum" operation in a priority queue cannot be done in o(log n)?
|algorithms|data-structures|algorithm-analysis|runtime-analysis|priority-queues|
The type of a literal integer is semantic, not syntactic, and should not be part of syntactic analysis. In other words, the program text can be *parsed* -- broken into syntactic parts with known relationships -- without knowing the magnitude of each integer literal. The magnitude of the literal does not affect the lite...
null
Suppose $l=[a[0],a[1],...,a[n]]$ be a list of n numbers. I need to calculate $$\sum a[j] a[k] a[j'] a[k']$$ such that $j+k=j'+k'$ .Obviously we can implement it in $O(n^4)$ time complexity by the exhaustive search method.Can we do it better?It is pertinent to mention the number of tuples satisfying $j+k=j'+k'$ are appr...
Improving an algorithm involving two pairs of sums
|time-complexity|
It's trivial to do in $O(n^3)$ time, by enumerating all $O(n^3)$ tuples $(j,k,j',k')$ such that $j+k=j'+k'$, computing the appropriate product, and summing those products. You can do it in $O(n^2)$ time with a bit more cleverness, by using the distributive property. It's a nice exercise, so I'll let you have the fu...
Suppose $l=[0,1,2,,n]$ be a list of n numbers. I need to enumerate the tuples (j,k,j',k') such that $j+k=j'+k'$ .Obviously we can implement it in $O(n^4)$ time complexity by the exhaustive search method.Can we do it better?It is pertinent to mention the number of tuples satisfying $j+k=j'+k'$ are approximately $n^3....
It's trivial to do in $O(n^3)$ time, by enumerating all $O(n^3)$ tuples $(j,k,j',k')$ such that $j+k=j'+k'$, computing the appropriate product, and summing those products. You can compute this sum in $O(n^2)$ time with a bit more cleverness, by using the distributive property. It's a nice exercise, so I'll let you ...