instruction
stringlengths
0
29.8k
⌀
While reading *CLRS (4th ed.)* regarding the analysis of the expected time for QuickSort, I encountered an alternative approach. The analysis involves the following steps: 1. Given an array of size $n$, the probability of choosing any particular element as a pivot is $1/n$. To formalize this, an indicator random var...
Analysis of QuickSort Expected Time Complexity: Without Counting the Number of Comparisons
|time-complexity|probability-theory|randomized-algorithms|quicksort|
null
(Should be read after John L’s answer so I upvoted it to make it come first). You don’t need to restrict n to be less than $2^{64}$. The primes are around $n^{1/k}$. If this is small enough that you can find primes of that size easily enough, then you can find k+1 consecutive primes so that the product of the first...
How would you build a fully connected neural network that learns eigenvalue decomposition efficiently? I wanted to build NNs that can predict certain properties about matrices which are NP-hard to compute but might require eigenvalue decomposition. However, I am not sure if hardcode-calculating eigenvalues at any sp...
Learning eigenvalue decomposition
|machine-learning|neural-networks|matrices|decomposition|
null
null
null
This exercise is indeed wrong as written, I don't think there is any reasonable probability space on which variables $T(k)$ for all $k$ can be defined in such a way that it works. But the idea can be made to work. The Quicksort algorithm consists of 4 steps: - Random choice of a pivot - Partition - Sorting the...
This smells like an [XY problem](https://meta.stackexchange.com/q/66377/160917). A neural network is not a good tool to use for computing the eigenvalue decomposition. Machine learning is best for problems where you have examples of input-output pairs but you don't know of a classical algorithm to solve the problem. ...
null
null
Suppose we are given a $n\times n$ matrix that is sorted row-wise and column-wise. We want to find the median in $\mathcal{O}(n\log{n})$. This is my approach:\ We know median is such element that is greater than exactly $\lfloor\frac{n^2-1}{2}\rfloor$ elements.\ In such matrix, we always know that minimum value is...
Find median in a sorted matrix
|algorithms|search-algorithms|recursion|software-verification|
null
Suppose we are given a $n\times n$ matrix that is sorted row-wise and column-wise. We want to find the median in $\mathcal{O}(n\log{n})$. This is my approach:\ We know median is such element that is greater than exactly $\lfloor\frac{n^2-1}{2}\rfloor$ elements.\ In such matrix, we always know that minimum value is...
null
Is the time complexity analysis correct? no. you changed what `n` means when you included the master theorem. The runtime of this algorithm is `O(n^2*log(n))` This algorithm does technically work, but it's a really dumb way of doing it (since at the very least the median of an unsorted list (of `n^2 numbers) can be...
Can you prove that the following code for (int i=0; i<n; i++){ i*=k; } has a time complexity of Log n based k by hand/tracing the program
null
I've read the stable matching chapter in Kleinberg and Tardos's _Algorithm Design_ and was wondering how one can show whether a stable matching under a given set of constraints exists. K&T introduce a modified algorithm that generalizes Gale-Shapely with forbidden pairs. They write > We will show that there is alway...
Proof about Existence of Stable Matching
|algorithm-analysis|proof-techniques|
null
null
null
Probably main problem I see is recursion being made on *values* > we put $mid=\frac{min+max}{2}$ > If number of smaller elements than mid is lower than $\frac{n^2−1}{2}$, then we put min=mid+1. Otherwise we put max=mid. Then recurse with new min and max values. The condition to stop is when min≥max. Then we retu...
Suppose we are given a $n$-vector $A$ of real numbers. We need to find the longest sequence of symmetrical numbers. The numbers $a_i$ and $a_j$ are symmetric if they are located at the same distance from element $a_k$ and $|a_i-a_j|< \epsilon$. **Question** Can it be done in less than $O(n^2)$ comparisons in the...
longest symmetric sequence
|algorithms|subsequences|algorithm-design|
null
null
Is the time complexity analysis correct? no. you changed what `n` means when you included the master theorem. The runtime of this algorithm is `O(n^2*log(n))` This algorithm does technically work, but it's a really dumb way of doing it (since at the very least the median of an unsorted list (of `n^2` numbers) can b...
null
null
null
null
You can write a program that detects that some programs halt with some inputs, and that some programs won't halt with some inputs (just not for all programs and all inputs). I'm sure there are programs where you can prove "with input X, it will either halt within s seconds, or it will not halt at all". And then of ...
Considering Deutsch–Jozsa algorithm problem statement, of not being able to recognize "constant functions" from "balanced functions" on single call conventionally is clear to me... Now quantum part, slightly modifies the "problem" function, from being a function (due to how quantum circuits work on gate based qua...
Are Quantum algorithms probing the oracle?
|quantum-computing|
8. What will be the time complexity of the following code? ``` for(int i=0;i<n;i++){ i*=k; } ``` The answer is Log n base k: O(log_k n)<br> The underscore _ means base.<br> The answer is read as Big O of Log n base k<br> ------------------------------------------ The problem is number 8 from: <br> htt...
So I was doing this problem, but it led me to a different solution. The actual solution is this: Problem - Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer elevation in the range 0 .. 100. In the winter, since there is abundant snow on these hills, FJ routinely operates a ski training cam...
USACO Ski Course Design
|recursion|
null
I am reading some notes on parameterized complexity located [here](https://www.cs.cornell.edu/courses/cs6810/2023fa/Parameterized.pdf). Under the topic of "Kernalization" (section 3, page 4) they state: > When faced with the task of solving an NP-Hard problem, almost every practical computer implementation performs...
Why does reducing the bit size by one of NP-hard instances imply P = NP?
|complexity-theory|
A formal statement of the text you are quoting could be: > For any given NP-complete problem $P \subseteq \Sigma^*$, if P $\neq$ NP, then there is no function $f\colon \Sigma^* \to \Sigma^*$ such that: > 1. $|f(w)| < |w|$ for all but finitely $w \in \Sigma^*$, > 2. $w \in P$ iff $f(w) \in P$, and > 3. $f$ is comp...
If you are given the combination of quantum gates that are used to implement the oracle, the problem is easier, even for classical algorithms. But when we have an oracle, we don't get to see the quantum gates. We just have a black-box API. The quantum algorithm doesn't see the gates. Neither does the classical al...
null
I'm struggling to grasp the intuition behind the concept of an index set. By definition, a set $I$ is called an index set if $\forall i,j \in I$, $\phi_i = \phi_j \implies j \in I$. This implies that if we have a program with indices $i \in I$ and a different program $j$, both computing the same function, then $j$ is a...
Understanding Whether a Set is an Index Set
|computability|
I'm struggling to grasp the intuition behind the concept of an index set. By definition, a set $I$ is called an index set if $\forall i,j: i \in I$, $\phi_i = \phi_j \implies j \in I$. This implies that if we have a program with indices $i \in I$ and a different program $j$, both computing the same function, then $j$ i...
I'm struggling to grasp the intuition behind the concept of an index set. By definition, a set $I$ is called an index set if $\forall i,j: i \in I$, $\phi_i = \phi_j \implies j \in I$. This implies that if we have a program with indices $i \in I$ and a different program $j$, both computing the same function, then $j$ i...
null
null
null
Big Hint: You can simulate infinite, random access memory (RAM) using a turing machine (this would not require an infinite number of states). As you mentioned, you can encode the current configuration, so if you can store configurations in your unlimited memory, do you see how you can detect when $\langle M, x \ran...
null
Big Hint: You can simulate infinite, random access memory (RAM) using a turing machine (this would not require an infinite number of states). As you mentioned, you can encode the current configuration when running $M$ on $x$, so if you can store configurations in your unlimited memory, do you see how you can detect...
null
null
Suppose we are given a $n$-vector $A$ of real numbers. We need to find the longest sequence of symmetrical numbers. The numbers $a_i$ and $a_j$ are symmetrical if they are located at the same distance from element $a_k$ and $|a_i-a_j|< \epsilon$. **Question** Can it be done in less than $O(n^2)$ comparisons in t...
|algorithms|algorithm-analysis|proof-techniques|
null
null
I don't know if the title of the question is accurated or not, but I was thinking of the following problem: - I have a set of numbers, let's call them identifiers. Each identifier is stored on a 64-bit long integer; but in practice I only have, let's say, never more than 4 million different identifiers at any time. ...
Memory-efficient representation of keys over a huge domain
|algorithms|optimization|
8. What will be the time complexity of the following code? ``` for(int i=0;i<n;i++){ i*=k; } ``` **The answer is Big O of Log n base k:$\ O(Log_k n)$ <br>** ------------------------------------------ The problem is number 8 from: <br> https://www.geeksforgeeks.org/practice-questions-time-complexity-ana...
An in-order traversal of a binary search tree (BST) produces a sorted sequence. I wonder, if we perform an in-order traversal of a binary tree and obtain a sorted sequence, does that imply that the tree was a BST? (Is it a necessary and sufficient condition?) I was looking for an algorithm to check if a given binary...
Does a sorted sequence from in-order traversal imply a binary tree is a BST?
|data-structures|trees|binary-trees|search-trees|binary-search-trees|
Given an $n \times n$ grid of integers, I would like to compute the circular area which gives the maximum sum of integers within the area. For example: [![enter image description here][1]][1] In this picture, the integers 1, 0, 1, 2, 3, 1, 2, 1, -3, -2, 2, -3, 1, 3, -2, 0, 2, -1 etc are all within the circular ar...
I don't know if the title of the question is accurated or not, but I was thinking of the following problem: - I have a set of numbers, let's call them identifiers. Each identifier is stored on a 64-bit long integer; but in practice I only have, let's say, never more than 4 million different identifiers at any time. ...
Indeed. A binary tree is a BST iff its inorder traversal is sorted. First: when is a binary tree a binary search-tree (BST)? I for any node of the tree all nodes in its left subtree are less than the root, while all nodes in the right subtree are larger than the root. The inorder traversal of a binary tree is rec...
|algorithms|data-structures|data-compression|encoding-scheme|
$\overline{HALT}_{TM} \leq_m E_{TM}$. Define a machine $H$ on input $\langle M, w \rangle$ as follows: ``` H(<M, w>): Construct a machine M' defined as follows: M'(x): Run M on w for |x| steps if (M halts on w after |x| steps) Accept x else Reject...
Short answer: It's most likely not worth worrying about. The maximum possible amount of space saving is small enough that it's not worth the additional code complexity. One can prove that any data structure to store the mapping needs at least $\lg {n \choose k}$ bits, where here $n=2^{64}$ and $k=2^{22}$. This eva...
null
Consider the following problem in 2-party communication complexity, where Alice sends a single message to Bob who must compute the output. * Alice gets as input a vector $X=(x_1,...,x_N)$, for some integer N. * Bob gets as input an index $i \in [N]$ and gets $x_1,\dots,x_{i-1},x_{i+1},\dots,x_N$. Goal: Bob mu...
When does augmented indexing become easy?
|randomized-algorithms|lower-bounds|communication-complexity|
Consider the following problem in 2-party communication complexity, where Alice sends a single message to Bob who must compute the output. * Alice gets as input a bit vector $X=(x_1,...,x_N)$, for some integer N. * Bob gets as input an index $i \in [N]$ and gets $x_1,\dots,x_{i-1},x_{i+1},\dots,x_N$. Goal: Bo...
I can answer my own question: Alice just sends the parity of her input to Bob, and from this, Bob can compute the answer, so there is no nontrivial lower bound.
As non-unique values complicate things, let's keep to unique ones here. <!--____---> `[determine] the number of elements that are lower than [split:] For each row, a binary search can be done in O(logn)[, doing it on n rows] takes O(nlogn) time.` True, and about the best I expect when values are (guaranteed to be)...
null
Suppose we are given a $n$-vector $A$ of real numbers. We need to find the longest sequence of symmetrical numbers. The numbers $a_i$ and $a_j$ are symmetrical if they are located at the same distance from element $a_k$ and $|a_i-a_j|< \epsilon$, $\forall i < j$. **Question** Can it be done in less than $O(n^...
Your conception of the variable ordering is misleading you, and we can indeed add a dummy variable at the beginning. If we have a $\Pi_1\mathrm{P}$-problem $S$, we can write it as $S(x) \Leftrightarrow \forall y_1 Q(x,y_1)$. But then of course we also have that $S(x) \Leftrightarrow \exists y_1 \forall y_2 \ Q(x,y_2...
For your first question about how to prove that the following set is not an index set: K = { e | e is the code of a machine which halts on e} Let f be the following function: f(n) = Code of a machine which halts only on n and gives 1 as output. I think it is clear why f is a computable function. We know,...
I currently study well known dependency testing for automatic loop parallization from parallel compilers (ZIV, SIV, MIV, Single Variable Constraint, Multiple Variable Constraint, Acyclic Test, Fourier - Motzkin variable elimination, Delta test, Lambda test, Range test, Omega test, power test and Constraint Matrix Test)...
Dependency testing and parallel compilers
|compilers|parallel-computing|loops|