instruction
stringlengths
0
29.8k
⌀
null
This is more for my curiosity than anything else as I understand how to find the two's complement of a binary number via the standard approach which is to convert all 0s to 1s and 1s to 0s and then add $1_2$, but this "quick method" truly puzzles me. I see that the author of the book I am going through suggests that th...
Difficulty Understanding a Quick Method for Finding the Two's Complement of a Binary Number
|binary|
null
In that shortcut, let that right-most 1 bit left unchanged be $b$. Since $b$ is the right-most 1 bit all other bits on its right are 0s. In the standard two's complement, when you first do the one's complement, $b$ will be the right-most zero and everything else that follows it on the right will be 1s. Then, if you...
In that shortcut, let that right-most 1 bit left unchanged be $b$. Since $b$ is the right-most 1 bit all other bits on its right are 0s. In the standard two's complement, when you first do the one's complement, $b$ will be the right-most zero and everything else that follows it on the right will be 1s. Then, if you...
To add one to a binary number, you start from the right and zero out every one until you reach a zero. The you are done. E.g. 0101110001111 + 1 = 0101110010000. Notice that the last ones plus the first zero were changed and the next digits were unchanged. Two's complement is bit flipping followed by incrementa...
null
The offset is 37064 % 4096 = 200. % is modulo operator to calculate for remainder. So to get the offset, the formula is: offset = [virtual address] % [page size]. 2 Years late but hopefully it helps someone looking for this in the future.
The offset is 37064 % 4096 = 200. % is modulo operator to calculate for remainder of a division. So to get the offset, the formula is: offset = [virtual address] % [page size]. 2 Years late but hopefully it helps someone looking for this in the future.
null
null
Such an algorithm would run in pseudo-polynomial time.
null
That is an interesting observation. However, the propostion is not true in general. For a counterexample, consider the flow network with capacities $c(\overrightarrow{AB})=2$, $c(\overrightarrow{BC})=1$ and $c(\overrightarrow{AC})=1$. [![a simple flow network made with https://graphonline.ru/][1]][1] Let $A$...
I was playing around with https://visualgo.net/en/maxflow when I realized a pattern: [![enter image description here][1]][1] Take this graph, for example. We notice that the min-cut divides the graph into two sets of nodes: {0, 2, 3, 6} and {1, 4, 5, 7}. I noticed that choosing any node within {0, 2, 3, 6} as...
I take it that we are calling a *decider* a machine that takes in a natural number $n$ and then prints out either "yes" or "no", where as observers we interpret the output as the decider's opinion of whether Turing machine $n$ halts on an empty tape. Consider the decider $D_y$ that always prints "yes," along with the o...
null
With input size $O(n+m)$, the time complexity is $O(n2^b)$, which is linear in $n$ and exponential in $b$.
null
null
I believe the problem is, in the worst case, NP-hard. In particular, finding a Hamiltonian path in an induced subgraph of a grid graph is NP-hard. (See https://cs.stackexchange.com/a/68600/755.) Moreover, it seems like it is possible to construct an instance of such a problem in your setting, by putting the same val...
null
null
I understand the complexity of the issue in the event that P = NP: in this case, we couldn't prove it "by example" - it's simply impossible to sort through all possible tasks. The proof that, for all NP-complete problems, checking a solution is not easier than finding it, apparently, should be very non-trivial. However...
Why is the problem of P and NP so difficult?
|complexity-theory|np-complete|
I am reading Michael Sipser's book [Introduction to the Theory of Computation][1] and in the section 2.4(chapter 2 and DCFLs section) there is a proof for the lemma that says "Every DPDA has an equivalent DPDA that always reads the entire input string."(lemma 2.41, page 132 in the 3rd edition of the book). I have read ...
prove that Every DPDA has an equivalent DPDA that always reads the entire input string
|formal-languages|automata|finite-automata|pushdown-automata|computation-models|
As pointed out by @D.W. you are not required to hardcode these probabilities in the algorithm to obtain an optimal strategy, but you do need to know them if you want to model the scenario. A big step towards optimal solutions to the Multi-Armed Bandit problem (where a player doesn't know the underlying probability ...
I am trying to prove that the following statements are true: * The average time complexity of the quick sort is O(n log2 n). 
 * The average time complexity of the randomized quick sort is Θ(n log2 n). 
 * The worst case time complexity of the quick sort is Θ(n^2). 
 * The worst case time complex...
How to analyze quicksort
|sorting|quicksort|
I want to prove that, $$\sum_{i=0}^{h}{2^i\times(h-i)} \sim O(2^h).$$ ----------------------------------------- I did come up with the below proof, $$\sum_{i=0}^{h}{2^i\times(h-i)} \sim O(\sum_{i=0}^{h-1}2^{h-1}) \sim O(h2^h),$$ but as it is clear I did not find the correct path for my proof.
Prove that $$O(\sum_{i=0}^{h}{2^i\times(h-i)}) \sim O(2^h)$$
|time-complexity|asymptotics|
I know that if $P=NP$ then all of the languages in $NP$ are $NP-Complete$, but what about those in $P$? I assume yes, because $P \subseteq NP$, but I just want to check. Thanks!
If P=NP then all languages in P are NP-complete?
|complexity-theory|np-complete|p-vs-np|
**Consider this problem from [Jeff book][1]:** Let $D[1 .. n]$ be Fun Homework an array of digits, each an integer between $0$ and $9$. A digital subsequence of $D$ is a sequence of positive integers composed in the usual way from disjoint substrings of $D$. For example, $3, 4, 5, 6, 8, 9, 32, 38, 46, 64, 83, 279$ ...
Needs help about a problem in a book
|algorithms|
Both facts are wrong. The empty problem $\emptyset$ (the decision problem whose answer is always *false*) is in both $\mathsf{P}$ and $\mathsf{NP}$, and is not $\mathsf{NP}$-complete. See [here](https://cs.stackexchange.com/questions/155865/why-does-showing-that-a-np-problem-is-not-np-complete-implies-p-neqnp/155866...
null
Let $G$ be an undirected graph with an infinite number of vertices (and edges), and assume it is connected in the sense every $u,v$ have at least one path connecting them. Assume each vertex has a finite degree. My question is: Is it possible for a pair of vertices to exist, such that they will have an infinite number ...
Infinite Graph with Finite Degree
|graphs|connected-components|
Prove that $O(\sum_{i=0}^{h}{2^i\times(h-i)}) \sim O(2^h)$
I know that $A_{TM}=\{<M,w>|M~is~a~TM~and~M~accepts~w\}$ is NP-Hard: Let $A \in NP$, then there exists a $NTM$ that decides $A$ in polynomial time, thus there exists a $DTM$ $M_A$ that decides $A$ in exp time. Then $f(w)=<M_A,w>$ is the reduction, so $A_{TM}$ is NP-Hard. Does it mean that $\overline{A_{TM}}$ i...
Is $\overline{A_{TM}}$ co-NP Hard?
|complexity-theory|np-complete|np-hard|np|decision-problem|
null
I'm reading [this book][1], and there's something basic that I don't exactly get. The authors say that every common noun is declared to be a type. For example, $Human:Type$. Then, they give an example of semantics of an intransitive verb, which is $talk: Human \to Prop$, where $Prop$ is "the internal totality of all lo...
How to find a term that proves a given proposition?
|logic|lambda-calculus|type-theory|dependent-types|
The lattice $\mathbb{Z}^2$ gives an example. Take for example $u=(0,0)$ and $v=(0,1)$. For every $n$ we can construct the path $u = (0,0) \to (n, 0) \to (n, 1) \to (0, 1)=v$ of length $2n+1$. Each of these paths is simple and contains no cycle.
Let $\overline{D[i..j]}$ denote the number formed by the digits $D[i..j]$. For example, if $D=(1,5,7,4,8,3)$, then $\overline{D[2..2]}=5$ and $\overline{D[2..4]}=574$. #### The subprolems Let $DP[i][j]$ with $1\le i\le j\le n$ be the maximum length of a digital subsequence of $D$ the last number of which is $\ov...
**Consider this exercise from [Jeff book][1]:** > Let $D[1 .. n]$ be an array of digits, each an integer between $0$ and $9$. A digital subsequence of $D$ is a sequence of positive integers composed in the usual way from disjoint substrings of $D$. For example, $3, 4, 5, 6, 8, 9, 32, 38, 46, 64, 83, 279$ is a digit...
Compute the maximum length of an increasing digital subsequence given an array of digits
|algorithms|optimization|dynamic-programming|
null
The lattice $\mathbb{Z}^2$ gives an example. Take for example $u=(0,0)$ and $v=(0,1)$. For every $n$ we can construct the path $u = (0,0) \to (n, 0) \to (n, 1) \to (0, 1)=v$ of length $2n+1$. Each of these paths is distinct and contains no cycle.
The lattice $\mathbb{Z}^2$ gives an example. Take $u=(0,0)$ and $v=(0,1)$. For every $n$ we can construct the path $u = (0,0) \to (n, 0) \to (n, 1) \to (0, 1)=v$ of length $2n+1$. Each of these paths is distinct and contains no cycle. The same works for any selection of vertices $u$ and $v$.
A completely general solution for this is difficult to achieve if a wider floating-point format with at least twice the number of significand bits is not available. Normally, on common system platforms using C or C++ one could just use `float rem = (float) fmod ((double)a * (double)b, 360.0);` with `float` mapped to IE...
A completely general solution for this is difficult to achieve if a wider floating-point format with at least twice the number of significand bits is not available. Normally, on common system platforms using C or C++ one could just use `float rem = (float) fmod ((double)a * (double)b, 360.0);` with `float` mapped to IE...
If we had a single example where we can prove that finding a solution is more difficult then checking it, then this would immediately yield a proof of P != NP (well, with some assumptions). So, when people say it is hard to prove that P != NP, they are also saying it is hard to come up with even a single example where...
Consider $$1+x+x^2+x^3+\dots+x^n=\frac{x^{n+1}-1}{x-1}.$$ Differentiate from two sides: $$1+2x+3x^2+\dots+nx^{n-1}=\frac{(n (x-1)-1) x^n+1}{(x-1)^2}.$$ Multiply two sides by $x$: $$x+2x^2+3x^3+\dots+nx^{n}=\frac{(n (x-1)-1) x^{n+1}+x}{(x-1)^2}.$$ Plug $x=2$ into into formula you will get: $$\begin{align} \s...
Consider the following exercise from [chapter *Dynamic Programming* in the book *Algorithms*][1] by Jeff Erickson. > Let $D[1 .. n]$ be an array of digits, each an integer between $0$ and $9$. A **digital subsequence** of $D$ is a sequence of positive integers composed in the usual way from disjoint substrings of $D...
I was recently playing around in Python, and I wrote a program to check if a given number is prime. It works by checking to see if its divisible by each number other than 1 leading up to itself. It works well for small numbers but for very large numbers it takes a very very long time. I was wondering if there are progr...
Are there efficient ways to check if large numbers are prime
|algorithms|time-complexity|
There are many pitfalls in your approach. In the first place, you cannot obtain any reliable information on the time complexity of a program by timing it. Because for a small number of elements, the time is heavily polluted by many ancillary "setup" processes, and for a large number of elements, the memory accesses ...
There are many pitfalls in your approach. In the first place, you cannot obtain any reliable information on the time complexity of a program by timing it. Because for a small number of elements, the time is heavily polluted by many ancillary "setup" processes and many non-deterministic perturbations, and for a large...
I need help in finding a more performant algorithm. I have two timelines in the form of two indexed lists where each element is a floating-point value that represents seconds. The values in each list are only growing with higher indices. From every timeline, I take two indices and thus timestamps. From these four...
Iterating over combinations of 4 timestamps from 2 timelines *efficiently*
|efficiency|performance|iteration|time-series-analysis|
I need help in finding a more performant algorithm. I have two timelines in the form of two indexed lists where each element is a floating-point value that represents seconds. The values in each list are only growing with higher indices. Each list has about 2000 elements. From every timeline, I take two indices a...
I know that $A_{TM}=\{<M,w>|M~is~a~TM~and~M~accepts~w\}$ is NP-Hard: By showing a polynomial time reduction - $A \le_p A_{TM}$: Let $A \in NP$, then there exists a $NTM$ that decides $A$ in polynomial time, thus there exists a $DTM$ $M_A$ that decides $A$ in exp time. Then $f(w)=<M_A,w>$ is the reduction, so ...
I have thousands of short arrays (length less than 9) holding integers. These numbers can be identical with high probability (in many arrays there are two triples of equal numbers). I need to remove the duplicates in each array, as efficiently as possible. An obvious solution is to sort using a fast sort (such as st...
Telling unique values in a short array
|algorithms|sorting|efficiency|
I have thousands of short arrays (length less than 9) holding integers. These numbers can be identical with high probability (in many arrays there are two triples of equal numbers). I need to remove the duplicates in each array, as efficiently as possible. An obvious solution is to sort using a fast sort (such as st...
|combinatorics|enumeration|performance|combinatory-logic|time-series-analysis|
Let $$S_h:=\sum_{i=0}^{h}{2^i(h-i)}.$$ We have $$S_h-S_{h-1}=\sum_{i=0}^{h}{2^i(h-i)}-\sum_{i=0}^{h-1}{2^i(h-1-i)}=\sum_{i=0}^{h-1}{2^i}=2^{h}-1.$$ So by induction, $$S_h=S_0+\sum_{i=1}^h(2^h-1)=S_0+2^{h+1}-2-h.$$
null
Leave the points immobile. They won't collide.
I'm trying to find an algorithm to update minimal top-down tree automata/hypergraphs. Regular tree grammars can be seen as definitions for recursive data structures: ``` List -> cons(Bool, List) | nil() Bool -> true() | false() ``` By minimal I mean that distinct nodes should generate distinct term langua...
Extending minimal top-down tree automata
|regular-languages|tree-grammars|tree-automata|
Yes, let's show this in $2$ ways. ## Option A ## Let $B\in Co-NP$. As such, there exists a NTM, say $N_B$, such that for any $b$: if $b\notin B$ then $N_B$ rejects in a polynomial time. We can also say there exists a DTM, say $M_B$, such that for any $b\notin B$ it rejects it in (at most) exp time. We therefore...
null
null
null
A = {[ u v ] ∈ Σ ∗ 2 | [v]2 = 5[u]2} Where [x]k is the x to the base k. So [x]2 is a binary number. The question accepts input where the second row is five times the first row. Example of accepted input. [001][101] . i.e. 1 and 5. I've been at this for over a day now. Please provide some insight if you ...
Prove that this language is regular using NFA or DFA
|regular-languages|finite-automata|
Let [0,0] be a two-column vector with 0 in the first row and 0 in the second row <br> Let Σ2 = {[0,0],[0,1],[1,0],[1,1]} <br> be the set of all 2-element column vectors of binary digits. A = {[ u v ] ∈ Σ ∗ 2 | [v]2 = 5[u]2} Where [x]k is the x to the base k. So [x]2 is a binary number. The question acc...
Let $$S_h:=\sum_{i=0}^{h}{2^i(h-i)}.$$ We have $$S_h-S_{h-1}=\sum_{i=0}^{h}{2^i(h-i)}-\sum_{i=0}^{h-1}{2^i(h-1-i)}=\sum_{i=0}^{h-1}{2^i}=2^{h}-1.$$ So by induction, $$S_h=S_0+\sum_{i=1}^h(2^i-1)=2^{h+1}-h-2.$$