instruction
stringlengths
0
29.8k
⌀
It is a well known fact that the following 'subset-product' problem is $\mathsf{NP}$-complete when $n/\log M = \Theta(1)$. > Consider a size-$n$ subset of a multiplicative group $\mathbb{G}\cong\mathbb{Z}^{*}_M$. Then an instance of the subset-product problem consists of $(a_1, a_2,\dots,a_n, t)$ with each $a_i, t\i...
Making the same assumption as John's accepted answer, that the numbers aren't limited like on LeetCode, we can answer your question with "no" even without looking at your code. Because those complexities are impossible. You can't do better than O(n). Consider the n even numbers 2, 4, 6, 8, ..., 2n. The sum of smal...
It is a well known fact that the following 'subset-product' problem is $\mathsf{NP}$-complete when $n/\log M \in \Theta(1)$. > Consider a size-$n$ subset of a multiplicative group $\mathbb{G}\cong\mathbb{Z}^{*}_M$. Then an instance of the subset-product problem consists of $(a_1, a_2,\dots,a_n, t)$ with each $a_i, t...
Making the same assumption as John's accepted answer, that the numbers aren't limited like on LeetCode, we can answer your question with "no" even without looking at your code. Because those complexities are impossible. You can't do better than O(n). Consider the n even numbers 2, 4, 6, 8, ..., 2n. The sum of smal...
'All $A$ are $B$' and 'All $B$ are $C$' then 'All $A$ are $C$', it is called deductive reasoning. If two premises are identical then you don't get actually the deduction, you get implication. For example 'All $A$ are $B$' then you get the implication 'some $A$ are $B.$' 'No $A$ are $B$' you get the implicat...
I have a 2D Array of some rows and columns which are having only 0's and 1's. I would want to know if there is a way to optimize the number of rows so that maximum number of columns have their column sum greater than a threshold (this is known). In the end, I should be able to get the rows which should be considered to...
Given a 2D Array (of 0's and 1's), find the minimum number of rows required so that maximum columns have their sum greater than a threshold
|algorithms|
Making the same assumption as John's accepted answer, that the numbers aren't limited like on LeetCode, we can answer your question with "no" even without looking at your code. Because those complexities are impossible. You can't do better than O(n). Consider the n even numbers 2, 4, 6, 8, ..., 2n. The sum of smal...
null
I am trying to find the Gesalt similarity of a string $S$ and all substrings of $T$ using [Gestalt Pattern Matching (Ratcliff Obershelp Algorithm)](https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching) This algorithm requires me to find the matches of S and T which is defined as follows $$ matches(S,T) = \beg...
As you state the language $\{0^n 1 0^n\mid n\ge 0\}$ is context-free. (You do not need closure properties for this: $S\to 0S0\mid 1$ will do.) Now continue as follows. Consider instead the language $\{X^n Y X^n\mid n\ge 0\}$, where $X,Y$ are the axioms of context-free grammars for $C$ and $D$.
To prove PSAPCE = NP we will show following inclusions : - NP $\subseteq$ PSPACE : If every NP-hard language is PSPACE-hard then SAT is also PSPACE-hard. Since every language in PSPACE can be reduced polynomially to PSPACE-hard implies SAT $\in$ PSPACE. SAT $\in$ PSPACE. \ If L $\leq_{P}$ B and B ...
If every NP-hard language is PSPACE-hard then NP=PSPACE
|np-hard|np|space-complexity|check-my-answer|
null
I am not a Regular Experssion expert, but my request is simple: I need to match any string that has at least 3 characters of B and at most 2 characters of A so for example: "ABABBB" => Accepted "ABBBBBB" => Accepted "BBB" => Accepted "ABB" => Rejected "AABB" => Rejected "A...
Regular Expressions with at least 3 b's and at most 2 a's
|regular-expressions|
To those of you who saw my post from an hour ago - I deleted it because I came up with an idea. To summarize, I have to design a PDA for this language, without using the usual method of firstly defining a CFG then transforming it to a PDA. $ L = \{ a^{3n}b^{2n} | n \ge 0 \}$ Here is my proposed solution: [![...
Possible PDA for $ L = \{ a^{3n}b^{2n} | n \ge 0 \}$ without transforming CFG to PDA
|formal-languages|automata|context-free|pushdown-automata|
In the Silberschatz's book "operating systems" the author talks about the allocation of memory via **system buddy** and **slab**. My first question is: in the book, both memory allocation methods are described as allocation method that the kernel use to allocate memory *only* for kernel's process, not for user's proc...
Buddy system allocator and slab allocator in Linux kernel
|virtual-memory|memory-allocation|
If you partition the points into two sets $S_1$ and $S_2$ depending on which side of the line they lie on, what you're asking for reduces to finding the so-called bridges of the convex hull across this partition, i.e. the two edges of the convex hull which have one vertex in $S_1$ and one in $S_2$. Kirkpatrick and Seid...
I don't think there is any simple solution. There are 15 ways to write a word with 3 $b$'s and at most 2 $a$'s: $bbb$, $abbb$, $babb$, $bbab$, $bbba$, $aabbb$, $ababb$, $abbab$, $abbba$, $baabb$, $babab$, $babba$, $bbaab$, $bbaba$ and $bbbaa$. Between every pair of letters of those words, you can insert any numb...
"Since SAT $\in$ NP $\implies \forall L \in$ PSPACE $\leq_{P}$ SAT $\implies$ PSPACE $\subseteq$ NP" is indeed confusing. What is much clearer is "SAT is PSPACE-HARD $\implies (\forall L \in$ PSPACE, $L\leq_{P}$ SAT) $\implies$ ($\forall L \in$ PSPACE, $L$ is in NP) $\implies$ (PSPACE $\subseteq$ NP)". - The first...
{"Voters":[{"Id":151426,"DisplayName":"Manirva C"}]}
"SAT is PSPACE-hard. Since SAT $\in$ NP $\implies \forall L \in$ PSPACE $\leq_{P}$ SAT $\implies$ PSPACE $\subseteq$ NP" is indeed confusing. What is much clearer is "SAT is PSPACE-HARD $\implies (\forall L \in$ PSPACE, $L\leq_{P}$ SAT) $\implies$ ($\forall L \in$ PSPACE, $L$ is in NP) $\implies$ (PSPACE $\subseteq$...
To prove PSAPCE = NP we will show following inclusions : - NP $\subseteq$ PSPACE : If every NP-hard language is PSPACE-hard then SAT is also PSPACE-hard. Since every language in PSPACE can be reduced polynomially to PSPACE-hard implies SAT $\in$ PSPACE. SAT $\in$ PSPACE. \ If L $\leq_{P}$ B and B ...
|reductions|np-hard|np|space-complexity|polynomial-time-reductions|
I'm trying to understand IEEE 754 floating point. when I try convert ```0.3``` from decimal to binary with online calculator, it said the significand value was ```1.2``` Where ```1.2``` come from? I did understand another bits like exponent and sign bit. .3 if converted to binary it will be ``` .3 * 2 = .6 +...
Is significand same as mantissa in IEEE754?
|floating-point|
I have a 2D array of some rows and columns which are having only 0's and 1's. I would want to know if there is a way to optimize the number of rows so that maximum number of columns have their column sum greater than a threshold (this is known). In the end, I should be able to get the rows which should be considered to...
The [Wikipedia][1] explanation is clear to convert unsigned integer binary format into ```Binary Coded Decimal```. The double-dable algorithm is trying separate binary digit to BCD for example: Given 4-bit input ```1101``` (13 in decimal) will produce ```0001 0011``` The input from example clearly is unsigned in...
Double-dable algorithm for IEEE754
|floating-point|
In base 2, the significand is a number of the form $1.b_1b_2\ldots$ where the $b_i$'s are base 2 digits. The mantissa is the digits $b_1b_2\ldots$. More generally, in base $n$, the **significand** $s$ and **exponent** $e$ of a positive number $x$ are the numbers such that $x = s \cdot n^{e}$, $1 \le s < n$ and $e$ i...
Your language is DCFL. But you made NPDA because in state $q_5$ the transitions $(q_5,\epsilon,a)\neq\emptyset$ and $(q_5,\epsilon,A)\neq\emptyset$ made your diagram NPDA as I previously said. Below image is DPDA:[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/1erKg.jpg
In base 2, the significand is a number of the form $1.b_1b_2\ldots$ where the $b_i$'s are base 2 digits. The mantissa is the digits $b_1b_2\ldots$. More generally, in base $n$, the normalized **significand** $s$ and **exponent** $e$ of a positive number $x$ are the numbers such that $x = s \cdot n^{e}$, $1 \le s < n...
Your language is DCFL. But you made NPDA because in state $q_5$ the transitions $(q_5,\epsilon,a)\neq\emptyset$ and $(q_5,\epsilon,A)\neq\emptyset$ made your diagram NPDA as I previously said. Below the image is DPDA:[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/1erKg.jpg
I got an exercise about a variation of RB trees but I am struggling to see how to solve it, therefore I'll be happy to hear your opinion about it. The exercise is: > Let us define a binary search tree which we will call Red-Red-Black tree if it satisfies the following: > 1. Every node is either red or black. > ...
Problem about variation of red-black trees
|binary-trees|red-black-trees|
I got an exercise about a variation of RB trees but I am struggling to see how to solve it, therefore I'll be happy to hear your opinion about it. The exercise is: > Let us define a binary search tree which we will call Red-Red-Black tree if it satisfies the following: > 1. Every node is either red or black. > ...
A modern operating system manages physical memory as page frames. A page frame can be allocated to a user process or for the kernel to use for its own purposes, such as to allocate its own data structures. A kernel data object (e.g. a structure representing an "open file" or something) is typically less than the siz...
I got an exercise about a variation of RB trees but I am struggling to see how to solve it, therefore I'll be happy to hear your opinion about it. The exercise is: > Let us define a binary search tree which we will call Red-Red-Black tree if it satisfies the following: > 1. Every node is either red or black. > ...
Show that P and NP are under Kleene star. I found possible solutions to these problems, more specifically: 1) P - finding all subwords from a giving word and looking if there is a connection between them (idea: https://louis.jachiet.com/lfcc/final_solutions.pdf) 2) NP - non-deterministically dividing word for *m* sub...
Why does "NP under Kleene star" proof reject correct word?
|turing-machines|np|nondeterminism|kleene-star|
Show that P and NP are under Kleene star. I found possible solutions to these problems, more specifically: 1) P - finding all subwords from a giving word and looking if there is a connection between them (idea: https://louis.jachiet.com/lfcc/final_solutions.pdf) 2) NP - non-deterministically dividing word for *m* sub...
>Let $C$ be a regular language. Prove that the language $D = \{x x^R : x\in C\}$ is context-free. It's clearly important that $C$ is regular; if the hypothesis were strengthened to C being context-free, then we would have the counterexample $C = \{0^n 1^n : n\ge 0\}, D = \{0^n 1^{2n} 0^n:n\ge0\},$ which isn't contex...
prove that the language $D = \{x x^R : x\in C\}$ is context-free
|formal-languages|automata|finite-automata|
null
Your language is DCFL. But you made NPDA because in state $q_5$ the transitions $(q_5,\epsilon,a)\neq\emptyset$ and $(q_5,\epsilon,A)\neq\emptyset$ made your diagram NPDA as I previously said. Below the image is DPDA:[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/OHVU3.jpg
Your language is DCFL. But you made NPDA because in state $q_5$ the transitions $(q_5,\epsilon,a)\neq\emptyset$ and $(q_5,\epsilon,A)\neq\emptyset$ made your diagram NPDA as I previously said. Below the image is DPDA:[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/alLb0.jpg
'All $A$ are $B$' and 'All $B$ are $C$' then 'All $A$ are $C$', it is called deductive reasoning. If two premises are identical then you don't get actually the deduction, you get only the implication. For example 'All $A$ are $B$' then you get the implication 'some $A$ are $B.$' 'No $A$ are $B$' you get the...
Recall that every finite state automaton can be changed into a rightlinear grammar which has productions like $X\to aY $ and $X\to \varepsilon$. Your language can be generated using the same technique, but with linear productions which have the form $X\to aYa $ or $X\to \varepsilon$.
null
null
Let $[x_1,...,x_n]$ be an array of positive real numbers (with finite decimal approximations). Let $y > 1$ be a fixed real number. In linear time $O(n)$, we want to find two numbers $x_i$ and $x_j$ such that $|x_i - x_j| \leq y$. I am trying to solve this using hashing similar to the following interview-style p...
Hashing algorithm for finding two numbers whose absolute difference is less than some fixed constant
|hash|hash-tables|hashing|
Let $[x_1,...,x_n]$ be an array of positive real numbers (with finite decimal approximations). Let $y > 1$ be a fixed real number. Note that $y$ is greater than 1. In linear time $O(n)$, we want to find two numbers $x_i$ and $x_j$ such that $|x_i - x_j| \leq y$. I am trying to solve this using hashing similar ...
Hashing algorithm for searching two numbers whose absolute difference is less than some fixed constant
|algorithms|data-structures|search-algorithms|hash-tables|hashing|
Algorithm for searching two numbers whose absolute difference is less than some fixed constant
null
null
Instead of using a hash *set*, use a hash *map*. Store each $x_i$ under its hash $h_i = \lfloor \frac{x_i}{y} \rfloor$. But before you store it, check it against the hash entries $h_i-1$, $h_i$ and $h_i+1$ and report a pair if it's close enough. Python implementation: ``` def pair(xs, y): seen = {} for x...
I often find it that in articles or quora post about Category theory, the programming language Haskel is often mentioned. I have little knowledge of Category theory and even less of programming. Still, could someone explain on the big picture how Category theory is important in Haskell?
What exactly is the relation between Haskell and Category theory?
|category-theory|haskell|
**They're used as synonyms in the context of floating point math**, but "mantissa" is less correct mathematically. It's fewer syllables, easier to type, and starts with a different letter than Sign or Exponent, so many people including myself still prefer it, despite what Kahan and Knuth have to say. (Also including...
**They're used as synonyms in the context of floating point math**, but "mantissa" is less correct mathematically. It's fewer syllables, easier to type, and starts with a different letter than Sign or Exponent, so many people including myself still prefer it, despite what Kahan and Knuth have to say. (Also including...
null
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
I wonder if we take the current state of our machine as input, is it possible to generate a function to estimate the future state? Of course I mean like we get the 10 minutes after status within 1 minute of computing. Is it a possible things? If not, then why is it impossible? I know it's quite a weird questio...
Is it possible to design an algorithm to estimate the future state?
|computability|
I wonder if we take the current state of our machine as input, is it possible to generate a function to estimate the future state? Of course I mean like we get the 10 minutes after status within 1 minute of computing. Is it a possible things? If not, then why is it impossible? I know it's quite a weird questio...
Yes, your problem is NP-complete, even when we restrict to the case where $t=1$. We will focus on the case $M=2^k$. Then $\mathbb{Z}_M^*$ is isomorphic to $\mathbb{Z}_2 \times \mathbb{Z}^{2^{k-2}}$, and $3$ has order $2^{k-2}$ in $\mathbb{Z}_M^*$, so the subgroup generated by $3$ modulo $M$ is isomorphic to $\mathb...
|algorithms|logic|sorting|matrices|linear-algebra|
Category theory is an abstract branch of mathematics and you do not need to learn it before you start writing Haskell code and similarly, you do not need to learn Haskell before you start learning Category theory. Haskell has a beautiful relationship with Category theory, for example, consider polymorphic functions,...
Yes, your problem is NP-complete, even when we restrict to the case where $t=1$. We will focus on the case $M=2^k$. Then $\mathbb{Z}_M^*$ is isomorphic to $\mathbb{Z}_2 \times \mathbb{Z}^{2^{k-2}}$, and $3$ has order $2^{k-2}$ in $\mathbb{Z}_M^*$, so the subgroup generated by $3$ modulo $M$ is isomorphic to $\mathb...
The [Wikipedia][1] explanation is clear to convert unsigned integer binary format into ```Binary Coded Decimal```. The double-dabble algorithm is trying separate binary digit to BCD for example: Given 4-bit input ```1101``` (13 in decimal) will produce ```0001 0011``` The input from example clearly is unsigned i...
Double-dabble algorithm for IEEE754
|algorithms|floating-point|
The [Wikipedia][1] explanation is clear to convert unsigned integer binary format into ```Binary Coded Decimal```. The double-dabble algorithm is trying separate binary digit to BCD for example: Given 4-bit input ```1101``` (13 in decimal) will produce ```0001 0011``` The input from example clearly is unsigned i...
|algorithms|
With using analogy of IEEE 754 standard. We see the only difference is about size. Yours is 8-bit while IEEE 754 is 32-bit for single precision and 64-bit for double precision. Let's play with your own standard format that still using IEEE 754 analogy: ``` sign (1-bit) | exponent (2-bit) | mantissa (5-bit) ``` ...
null
"All $A$ are $B$" and "All $B$ are $C$" then "All $A$ are $C$", it is called deductive reasoning. If two premises are identical then you don't get actually the deduction, you get only the implication. For example "All $A$ are $B$" then you get the implication "some $A$ are $B.$" "No $A$ are $B$" you get the...
What you're asking for reduces to finding the so-called bridges of the convex hull across this line, i.e. the two edges of the convex hull which have one vertex on both sides of the line. Kirkpatrick and Seidel [1] show how to do this in linear time. Their method amounts to using the two dimensional linear programming ...
In articles or Quora posts about [category theory][1], I often find mentions of the programming language [Haskell][2]. I have little knowledge of category theory and even less of programming. Could someone please explain how category theory is important in Haskell? [1]: https://en.wikipedia.org/wiki/Category_the...
What exactly is the relation between Haskell and category theory?
null