instruction
stringlengths
0
29.8k
⌀
Assume that all elements are distinct (if not, replace each element with a pair $(element, position)$ and perform the comparisons lexicographically) and consider a rooted binary tree $T$ in which each vertex has either $0$ or two children and every level, except possibly the last, is completely filled. Arbitrarily asso...
Assume that all elements are distinct (if not, replace each element with a pair $(element, position)$ and perform the comparisons lexicographically) and consider a rooted binary tree $T$ in which each vertex has either $0$ or two children and every level, except possibly the last, is completely filled. Arbitrarily asso...
null
Assume that all elements are distinct (if not, replace each element with a pair $(element, position)$ and perform the comparisons lexicographically) and consider a rooted binary tree $T$ with $n$ leaves in which each vertex has either $0$ or two children and every level, except possibly the last, is completely filled. ...
We have a bipartite graph with parts $A$ and $B$, and it is edge weighted. We have some constraints for part $B$. Each constraint is in this format: Between vertices $b_1$ and $b_2$ both from part $B$, at most one of them can be matched. The goal is to find the maximum weighted matching which qualifies these constraint...
Bipartite matching with constraints on one part
|np-hard|weighted-graphs|bipartite-matching|constraint-satisfaction|polynomial-time-reductions|
null
Given that $L∈\textrm{P}$, how do we show that an arbitrary subset $L_{A}$ of $L$ is also in P?
How to prove that a subet set of a language L that is in P is also in P?
|complexity-theory|turing-machines|
How to prove that the subset of a language L that is in P is also in P?
By $\textrm{P}$ do you mean the languages that are decidable in polynomial time? If so, I am pretty sure this isn't true. For example, let $L$ be the language of graphs that are 2-edge-connected, and $L_A$ the language of graphs that contain Hamiltonian cycles. Then $L \in \textrm{P}$ and $L_A \subseteq L$ but $L_A \no...
You cannot show that, since the claim is false. Let $L = \Sigma^*$ and let $L_A \subset \Sigma^*$ be the language of the halting problem. Clearly $L \in \mathsf{P}$ (a Turing machine that decides $L$ is the one that ignores its input and immediately accepts). However $L_A$ is well-known to be undecidable (and hence no...
The problem is not approximable in polynomial-time within a factor of $n^{1-\varepsilon}$ for any constant $\varepsilon>0$, unless $\mathsf{NP} = \mathsf{ZPP}$. To see this you can reduce from independent set. Let $G$ be of independent-set. Define $H$ as the graph that contains two-vertices $v_A, v_B$ for each verte...
By $\textrm{P}$ do you mean the languages that are decidable in polynomial time? If so, I am pretty sure this isn't true. For example, let $L$ be the language of graphs that are 2-edge-connected, and $L_A$ the language of graphs that contain Hamiltonian cycles. Then $L \in \textrm{P}$ and $L_A \subseteq L$ but $L_A \no...
How to use importance sampling identity to obtain the Chernoff bounds as given below? Let X have moment generating function $\phi(t)= E[e^{tX}]$. Then, for any c > 0 , $P[X\geq c ]\leq e^{-tc} \phi(t), \text{if t > 0}$ $P[X \leq c]\leq e^{-tc}\phi(t), \text{if t<0} $
Chernoff bounds using importance sampling identity
|sampling|chernoff-bounds|
null
null
null
TL;DR --- I have some ideas but am curious to know if there are existing proofs, research, etc. in this area that I can use to guide my algorithm development. Problem summary --- We have a population where each sample has attributes, or tags, associated with it. The cardinality of the tag set is unbounded, bu...
Given a population, find the boolean algebra expressions that most closely evaluate to that population
|algorithms|logic|
null
Assume I generate a random binary tree with a bounded height with $n$ nodes. For a given key we measure the length of its path (the maximum can be $n-1$). So my Question is what is the distribution of the path length? The tree is constructed by recursively partitioning the given n points until all points are isolat...
What is the depth distribution of a random binary tree with n nodes?
I've been trying to solve a variation of this problem https://stackoverflow.com/questions/62389658/best-time-to-buy-and-sell-stocks-when-allowing-consecutive-buys-or-sells You are given an input array of non-negative integers. You are allowed to either buy 1 share or sell any number of shares that you own, or not ma...
null
null
Query the least significant bit (LSB) of all the numbers and split them into two sets $E, O$ where $E$ contains the even numbers (the least significant bit is 0) and $O$ contains the odd numbers. Now xor together all these bits. If the result matches the LSB of $\sum_{i=0}^n i = \frac{i(i+1)}{2}$ then the missing nu...
Good day everyone, I'm currently trying to carry out the PetersonNP (a.k.a. FilterLock) correctness proof (mutual exclusion). I've found several proof sketches on concurrency books but I'm interested in the one shown in `Distributed Algorithms` (by Nancy Lynch). I find it more convincing because lemmata required for ...
null
null
The weights are stored in a matrix rather than a vector so that the weighting can be expressed as a matrix/vector product. E.g. $$\begin{pmatrix}w_0&0&0\\0&w_1&0\\0&0&w_2\end{pmatrix}\begin{pmatrix}c_0\\c_1\\c_2\end{pmatrix}=\begin{pmatrix}w_0c_0\\w_1c_1\\w_2c_2\end{pmatrix}.$$ This is a common trick in linear...
Based on Steven's great answer, and some modification so that the second minimum is computed "on the fly" (this won't change the number of comparison) below implemented the algorithms in C++ that also prints the tree for visualization e.g. with input array L = `3,1,5,2,4` the second smallest is `2` and the tree is p...
Following a previous post on the cs stack exchange ([link to question][1]), I have been searching to no avail for an implementation of a disjunctive programming solver in C# (or wrapped in C#). In this question, I'll go into more depth in regards to my specific problem in case there is a better solution. I am looki...
Which algorithms could be suitable for solving my disjunctive programming problem?
|algorithms|linear-programming|integer-programming|mathematical-programming|
null
null
null
It is important to know that endianness applies to multi-byte primitive data types. These occupy 2 (short), 4 (int, float) or 8 bytes (long log, double) and are stored as a whole. There are two obvious ways to store these bytes: by increasing (little-endian) or decreasing weights (big-endian). The qualifier refers t...
null
It is important to know that endianness applies to multi-byte primitive data types. These occupy 2 (short), 4 (int, float) or 8 bytes (long log, double) and are stored as a whole. There are two obvious ways to store these bytes: by increasing (little-endian) or decreasing weights (big-endian). The qualifier refers t...
On Wikipedia the error rate for the minhash algorithm vs baseline jaccard similarity [is stated as `1/sqrt(1/hashes)`](https://en.wikipedia.org/wiki/MinHash#Algorithm). But, how should one interpret this number in a practical scenario? It seems to me that this must mean `avg(abs(minhash_similarity - jaccard_similari...
What about using a local search solver like [Timefold][1] or [LocalSolver][2]? In particular, LocalSolver has a C# API, which seems to address your need. [1]: https://timefold.ai/ [2]: https://www.localsolver.com/
null
How can I create a DFA table that has memory such that I could write a rule for this DFA that states `accept state B after accepting state A at some point (doesn't matter when. Could have been the last state or 5 states ago)`. I'm not even sure if creating a DFA state transition table like this is possible, hence wh...
How to create a DFA with memory
|finite-automata|
Query the least significant bit (LSB) of all the numbers and split them into two sets $E, O$ where $E$ contains the even numbers (the least significant bit is 0) and $O$ contains the odd numbers. Now xor together all these bits. If the result matches the LSB of $\sum_{i=0}^n i = \frac{i(i+1)}{2}$ then the missing nu...
I am confused by some of your terminology. By "DFA table" do you mean the DFA's transition function? Also you want a rule of the form "Accept state $B$ after accepting state $A$" but an accepting state of a DFA is (basically) a terminating state. Do you mean that $B$ should be an accepting state only after visiting $A$...
null
null
How can I create a DFA that has memory such that I could write a rule for this DFA that states `transition to state B after transitioning from state A at some point (doesn't matter when. Could have been the last state or 5 states ago)`. I'm not even sure if creating a DFA like this is possible, hence why I'm asking ...
I'm confused on how to prove the below using induction: T(n) = 3T(n/9) + √n I have been given the base case T(1) = 1. I know using the master theorem that the time complexity is O(√n log n). However, when trying to find the inductive hypothesis (function form) of the recurrence by substituting k = 0, 1, 2, 3... i...
Proving T(n) = 3T(n/9) + n^1/2 using induction
|induction|
$$\begin{align}T(9^4)&=3T(9^3)+3^4 \\&=3(3T(9^2)+3^3)+3^4=3^2T(9^2)+2\cdot3^4 \\&=3^2(3T(9)+3^2)+2\cdot3^4=3^3T(9)+3\cdot3^4 \\&=3^3(3T(1)+3^1)+3\cdot3^4=3^4T(1)+4\cdot3^4 \end{align}$$ and we can infer $$T(9^m)=3^m(T(1)+m),$$ which is $$T(n)=\sqrt n(T(1)+\log_9(n)).$$ ---------- **Verification:** ...
**Other method:** We divide both membres by $\sqrt n$: $$\frac{T(n)}{\sqrt n}=\frac{3T\left(\dfrac n9\right)}{\sqrt n}+1=\frac{T\left(\dfrac n9\right)}{\sqrt{\dfrac n9}}+1.$$ This is of the form $$S(n)=S\left(\frac n9\right)+1$$ and denotes the number of times you can divide by $9$ before reaching $1$, or $...
You can eliminate `B` by substituting all its expansions wherever it appears, giving the equivalent grammar A' -> A A -> if A A -> if A else S A -> null
This problem is polynomially equivalent to the Knapsack problem. It is quite easy to reduce the Knapsack problem to this problem, where given a list of items $L$ and a budget $k$, one can build the following instance of your problem, where your own list contains exactly one item of value $0$ and price $k$, meanwhile...
How to identify Dominant terms in big-O notation and understand Time Complexity of an algorithm?
null
null
null
Numerical examples can be misleading. $$100^{20}=10000000000000000000000000000000000000000, \\3^{100}=515377520732011331036461129765621272702107522001.$$ ---------- When you consider the ratios $\dfrac{T(n+1)}{T(n)}$, you get $$\frac{(n+1)^{20}}{n^{20}}=\left(1+\frac1n\right)^{20}\sim1+\frac{20}n$$ and ...
Numerical examples can be misleading. $$100^{20}=10000000000000000000000000000000000000000, \\3^{100}=515377520732011331036461129765621272702107522001.$$ ---------- When you consider the ratios $\dfrac{T(n+1)}{T(n)}$, you get $$\frac{(n+1)^{20}}{n^{20}}=\left(1+\frac1n\right)^{20}\sim1+\frac{20}n\to1$$ ...
I need help with this task, so if anyone is willing to help me, I would be grateful. The task is: Given a discrete information source that generates symbols from the set `{M,A,$}` with probabilities `{0,4;0,4;0,2}` respectively. a) Determine the entropy of the source. What is the minimum mean length of lossless co...
Minimum mean length of code words
|entropy|huffman-coding|
null
What does it mean for a shell to parse its command line and to identify the PATH?
First of all, obviously there is a flaw in my logic and I just want to know what it is. So here is my idea: Given a TM M and an input string ω, simulate M on ω on another TM S. For every change of state on M record the TM's configuration. On all iterations compare the new configuration to every other recorded configur...
Why can't we use computation history to detect looping of a Turing machine on a given input?
|computability|undecidability|
You somehow confuse the result of the multiplications and the time they take. $$x^{n/2}\cdot x^{n/2}$$ does not take $T(\frac n2)\cdot T(\frac n2)$ units of time but $T(\frac n2)+M+T(\frac n2)$ where $M$ denotes the time for a multiplication (assuming they can be done in constant time). Hence the complete recu...
The following theorem was proven by R.E. Tarjan in 1984: >**Theorem (Sequential Access Theorem).** If we access each of the nodes of an arbitrary initial tree once, in symmetric order, the total time spent is $O(n)$ But if we remove the smallest element one at a time, then does it imply that we sorted the element...
Splay Trees - Sequential Access Theorem & lower bound for comparison-based sorting
|data-structures|binary-search-trees|amortized-analysis|splay-trees|
The following theorem was proven by [R.E. Tarjan in 1984][1]: >**Theorem (Sequential Access Theorem).** If we access each of the nodes of an arbitrary initial tree once, in symmetric order, the total time spent is $O(n)$ But if we remove the smallest element one at a time, then does it imply that we sorted the el...
There is nothing wrong in saying that if you access the nodes of a BST (not necessarily a splay tree) in symmetric order in time $O(n)$ then the sequence of the resulting elements is sorted. However this alone is not enough to obtain a sorting algorithm that runs in time $O(n)$ since you're disregarding the time nee...
There is nothing wrong in saying that if you access the nodes of a BST (not necessarily a splay tree) in symmetric order in time $O(n)$ then the sequence of the corresponding elements is sorted. However this alone is not enough to obtain a sorting algorithm that runs in time $O(n)$ since you're disregarding the time...
Is it valid to have the token split up, in a parser; as shown in the below grammar: expr -> expr addop term term -> term mulop factor factor -> factor digit | digit addop -> + | - mulop -> * | / digit -> 0 | 1 | ... | 9 Say, for the arithmetic expression: 1...
Can parser split tokens?
|compilers|
Is it correct to state that the below grammar can handle the expression: a - b * c, by the below two different parse trees. Grammar: Expression = Expression "-" Expression | Expression "*" Expression | Factor Factor = "a" | "b" | "c" Parse tree #1: Expression -> Expression - Express...
Correct way to derive parse trees, for a given input, to show ambiguity
|compilers|
Detecting whether a machine $M$ is *looping* (meaning that it has reached the same configuration (**not only of its internal state but also of the tape**) twice), is indeed as "easy" as recording the configurations as we simulate $M$ and checking whether the current one was already seen. This method is of course inc...
Is it correct to state that the below grammar can handle the expression: a - b * c, by the below two different parse trees. Grammar: Expression = Expression "-" Expression | Expression "*" Expression | Factor Factor = "a" | "b" | "c" Parse tree #1: Expression -> Expression - Express...
Is it correct to state that the below grammar can handle the expression: a - b * c, by the below two different parse trees. Grammar: Expression = Expression "-" Expression | Expression "*" Expression | Factor Factor = "a" | "b" | "c" Parse tree #1: Expression -> Expression - Express...
Is it correct to state that the below grammar can handle the expression: a - b * c, by the below two different parse trees. Grammar: Expression = Expression "-" Expression | Expression "*" Expression | Factor Factor = "a" | "b" | "c" Parse tree #1: Expression -> Expression - Express...
{"Voters":[{"Id":113534,"DisplayName":"Hugh Mann"}]}
I think this is a solution. Works better with 1-based indices. // 1 2 3 4 5 // +--------------- ... // 1 | 1 // 2 | 2 3 // 3 | 4 5 6 // 4 | 7 8 9 10 // 5 | 11 12 13 14 15 // ... Let `i` be the 1D index. Then we have `i < (row^2 + row /...
null
null
null