instruction
stringlengths
0
29.8k
⌀
null
null
null
null
null
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. Assume we have a matrix with Yi and corresponding set of features Xi (say around 40). Number of samples relativel...
null
Suppose given two $n$ bits numbers $A$ and $B$. Also suppose there is a machine that compute multiply two $\sqrt{n}$ bits numbers in $O(1)$. What is time complexity of multiplying two $n$ bits number in a such case? I think we can use divide and conquer [Karatsuba algorithm ][1] such that our recursion tree will ...
If you are asked to find a O(n) algorithm, that is trivial. Split each number in $n^{1/2}$ groups of $n^{1/2}$ bits, calculate n multiplications in O(n) time, and then add the n partial sums. Or since the question posed is quite strange: Take the two n-bit numbers, add n^2 - n zero bits at the left giving two n^2 b...
null
If you are asked to find a O(n) algorithm, that is trivial. Split each number in $n^{1/2}$ groups of $n^{1/2}$ bits, calculate n multiplications in O(n) time, and then add the n partial sums. Actually, the whole question is a massive abuse of Big-O notation: $n^{1/2}$ multiplication is O(1) means there is a constan...
In one of my lessons about turing machines I have been taught that the function g is not computable: \begin{cases}g(n)=f_{n}(n)+1 & \text { if } f_{n}(n) \text { is defined } \\ g(n)=1 & \text { if } f_{n}(n) \text { is undefined }\end{cases} Proof: \ If $g$ is computable, then it can be computed by some Turing ma...
proof of non Turing-computable function g
|turing-machines|computability|undecidability|
I understand that total inversion in a sequence is the number of swaps that need to be done, to sort the sequence. And the best approach to solve this problem is to count swaps in a merge sort of the sequence. Now I can think of another problem whose application I need. Imagine I have two unsorted sequences with per...
Is this an inversion problem?
|algorithms|sorting|arrays|permutations|
null
I'm trying to understand whether integers are an abstract data type. The Wikipedia [article](https://en.wikipedia.org/wiki/Abstract_data_type#Defining_an_abstract_data_type:~:text=In%20practice%2C%20many,value%20is%20exceeded.) starts out by saying that integers are *not* an ADT: > In practice, many common data t...
Are integers an abstract data type?
|data-structures|type-theory|object-oriented|abstract-data-types|
You can let the sequence given by $P_2$ be the sorted order of the elements. For simplicity let your elements be the integers $0,1..., n-1$. In this example, let $n=3$. If $P_2 =[1, 0,3,2]$. Then this permutation will be interpreted as $1 < 0<3<2$. To be able to use the above idea in your problem, you can let array ...
null
> On the other hand, does full representation independence even exist in practice? **It depends on the domain you are working with.** In the case of integers as mentioned, being of fixed width makes them prone to conditions like overflow. This is because the notion of integer addition in mathematics(which operat...
**On the other hand, does full representation independence even exist in practice?** **It depends on the domain you are working with.* In the case of integers as mentioned, being of fixed width makes them prone to conditions like overflow. This is because the notion of integer addition in mathematics(which opera...
null
The problem of checking whether $P$ admits a feasible solution might or might not be NP-hard (both cases are possible). For example, if $P$ it the problem of finding vertex cover and the goal is to minimize the number of selected vertices then $P$ is NP-hard but a feasible solutions is trivial (just select all verti...
Nielson and Nielson have come out with another book called Program Analysis - An Appetizer which is supposed to be much more elementary compared to Principles of Program Analysis. It might be a good starting point. You can find it [here][1] [1]: https://arxiv.org/abs/2012.10086
The first paragraph is written in a way that is a bit confusing. It doesn't mean that integers are not an ADT. It means that fixed-width ints are not a faithful/valid/correct implementation of integers. Fixed-width ints are presumably the common datatype it is referring to.
The problem of checking whether $P$ admits a feasible solution might or might not be NP-hard (both cases are possible). For example, if $P$ it the problem of finding a vertex cover and the goal is to minimize the number of selected vertices then $P$ is NP-hard but a feasible solutions is trivial (just select all ver...
null
Forget about there being a nested loop. There could be 10 nested loops; it wouldn't make a difference. Ask yourself: How often is window_start increased? From that you can conclude how often the inner loop is executed and that solves the problem. Note: It takes experience and training / practice to read code li...
You can just greedily take the element of the first set that appears in the most consecutive sets (decide equals arbitrarily). That's the first element of your solution. Then do the same for the next set after those consecutive sets.
*(Note: cross-listed on stack overflow: https://stackoverflow.com/questions/73362856/looking-for-name-of-a-priority-queue-data-structure-based-on-bit-boundary-bucket)* I'm looking for the name of a data structure. I came up with this idea but suspect it should already be known, and don't know what to search to find ...
Looking for name of a priority queue data structure based on bit-boundary buckets
|data-structures|reference-request|priority-queues|
null
I'm writing a DFA minimizer using Hopcroft's algorithm. While testing some regular expressions, I came out with an issue in the algorithm's output relative to two particular regular expressions: + _a(b|c)*_ + _a(b|c*)_ P.S.: the assumption is that both regular expressions are valid, but if that's not the case pl...
Hopcroft's minimization algorithm produces an incorrect result for a particular regular expression
|finite-automata|
null
I suspect what happened is that you took Split to subdivide a cluster of states based on whether the successor state is accepting or rejecting, which, since the pseudocode only contemplates a binary division (wrong), is understandable. Below is some Python code that I believe correctly implements minimization while ...
For every I = 1 to n, and for every x in xi, calculate the cheapest sequence for the first I sets ending in x. For I = 1 it is trivial, every sequence has cost 0. To find the cheapest sequence for I+1 sets ending in x, the cost is either the cheapest sequence for I sets ending in x or the cost of any sequence f...
This data structure is called a [**radix heap**](https://github.com/iwiwi/radix-heap).
Schaefer proved that deciding even cycles cover ( 2-factor with even cycles) in cubic graphs is NP-complete. I am interested in the complexity of odd cycles cover in cubic graphs. Is it NP-complete? Is it polynomial time solvable?
Is odd cycles cover NP-complete?
|complexity-theory|np-complete|
In [this question][1] it is stated that a CRC detects burst errors of length greater than the CRC length with probability $1-2^{-r}$, where $r$ is the length of the CRC. Why is there no dependence on the length of the burst? [1]: https://stackoverflow.com/questions/49752754/proof-of-crc-burst-error-detection-...
Why does a CRC detect burst errors of longer than r+1 bits independently of burst length?
|error-correcting-codes|crc|
Schaefer proved that deciding even cycles cover ( 2-factor with even cycles) in cubic graphs is NP-complete. I am interested in the complexity of odd cycles cover in cubic graphs. Is it NP-complete? Is it polynomial time solvable? P.S. Cycle cover is a set of vertex disjoint cycles that cover all nodes such that e...
The CRC could have any of $2^r$ possible values. If you have an error burst where k >= r bits have random bit values, then the CRC of these k bits has one of $2^r$ possible values (because the CRC has r bits), of which one is correct. So you get the correct CRC by pure coincidence with probability $2^{-r}$. For sma...
My first impression was that the source you've quoted is contradictory nonsense. Having spent a bit of time reading up, I've come to the following conclusion. The notion of an "abstract data type" makes sense only to the extent that we recognise certain data types can have different but equivalent implementations...
null
Well, *purely theoretically*... It can be done in $O(1)$ space<sup>1</sup> using some well-known techniques, though that may be like firing a cannon at sparrows. I will describe a slightly cumbersome and overengineered, but comprehensible solution in $O(\log n)$ space<sup>1</sup>, where $n$ is the board area, and then ...
Consider a function $f(x)$, is it always possible to decide whether $f^-1(f(x)) = x$ I.e. is it possible to use a terminating decision procedure, such as those in SMT solvers to check for this, does it depend on the language used in f, or is it possible in every case? I believe I have seen somewhere that the rev...
Is checking the reversibility of a function decidable?
|turing-machines|decision-problem|functional-programming|decidability|reversible-computing|
<!-- $\mathbb N$ means all positive integers. --> #### Assign an integer to each Turing machine. First, we fix an encoding scheme (or method) for all Turing machines (of some fixed kind, such as the one defined [here](https://en.wikipedia.org/wiki/Turing_machine#Formal_definition)) that encodes each Turing machine ...
Consider a a deterministic algorithm $f(x)$, is it always possible to decide whether $f^-1(f(x)) = x$ I.e. is it possible to reverse the algorithm and check that its reverse is the inverse of the original algorithm given it contains no loops and therefore is not exposed to the halting problem, using a terminatin...
Is possible to automatically check the reversibility of an algorithm, that contains no loops?
null
null
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. The goal is to find a range of values for each feature, so that the subset of rows where every feature falls in th...
Find a range of values to subset the rows to maximize the objective function
null
null
I have one LP problem (LP1) to solve, where a term in a constraint is to be substituted after solving another LP problem (LP2) (with a different variable vector). Suppose I call the dimension of the variable vector in LP1 as $n$ and in LP2 as $m$. I know that the complexity of solving an LP problem is $O(n^3L)$ ($L$ is...
null
I am struggling to wrap my head around this compiler technique, so lets say here's my factorial function ```python3 def factorial(value: int) -> int: if value == 1: return 1 else: return factorial(value-1) * value ``` It is recursive, but not TCO friendly yet, so, as the theory implies, ...
Tail call optimization via translating to CPS
|compilers|recursion|
null
Presumably you are after a substitution like$$\sqrt{n+m}\,n^3\le f(n)\,g(m),$$ or equivalently $$n+m\le p(n)\,q(m).$$ If you freeze $m$, then $p(n)=\Omega(n)$ must hold (and similarly $q(m)=\Omega(m)$). So I see no better solution than $$\sqrt{n+m}\,n^3\le\sqrt{nm}\,n^3= n^{7/2}m^{1/2}.$$
null
I am bit confused while reading a standard textbook of my curriculum, where it is mention time complexity for knapsack problem is O(nlogn), and rationale they provided is we need O(n) to calculate (value/weight) value for each weight provided and next we need to sort it using O(nlogn) using any standard sorting algorit...
Complexity of fractional knapsack problem
|data-structures|greedy-algorithms|knapsack-problems|
It is not really a competition, but there is the well-known Mittelmann benchmark, which lists results for some of the best solvers (including commercial ones) for mixed-integer programming and related problem classes: http://plato.asu.edu/bench.html http://plato.asu.edu/ftp/milp.html
Consider an algorithm $f(x)$. Are there formal systems or programming languages that only allow $f(x)$ to be defined if $f^-1(x)$ exists?
Are there any formal systems or programming languages in which its only possible to define functions that have inverses?
null
3-SAT concerns formulas in CNF form: $(a_1 \vee a_2 \vee a_3) \wedge \dots \wedge (b_1 \vee b_2 \vee b_3)$ (3-CNF). The problem of whether or not such a formula has an assignment of its Boolean variables such that it evaluates to $1$, and returning such an assignment is NP-complete. But if we can convert the 3-CNF ...
Why can't 3-SAT be solved efficiently if you convert all clauses $(x \vee y \vee z)$ into $(u \vee z)$ by introducing a variable?
|complexity-theory|satisfiability|boolean-algebra|3-sat|2-sat|
Let, $a_i, b_i$ etc be either a literal (a variable) or the negation of a literal. 3-SAT concerns formulas in CNF form: $(a_1 \vee a_2 \vee a_3) \wedge \dots \wedge (b_1 \vee b_2 \vee b_3)$ (3-CNF). The problem of whether or not such a formula has an assignment of its Boolean variables such that it evaluates to $1$...
Because the variables thus introduced can be dependent among themselves. For example, if we replace $a \lor b$, $c \lor d$, $a\lor c$, $b\lor d$ by $w,x,y,z$ respectively, then we also have $$w\lor x=y\lor z.$$
Because the variables thus introduced can be dependent among themselves. For example, if we replace $a \lor b$, $a \lor c$, $b\lor c$, by $x,y,z$ respectively, then we also have $$x\le y\lor z.$$ For example, if we replace $a \lor b$, $c \lor d$, $a\lor c$, $b\lor d$ by $w,x,y,z$ respectively, then we also ha...
null
> $u = (a \vee b) \iff (u \vee \bar{a}) \wedge (u \vee \bar{b}) \wedge (\bar{u} \vee a) \wedge (\bar{u} \vee b) =1 $ Unfortunately, the equivalence above does not hold. Let $a=\text{false}$, $b=\text{true}$, $u=\text{true}$. - the LHS is $\text{true}$. - the RHS is $\text{false}$ since $\bar u\lor a=\text{fa...
please delete post, thank you in advance.
please delete post
|complexity-theory|time-complexity|
> $u = (a \vee b) \iff (u \vee \bar{a}) \wedge (u \vee \bar{b}) \wedge (\bar{u} \vee a) \wedge (\bar{u} \vee b) =1 $ Unfortunately, the equivalence above does not hold. Let $a=\text{false}$, $b=\text{true}$, $u=\text{true}$. - the LHS is $\text{true}$. - the RHS is $\text{false}$ since $\bar u\lor a=\text{fa...
I have been trying to solve questions like this before but I have stumbled in difficulty to track the the space of the cache. so there is an example of a question like this: Given the code: int A[1024,1024],B[1024,1024],C[1024,1024] for(int i=0;i<1024;i++){ for(int j=0;j<1024;j++){ ...
compute cache miss rate by given code
|computer-architecture|cpu-cache|memory-access|
<!-- $\mathbb N$ means all positive integers. --> #### Assign an integer to each Turing machine. First, we fix an encoding scheme (or method) for all Turing machines (of some fixed kind, such as the one defined [here](https://en.wikipedia.org/wiki/Turing_machine#Formal_definition)) that encodes each Turing machine ...
Yes, there are. See [reversible computing](https://en.wikipedia.org/wiki/Reversible_computing). You could of course design a programming language that only allows using reversible operations (e.g., Toffoli gates), though I'm skeptical whether this would be useful in practice. Searching on "reversible programming lan...
We are given segments $(s_1,e_1),(s_2,e_2),(s_3,e_4),...,(s_k,e_k)$ where $s_i<=e_i$. Now we are given a query interval $[L,R]$ find the largest segment $(s_i,e_i)$ contained within $[L,R]$. By the term `largest` we mean among all the segments contained within $[L,R]$ return the one whose $e_i-s_i$ is maximum. A...