instruction
stringlengths
0
29.8k
⌀
Consider a truncated hexagonal grid, with some hexagons lit up, such as the one shown below: [![truncated hexagonal grid, with some hexagons lit up][1]][1] Here the red, green, and blue hexagons are lit up while the desatured gray, gray, and other gray hexagons are not lit up. The distinction between red, green, ...
Consider a truncated hexagonal grid, with some hexagons lit up, such as the one shown below: [![truncated hexagonal grid, with some hexagons lit up][1]][1] Here the red, green, and blue hexagons are lit up while the desatured gray, gray, and other gray hexagons are not lit up. The distinction between red, green, ...
You can check these two surveys for discussions of other heuristics like TIMESTAMP and MRI, beyond the 3 common heuristics: * [Self-organizing data structures by Albers & Westbrook (2005) ](https://scholar.google.com/scholar?q=Self-organizing+data+structures) * [A survey of algorithms and models for list update by Ka...
Let $n$ be the number of variables in the input formula and $m$ the number of clauses. Define $s_k = \inf\{\delta : k\text{-SAT can be solved in } 2^{\delta n} \text{ time}\}$. The strong exponential time hypothesis says that $\lim \limits_{k \to \infty} s_k=1$. I have two questions here: 1. What if the input size i...
Understanding the Strong Exponential Time Hypothesis
|algorithms|complexity-theory|np-complete|satisfiability|
1. That can't happen. The maximum number of distinct possible clauses is $(2n)^k = O(n^k)$, which is polynomial in $n$ (since here $k$ is fixed). 2. Here I imagine that there notation $O^*(c^n)$ probably refers to something like $O((nL)^{O(1)} c^n)$. If you could solve SAT in $O(1.5^n)$ time, then you could solve ...
Your approach of fitting a curve and then finding the tangent to the fitted curve seems like a sensible approach. No fitted curve will ever exactly match all of the points. If you aren't fitting all of the data, then the family of curves doesn't fully model the distribution the data actually came from. One simple ...
Consider a truncated hexagonal grid, with some hexagons lit up, such as the one shown below: [![truncated hexagonal grid, with some hexagons lit up][2]][2] Here the red hexagons are lit up while the dark gray hexagons are not lit up. The grid has buttons (small black circles) that flip the color of adjacent hexag...
Let's say that we have a context free grammar G, which is not in chomsky normal form, and we need to convert it to chomsky normal form. The steps involved in the conversion are as follows: 1) Add a new start variable and point it to the old start variable 2) Remove all of the empty rules, except for the empty rule...
Let's say we've got $n$ numbers to multiply together. But the multiplication operation, like in computer floating-point arithmetics, is not associative. Thus the order of multiplication matters. Furthermore let's say that we want to minimize the nesting of the expression tree that represents the entire multiplicatio...
Iterate through all values of a certain subset of all permutations
|enumeration|multiplication|iteration|
Let's say we've got $n$ numbers to multiply together. But the multiplication operation, like in computer floating-point arithmetics, is not associative. Thus the order of multiplication matters. Furthermore let's say that we want to minimize the nesting of the expression tree that represents the entire multiplicatio...
Usually, in bin-packing, we have objects of sizes $a_1,...a_n$, and each bin has size 1, We need to minimize the number of bins, and for this, there are best fit/first-fit approximation algorithms. What will happen if there are more parameters than just size, say 3 parameters? Each object $i$ has say parameters $(a_...
Bin packing with more than one parameter
|combinatorics|approximation|packing|
If you rotate the plot by a suitable angle that makes the tangent horizontal, your problem is recast as that of finding the minimum of the curve, which is a simple problem. For better accuracy, you can fit a parabola *on a few neighbors* of the lowest point. [![enter image description here][1]][1] Anyway, notice ...
null
Let's say we've got $n$ numbers to multiply together. But the multiplication operation, like in computer floating-point arithmetics, is not associative. Thus the order of multiplication matters. Furthermore let's say that we want to minimize the nesting of the expression tree that represents the entire multiplicatio...
Given a fixed number of infinite-capacity containers and a list of items of varying weights, how can I best place the items into the containers **preserving their original order** in a way that minimises the difference between the heaviest and lightest containers? For example, given 3 containers and 10 items with we...
Ordered open-end knapsack problem optimised for minimum weight range
|algorithms|optimization|knapsack-problems|packing|
For example, 5 can be written in 2 ways: - 4 + 1 - 3 + 2 8 can be written in 5 ways: - 7+1 - 6+2 - 5+3 - 5+2+1 - 4+3+1 How could this be determined for any positive integer N?
Amount of ways N can be written as sum of two or more non-repeating integers
|algorithms|
I have a file with trillions of numbers and I want to get all numbers that have a frequency `<=100`. These numbers are in text format (`UInt8`s) so I first have to parse them. As this is slower than reading the bytes to a buffer I have one thread reading the data and 80 threads processing the bytes. I could give ea...
Data structure to estimate the frequency of low frequency elements
|algorithms|data-structures|performance|
null
null
What is the algorithm's computational complexity for a variant of *the Travelling Salesman Problem*, where every node must be visited ***at least once***, meaning that a node can be visited more than once? (The cycle starts from a specific node and, after passing all nodes (at least once) returns to the start node). ...
The computational complexity of a variant of algorithm for the TSP (Travelling Salesman Problem)
|algorithms|complexity-theory|graphs|graph-traversal|
null
null
Let $K=a_1<a_2<\dots<a_n$ be set $n$ distinct keys that inserted into an AVL tree $T$. The probability of any permutation of the order of insertion sequence $K$ be equal also we first insert $a_{40}$ into $T$, how I can find the probability of after in the insertion process, $a_4$ and $a_9$ will compared? I think l...
Probability of comparison of two nodes after insertion in AVL tree
|algorithms|data-structures|
I have a file with trillions of numbers and I want to get all numbers that have a frequency `<=100`. These numbers are in text format (`UInt8`s) so I first have to parse them. As this is slower than reading the bytes to a buffer I have one thread reading the data and 80 threads processing the bytes. I could give ea...
This is known as the [number of strict partitions](https://en.wikipedia.org/wiki/Partition_function_(number_theory)#Strict_partition_function). Wikipedia contains a number of results on this. You can compute the number using [dynamic programming](https://cs.stackexchange.com/tags/dynamic-programming/info).
Is $UP = NP\cup co-NP$ closed under polynomial-time many-one reductions? I understand that in order to be so, for $A\in UP, A \leq_P B $ there should exist a polynomial time computable function $f$ such that: $x\in A \implies f(x) \in B$. So the function computed for an input from UP is also in UP. It looks like a ...
union of NP and co-NP, closure under polynomial time reduction
|np|polynomial-time-reductions|co-np|
I have a file with trillions of numbers and I want to get all numbers that have a frequency `<=100`. These numbers are in text format (`UInt8`s) so I first have to parse them. As this is slower than reading the bytes to a buffer I have one thread reading the data and 80 threads processing the bytes. I could give ea...
I have a file with trillions of numbers and I want to get all numbers that have a frequency `<=100`. These numbers are in text format (`UInt8`s) so I first have to parse them. As this is slower than reading the bytes to a buffer I have one thread reading the data and 80 threads processing the bytes. I could give ea...
Suppose $K=a_1<a_2<\dots<a_n$ be a set $n$ distinct keys that inserted into an AVL tree $T$. The probability of any permutation of the order of insertion of the sequence $K$ is equal. Also we first insert $a_{40}$ into $T$, how I can find the probability, $a_4$ and $a_9$ will be compare in the insertion process? ...
I came across this pair of blog posts explaining the problem with calculating variance on floating point data: https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/#example-3-a-variance-calculation-gone-wrong https://jonisalonen.com/2013/deriving-welfords-method-for-computing-variance/ They show...
Why use Welford's Method over a more naive approach?
|efficiency|statistics|
I’ve searched for a solution for this problem for some time now, it is out of an algorithm question sheet. We know that in order to find the minimal amount of edges in a flow graph’s min-cut we need to find the maximal flow, $c_o$,set the capacity of the edges of the min-cut to $1$ and for for the rest $e\in E$ set ...
Min-cut with maximal number of edges
|network-flow|max-cut|
I was studying algorithms, and that problem below came up. Write an efficient algorith that calculates the biggest single positive forward change in value given the values. [![enter image description here][1]][1] There is a second image with some pseudo code with the resolution, I think. But I couldn't even un...
What the algorith should return and how to implement
|algorithms|data-structures|efficiency|
null
Kolmogorov said _"It seems natural to call a chain random if it cannot be written down in a more condensed form, i.e., if the shortest program for generating it is as long as the chain itself. "_ So for example (in bits & bytes):- $$ K(\text{a thousand zeros}) \approx \log_2(1000) \text{bits} $$ $$ K(\text{Sha...
In Kolmogorov's $ K(s) \leq |s| + c $, why is $c$ +ve?
|kolmogorov-complexity|
I am considering multivariate polynomials that can be expressed as sums of products of terms of the form $y_i-z_j$ for positive integers $i$ and $j$. I am trying to find an algorithm to determine if there is a way to express them in terms of these linear factors in such a way that the terms have nonnegative coefficient...
Algorithm for determining a positivity property of a polynomial
|algorithms|polynomials|computer-algebra|
If we had $K(s) \le |s|-1$ (for example), then that would mean that every string can be compressed to a strictly shorter one. It is known that this is impossible: see https://cs.stackexchange.com/q/7531/755. See also https://en.wikipedia.org/wiki/Pigeonhole_principle#Uses_and_applications, https://cs.stackexchange....
I am considering multivariate polynomials with integer coefficients that can be expressed as sums of products of terms of the form $y_i-z_j$ for positive integers $i$ and $j$. I am trying to find an algorithm to determine if there is a way to express them in terms of these linear factors in such a way that the terms ha...
Algorithm for determining an algebraic positivity property of a multivariate polynomial
I am considering multivariate polynomials with integer coefficients that can be expressed as sums of products of terms of the form $y_i-z_j$ for positive integers $i$ and $j$. I am trying to find an algorithm to determine if there is a way to express them in terms of these linear factors in such a way that the terms ha...
If we had $K(s) \le |s|-1$ (for example), then that would mean that every string can be compressed to a strictly shorter one. It is known that this is impossible: see https://cs.stackexchange.com/q/7531/755. See also https://en.wikipedia.org/wiki/Pigeonhole_principle#Uses_and_applications, https://cs.stackexchange....
For the dataset you show in the question, all numbers are in the range between 0 to about 500 million. For this dataset, there is an easy efficient algorithm. Build an array $A$ with 500M entries, initialized to zero. Read each line one at a time; when you read the number $x$, increment $A[x]$. At the end, output a...
I am considering multivariate polynomials with integer coefficients that can be expressed as sums of products of terms of the form $y_i-z_j$ for positive integers $i$ and $j$. I am trying to find an algorithm to determine if there is a way to express them in terms of these linear factors in such a way that the terms ha...
I am considering multivariate polynomials with integer coefficients that can be expressed as sums of products of terms of the form $y_i-z_j$ for positive integers $i$ and $j$. I am trying to find an algorithm to determine if there is a way to express them in terms of these linear factors in such a way that the terms ha...
Here is a semi-algorithm. I don't know if it is a good one. If you conjecture is true, it always terminates. In particular, if a solution exists, it will find it; if no solution exists, it will run forever, searching for one. Let $p(x)$ be the original polynomial; it can be expressed in the form $$p(x) = \sum_S ...
For the dataset you show in the question, all numbers are in the range between 0 to about 500 million. For this dataset, there is an easy efficient algorithm. Build an array $A$ with 500M entries, initialized to zero. Read each line one at a time; when you read the number $x$, increment $A[x]$. At the end, output a...
In [Wikipedia](https://en.wikipedia.org/wiki/Lambda_calculus) I found out that the formal grammar of $\lambda$-calculus is the following: ``` <λexp> ::= <var> | λ<var> . <λexp> | ( <λexp> <λexp> ) ``` Then, a few lines later they say that this is a valid $\lambda$-expression: $$\lambda x.x^{2}+2$$ H...
How does "+" operator fit into the formal grammar of $\lambda$-calculus?
|lambda-calculus|
We have a graph where we want to get from node u to v in the shortest path possible. I understand how Bellman-Ford works when we have exactly i edges to go from u to v or where we are at most i edges to get from u to v. But how does this work when you have to go from u to v with at least k number of edges? Is this ...
Confused on Bellman Ford
|graphs|dynamic-programming|
We have a graph where we want to get from node u to v in the shortest path possible. I understand how Bellman-Ford works when we have exactly i edges to go from u to v or at most i edges to get from u to v. But how does this work when you have to go from u to v with at least k number of edges? Is this a simple ...
In the [Church-Turing thesis Wiki page][1], there are a set of descriptions of the "behavior of a computor—`a human computing agent who proceeds mechanically'". I am content with all of them, except: > (L.2) (Locality) A computor can shift attention from one symbolic configuration to another one, but the new observe...
Turing Machine, UNLIMITED number of steps left or right on the tape?
|turing-machines|computability|church-turing-thesis|
Suppose $K=a_1<a_2<\dots<a_n$ be a set $n$ distinct keys that inserted into an AVL tree $T$. The probability of any permutation of the order of insertion of the sequence $K$ is equal. Also we first insert $a_{40}$ into $T$, how I can find the probability, $a_4$ be ancestor of $a_9$ or $a_9$ be ancestor of $a_4$? An...
null
With unordered data spread over such a range, cache hit rate will be very low indexing a table directly or using a hash function. One alternative is ordering the data using an algorithm with good locality. Merge sort has been discussed for elimination of duplicates. With an "occurrence limit" higher than 1, on...
Suppose $K=a_1<a_2<\dots<a_n$ be a set $n$ distinct keys that inserted into an AVL tree $T$. The probability of any permutation of the order of insertion of the sequence $K$ is equal. Also we first insert $a_{40}$ into $T$, how I can find the probability, $a_4$ be ancestor of $a_9$ or $a_9$ be ancestor of $a_4$? An...
what is your formula for g? From your result it looks like amount of nodes visited. That cost function will result in more extraneous diagonals. Because going diagonally down left followed by diagonally down right has the exact same cost as going down twice. in particular at that turnaround assuming the node just...
I am currently studying the paper "Abstract Interpretation Frameworks" by Cousot and Cousot from 1992 (https://doi.org/10.1093/logcom/2.4.511) to gain an understanding of the theory behind abstract interpretation. One concept in abstract interpretation is the "soundness relation" (local page 6 in above paper). As I ...
It appears like I have simply misunderstood the expression: $\langle c, d\rangle \in \sigma \stackrel{def}{=} \alpha(c) \sqsubseteq_{\mathcal{D}} d \Leftrightarrow c \subseteq_{\mathcal{C}} \gamma(d)$. What I read is: $\langle c, d\rangle \in \sigma$ is defined to hold if and only if $\alpha(c) \sqsubseteq_{\mathca...
Is $Union = NP\cup co-NP$ closed under polynomial-time many-one reductions? I understand that in order to be so, for $A\in Union, A \leq_P B $ there should exist a polynomial time computable function $f$ such that: $x\in A \implies f(x) \in B$. So the function computed for an input from $Union$ is also in $Union$. ...
Suppose we have an undirected graph $G=(V,E)$ and and it's **Maximal** spanning tree $T=(V,F)$ such that the edges in $F$ is the heaviest subset of edges $E$ from which you can create a spanning tree. We're required to prove that for all $(u,v)\in V$, the bottleneck in the path $P(u,v)$ in $T$ is the heaviest bottle...
Proving a maximal bottleneck for all pairs of vertices in maximal spanning tree
|correctness-proof|minimum-spanning-tree|
null
null
Is it true that there is no known succinct data structure that has integer array (vector) functionality? Desirable operations would be: - append O(1) - access(i) - returns i-th item O(1) - iterate(i..j) - i.e. iterate from i to j efficiently O(j-i) The emphasis is on **integer** arrays and O(1). A structure tha...
Succinct array datastracture
|arrays|succinct-data-structures|
################### # create_slider() # ################### def create_slider(self, t0, t1): # adjust the main plot to make room for the sliders plt.subplots_adjust(bottom=0.25) slider = Slider( # left botm w h ...