instruction
stringlengths
0
29.8k
⌀
|binary|
How we can prove that 2n−1 comparisons are sometimes necessary to correctly merge two sorted sequences of n elements each into one sorted sequence? I tried to prove it with binary decision tree, but it was not working.
Why 2n−1 comparisons are sometimes necessary to correctly merge two sorted sequences
|data-structures|
null
How we can prove that the largest element in a min-heap using a comparison-based algorithm takes Ω(logn) time? Is this useful that worst running time for comparison based sorting is >= longest path from root to leaf = height of the tree >= log(n!) = Ω(logn)?
Why finding the largest element in a min-heap using a comparison-based algorithm takes Ω(logn) time?
|data-structures|
How we can prove that $2n−1$ comparisons are sometimes necessary to correctly merge two sorted sequences of $n$ elements each into one sorted sequence? I tried to prove it with binary decision tree, but it was not working.
Why $2n−1$ comparisons are sometimes necessary to correctly merge two sorted sequences
null
null
So, we are given a 100 long array, with 97 0s and 3 1s of which we do not know the locations. We must find them using only a compare function, which I managed to write (in Python): def compare(i, j): comparisons.append((i, j)) if data[i] == data[j]: return 0 else: ...
So, we are given a 100 long array, with 97 0s and 3 1s of which we do not know the locations. We must find them using only a compare function, which I managed to write (in Python): def compare(i, j): comparisons.append((i, j)) if data[i] == data[j]: return 0 else: ...
> returns a function and two variables No, it returns the result of applying the function to these two arguments. This result of course uses the arguments. Instead, consider this. I don't know what function `both` is, but let's say it works on numbers. if you calculate e.g. `(x => y => both x y) 1 2`, it will be:...
So, we are given a 100 long array, with 97 0s and 3 1s of which we do not know the locations. We must find them using only a compare function, which I managed to write (in Python): def compare(i, j): comparisons.append((i, j)) if data[i] == data[j]: return 0 else: ...
> Is this useful that worst running time for comparison based sorting is >= longest path from root to leaf = height of the tree >= log(n!) = Ω(logn)? It is useful if we interpret $\log n!$ as $n \log n$. > How we can prove that the largest element in a min-heap using a comparison-based algorithm takes Ω(logn) tim...
Let the sequences be $A_{1..n}$ and $B_{1..n}$, merging takes $2n - 1$ comparisons if $A_1 < B_1 < A_2 < B_2 < A_3 < B_3 < \cdots < A_n < B_n$. It compares $A_1$ with $B_1$, $A_2$ with $B_1$, $A_2$ with $B_2$, $A_3$ with $B_2$, $A_3$ with $B_3$, to $A_n$ with $B_n$. It is identical to $A_1$ with $B_1$, $B_1$ with...
Suppose I have a decision problem $\mathcal{L}\subseteq\Sigma^*$ and a verifier $V$ that recognizes $\mathcal{L}$, i.e. $L(V)=\mathcal{L}$. Let's arbitrarily choose some certificate $c(w)$ for $w \in \mathcal{L}$ such that $V$ accepts $(w,c)$. Let's consider the functions that bound the size of the certificate $|c(w)|$...
Size of the certificate as a property of the problem
|complexity-theory|
{"OriginalQuestionIds":[57726],"Voters":[{"Id":22714,"DisplayName":"orlp"},{"Id":79440,"DisplayName":"Nathaniel"},{"Id":65339,"DisplayName":"Discrete lizard"}]}
null
I would say you have made a good case that it is at least a little bit interesting, because imposing different bounds on the length of the witness, combined with different bounds on the running time of the verifier, yields different complexity classes. A few nitpicky remarks: 1) The length of witnesses depends on...
null
NULL is the name of the character. SOH is the name of the ASCII character with code 1. It’s just a name.
null
## Problem Statement My wife's business runs a summer camp for 68 students. The students are divided into cabins: - 27 students in 3 groups of 7 and one group of 6 belong in one set of 4 cabins; - 41 students in 5 groups of 7 and one group of 6 belong in the other set of 6 cabins. Which set of cabins a studen...
Can you identify this assignment problem and efficient solutions or estimates?
|approximation|assignment-problem|
null
null
This question should be asked on the SO... But anyway: 1. Create a [CGAL 2D Arrangement][1] from your set of polygons with holes. 2. Mark faces of this arrangement, which you consider unwanted, by the `false` boolean value. 3. Call the function `CGAL::locate` on this arrangement and your array of random points, an...
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
Constrained Maximum Flow Minimum Cost
|complexity-theory|np-hard|network-flow|
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
This question should be asked on the SO... But anyway: 1. Create a [CGAL 2D Arrangement][1] from your set of polygons with holes. 2. Mark faces of this arrangement, which you consider unwanted, by the `false` boolean value. 3. Call the function `CGAL::locate` on this arrangement and your array of random points, an...
A standard approach that is very general is to formulate this as an instance of integer linear programming, and apply an off-the-shelf ILP solver. The field of operations research deals with a lot of combinatorial optimization problems, such as arise in scheduling and logistics, and ILP solvers are one standard tool f...
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
In the modern digital era, character code 0 could have been any useful thing, such as "0" or "A". The use of character code 0 as "null," has a long history, as far back as [Murray codes][1] back in 1901. This had a particular advantage on punched tape, where a fresh tape with no punches in it read as all 0's. Distin...
It looks like by "encoded in decimal" what they mean is binary coded decimal (BCD), which is a format which uses 4 bits to encode the numbers 0-9. Obviously this wastes a little, as those 4 bits could also encode 10-15, but that is sacrificed to make a 1:1 mapping between groups of bits and digits of a number in base ...
Let's say we are given some CFG, maybe in SSA-form, and we want to "collapse" each top-level loop into s single node, whose successors would be all exit blocks of the original loop. So we get an acyclic CFG with loops replaced by nodes. I tried finding such a construction in the literature but without success. Are ...
Collapsing loops in a control-flow graph
|graphs|compilers|data-flow-analysis|
Since SAT is np-complete, there is a polynomial algorithm to check if a given solution for any particular is correct. But what if one claims that the given formula is unsatisfiable, is there a polynomial way to check if the claim is true... Am i missing something ?
how to polynomially check if a given boolean formula is unsatisfiable
|satisfiability|p-vs-np|
Since SAT is np-complete, there is a polynomial algorithm to check if a given solution for any particular formula is correct. Just substitute the values and solve. But what if one claims that the given formula is unsatisfiable, is there a polynomial way to check if the claim is true... Am i missing something ?
NP only requires you to have a polynomial size proof for "yes" instances. co-NP is the class of problems that requires polynomial size proofs for "no" instances. SAT is in NP, but is not known to be in co-NP. Whether NP = co-NP is an open problem (and proving that SAT is in co-NP would resolve this problem in the...
I'm working on constructing deterministic finite automata (DFAs) with a specific learning complexity when using the L* algorithm developed by Dana Angluin. My goal is to create a DFA of size \( n \) that necessitates \( n-1 \) equivalence queries for the L* algorithm to correctly learn the automaton. The L* algorith...
I don't understand how to solve this problem. I understand the concept of bottleneck links but I can't seem to solve this specific question type. For Question 3, I know the answer is 31 and that is achieved by adding the connections from A - B and the connections from C - D. I have absolutely no idea why that is nee...
Computer Networking - Basic Circuit Switching - Calculate Max Number of Connections
|computer-networks|
I'm working on understanding the backpropagation process in convolutional neural networks (CNNs) and am having some trouble comprehending how to calculate the partial derivatives of the output of a CNN layer with respect to both the input \(x\) and the filter weights \(W\). Specifically, I'm looking at a simple 1D conv...
Partial derivatives wrt input and weights in CNNs
|machine-learning|artificial-intelligence|image-processing|
null
I read almost everything I can find for count min sketch. Also look at most of the videos in Youtube, but did not found answer of a simple question - What is the proper way to calculate dimensions of count min sketch In both ChatGPT and Bing AI, if you ask how big a count min sketch needs to be in order to be abl...
What is the proper way to calculate dimensions of count min sketch
|algorithms|
This question appeared in my data structures examination : You are given that GDCBFAHEJ is an in-order traversal and GCDBHJAEF is a post-order traversal. Either build the unique tree for which these are traversals or argue that they are traversals of different trees. Why are we unable to build a unique tree, de...
Unique Tree using Inorder & Postorder traversals
|data-structures|trees|
Given the in-order and the post-order, there is indeed a unique corresponding binary tree. Since $F$ is the last node in the post-order, it is the root of the tree. In the in-order, the root of the tree separates the in-order of the left tree (hence GDCB) and the in-order of the right tree (AHEJ). That means t...
We don't know for sure, but most people expect the answer is "no". In particular, assuming NP != co-NP (as is a commonly held conjecture), the answer is "no". Checking that a formula is satisfiable (and exhibiting a proof that it is) is a NP-complete problem. Checking that a formula is unsatisfiable (and exhibitin...
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
Let $DECIDE=${$<M> :\ M\ halts\ on \ all \ inputs$} and I wish to show its unrecognizable using a reduction from $ALL=${$<M> :L(M)=\Sigma ^* $} using a deterministic turing machine $R$ which runs in polynomial time: $<M>\in ALL \rightarrow _R R(<M>)=M'\in DECIDE$ R(<M>): M'(x): run M on x,...
Reduction from $ALL$ to $DECIDE$
|reductions|decidability|
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to maximize the flow from $...
**This answer uses ARMv8 AArch64 Assembly (ARM64)** .LC0: .string "a[%d]: %d\n" square: stp x29, x30, [sp, -128]! mov x29, sp str w0, [sp, 28] mov w0, 1 (A) str w0, [sp, 124...
null
Let $G=(V, E)$ be a directed network with a set $V$ of vertices and a set $E$ of edges. Two vertices are distinguished, $s,t$ which are the source and sink respectively. Each edge $(i, j)$ has an associated cost $c_{ij} \in \mathbb{Z}$ and a capacity $u_{ij} \in \mathbb{N}$. The objective is to achieve a flow of value ...
null
Welcome to the site! A Karp reduction from $\mathrm{Hamiltonian Cycle}$ could work as follows: Given a graph $G = (V, E)$, we construct $\mathrm{Long Path}$-instance $(G', v, v', |V|)$ where $G'$ is obtained by adding a copy $v'$ of some arbitrarily chosen vertex $v \in V$ (including its edges). Note that this inst...
I have been trying to find a multitape Turing Machine in order to accept a input string which consists on 0's and whose length is a power of 2: [![enter image description here][1]][1] However, Im getting troubble finding it, because I dont really know how to take the procedure with, for example, 2 tapes. I have...
Multitape Turing Machine to accept power of 2 length 0's string?
|turing-machines|strings|turing-recognizable|tape-complexity|
**Refutation of the Peter Linz Halting Problem proof** The following shows how Linz H ⟨Ĥ⟩ ⟨Ĥ⟩ gets the right answer because Linz Ĥ.H ⟨Ĥ⟩ ⟨Ĥ⟩ gets the wrong answer. **Criterion Measure** H is assumed to be a simulating termination analyzer that aborts the simulation of any input that would cause its own non-te...
null
The problem appears to be NP-hard, by a reduction from [subset sum](https://en.wikipedia.org/wiki/Subset_sum_problem). In particular, suppose we are given integers $a_1,\dots,a_n$ and target $D$. Create a graph with two vertices, $s,t$. Add edges $s \to t$, whether the $i$th edge has capacity 1, cost $a_i$, then ad...
null
null
As codeing_monkey noted, there's nothing wrong with telling it to loop. It's also possible to give a more explicit definition of $R$ (without using the universal TM) if you're not convinced. Define for a TM $M = (Q, \Sigma, \Gamma, \delta, q_0, q_a, q_r)$ $$R(\langle M \rangle) = \langle M' \rangle$$ where $M...
null
**Refutation of the Peter Linz Halting Problem proof** The following shows how Linz H ⟨Ĥ⟩ ⟨Ĥ⟩ gets the right answer because Linz Ĥ.H ⟨Ĥ⟩ ⟨Ĥ⟩ gets the wrong answer H ⟨Ĥ⟩ ⟨Ĥ⟩ ⊢* H.qy // Ĥ applied to ⟨Ĥ⟩ halts<br> H ⟨Ĥ⟩ ⟨Ĥ⟩ ⊢* H.qn // Ĥ applied to ⟨Ĥ⟩ does not halt **Criterion Measure**<br> H is assumed to be...
The problem appears to be NP-hard, by a reduction from [subset sum](https://en.wikipedia.org/wiki/Subset_sum_problem). In particular, suppose we are given integers $a_1,\dots,a_n$ and target $D$. Create a graph with two vertices, $s,t$. Add edges $s \to t$, where the $i$th edge has capacity 1, cost $a_i$, then add ...
In order to correctly compute the sketch dimensions, you need first to decide the error $\epsilon$ and the probability of failure $\delta$. This is because Count-min sketch, denoting with $\boldsymbol{s}$ the vector corresponding to the stream of items, and with $w$ and $d$ respectively the number of buckets (columns) ...
I am currently taking a course on algorithms, and when reading about the 0/1 Knapsack Problem on [Wikipedia][1] I came across a technique which uses dynamic programming and supposedly runs in $O(nW)$ time, which makes sense to me after studying the algorithm. But to my understanding, the 0/1 Knapsack Problem is NP-comp...
Fizz Buzz and pseudo-polynomial time
|algorithms|complexity-theory|time-complexity|
I have a Windows 10 desktop (6 years old - Dell Optiplex) and a new Windows 11 laptop (maybe last years model - Lenovo Thinkpad P16 Gen2). I am running scripts in R to compare their compute times. The new machine is roughly twice as fast on average, but a significant portion of that time is occurring outside of use...
What could cause a Windows 11 machine to have so much more elapsed time relative to a Windows 10 machine?
|computer-architecture|operating-systems|efficiency|memory-hardware|comparison|
null
Let the sequences be $A_{1..n}$ and $B_{1..n}$, merging takes $2n - 1$ comparisons if $A_1 < B_1 < A_2 < B_2 < A_3 < B_3 < \cdots < A_n < B_n$. It compares $A_1$ with $B_1$, $A_2$ with $B_1$, $A_2$ with $B_2$, $A_3$ with $B_2$, $A_3$ with $B_3$, to $A_n$ with $B_n$. It is identical to $A_1$ with $B_1$, $B_1$ with...
Most of the sources about count min sketch say it usage is to give counts for several "items" stored "inside". However in the following this question https://cs.stackexchange.com/questions/166937/what-is-the-proper-way-to-calculate-dimensions-of-count-min-sketch I made valid point if count min sketch is very ...
What is the proper use case for count min sketch