Suppose I have n bits, all initially 0. I can flip any m of the bits (does not have to be contiguous) at a time (one operation). How many operations is required? When is it not possible? It seems that the answer is always in [n/m, n/m + 2] when it's possible to do so.
2025-01-13 00:07:00.1736726820
N bits, flip exactly M bits at a time, what is minimum number of operations to get all 0's to all 1's?
579 Views Asked by Josh Bao https://math.techqa.club/user/josh-bao/detail At
1
There are 1 best solutions below
Related Questions in LINEAR-ALGEBRA
- Proving a set S is linearly dependent or independent
- An identity regarding linear operators and their adjoint between Hilbert spaces
- Show that $f(0)=f(-1)$ is a subspace
- Find the Jordan Normal From of a Matrix $A$
- Show CA=CB iff A=B
- Set of linear transformations which always produce a basis (generalising beyond $\mathbb{R}^2$)
- Linear Algebra minimal Polynomial
- Non-singularity of a matrix
- Finding a subspace such that a bilinear form is an inner product.
- Is the row space of a matrix (order n by m, m < n) of full column rank equal to $\mathbb{R}^m$?
Related Questions in NUMBER-THEORY
- Page 99 of Hindry's Arithmetics, follows from exact sequence that $\text{N}(IJ) = \text{N}(J)\text{card}(J/IJ)$?
- How do I solve this over the integers
- How many ways to write a number $n$ as the product of natural numbers $\geq 2$?
- Representing integers as difference of semi-primes
- If $f,g$ are non-zero polynomials and $f$ divides $g$, then $\partial f \leq \partial g$.
- Conjugacy Class in Galois Representations
- Understanding Quadratic Residue Modulo n Structure
- Properties of the Gamma function
- Matrix of quadratic form (in Serre's general notion)?
- Find all pairs of positive integers $(n,k)$
Related Questions in ELEMENTARY-NUMBER-THEORY
- Fermats little theorem, $p$ is not a prime number
- Solve $17x\equiv31\pmod{109}$
- Confusion about natural numbers and leading zero(s)
- State machine scenario: finding invariant
- Finding $\left\lfloor\frac{a}{2} \right\rfloor \mod p$ knowing $a \mod p$ and $a \mod 2$?
- What is the largest $n$-digit number which is also an exact $n$th power?
- Picking random integers $a_i$ until the $\gcd(a_1,a_2,\dots,a_n)$ is 1
- Prove that $c^n>a^n+b^n$ for $n>2$
- Is the odd part of even almost perfect numbers (other than the powers of two) not almost perfect?
- Show that this sum is an integer.
Related Questions in GCD-AND-LCM
- N bits, flip exactly M bits at a time, what is minimum number of operations to get all 0's to all 1's?
- Adding fractions with variables and using common denominator. Merging and shortening $\frac{1}{2a+8} + \frac{4}{a^2-16} + \frac{4}{a-4}$
- How to find the g.c.d when I have another g.c.d
- Finding $\sum_{i = 1}^{n} \frac{n} { \gcd(i, n)}$
- Let $n$ be a positive integer. Prove that if $18|n^3$, then $18|n^2$.
- If $n$ is an odd integer, and $n$ divides $x^2-1$ then $n = \gcd(n, x-1)\cdot\gcd(n, x+1)$
- Prove that if $c|gcd(a,b)$, then $c|a$ and $c|b$.
- If $3|n^3$, does $3|n$?
- Given that $18|n^3$, can we conclude $18|n^2$?
- Prove gcd and common divisor
Trending Questions
- Induction on the number of equations
- How to convince a math teacher of this simple and obvious fact?
- Refuting the Anti-Cantor Cranks
- Find $E[XY|Y+Z=1 ]$
- Determine the adjoint of $\tilde Q(x)$ for $\tilde Q(x)u:=(Qu)(x)$ where $Q:U→L^2(Ω,ℝ^d$ is a Hilbert-Schmidt operator and $U$ is a Hilbert space
- Why does this innovative method of subtraction from a third grader always work?
- What are the Implications of having VΩ as a model for a theory?
- How do we know that the number $1$ is not equal to the number $-1$?
- Defining a Galois Field based on primitive element versus polynomial?
- Is computer science a branch of mathematics?
- Can't find the relationship between two columns of numbers. Please Help
- Is there a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not?
- Identification of a quadrilateral as a trapezoid, rectangle, or square
- A community project: prove (or disprove) that $\sum_{n\geq 1}\frac{\sin(2^n)}{n}$ is convergent
- Alternative way of expressing a quantied statement with "Some"
Popular # Hahtags
real-analysis
calculus
linear-algebra
probability
abstract-algebra
integration
sequences-and-series
combinatorics
general-topology
matrices
functional-analysis
complex-analysis
geometry
group-theory
algebra-precalculus
probability-theory
ordinary-differential-equations
limits
analysis
number-theory
measure-theory
elementary-number-theory
statistics
multivariable-calculus
functions
derivatives
discrete-mathematics
differential-geometry
inequality
trigonometry
Popular Questions
- How many squares actually ARE in this picture? Is this a trick question with no right answer?
- What is the difference between independent and mutually exclusive events?
- Visually stunning math concepts which are easy to explain
- taylor series of $\ln(1+x)$?
- Determine if vectors are linearly independent
- What does it mean to have a determinant equal to zero?
- How to find mean and median from histogram
- Difference between "≈", "≃", and "≅"
- Easy way of memorizing values of sine, cosine, and tangent
- How to calculate the intersection of two planes?
- What does "∈" mean?
- If you roll a fair six sided die twice, what's the probability that you get the same number both times?
- Probability of getting exactly 2 heads in 3 coins tossed with order not important?
- Fourier transform for dummies
- Limit of $(1+ x/n)^n$ when $n$ tends to infinity
As fleablood commented, this is impossible if $m$ is even and $n$ is odd. I have three claims: (1) this is the only impossible case; (2) if $n \geq 2m$, then it is always possible to do in less than $n/m + 2$ operations when it is possible, and less than $n/m + 1$ if $n$ and $m$ are both even; and (3) if $n$ is even and $m = n-1$ (generalizing Ben Blum-Smith's example from the comments), then it requires exactly $n$ operations.
Proof of (1): This is trivial if $m = n$. Otherwise, we can flip two bits (say, $a$ and $b$) by first flipping $a$ along with $m-1$ others, and then flipping $b$ along with the same $m-1$ others. If we flip two bits at a time, the only obstruction we can run into is having an odd number $n$ of bits to flip to begin with. This problem is easily fixed if $m$ is odd (flip any $m$ bits initially), so the only bad case is when $n$ is odd and $m$ is even.
Proof of (2): Suppose $n \geq 2m$. Then we can modify the two-bit maneuver from above to flip any even number $2k \leq 2m$ of bits in exactly two moves. To do this, just flip $m$ bits first, and then flip another $m$ bits overlapping the previous ones in a set of size $m-k$. To flip all $n$ bits, then, begin by flipping $m$ bits from 0 to 1, and repeat this until the number of 0 bits remaining is an even number $2k \leq 2m$; then flip these as described. This algorithm flips $m-k < m$ bits three times rather than once, so the total number of flips is less than $n + 2m$, so the number of moves is less than $(n + 2m)/m = n/m + 2$.
Moreover, if $n$ and $m$ are both even, then we can even get away with less than $n/m + 1$. The reason is that the number of bits remaining is always even, so we can choose to apply the $2k$-bit maneuver when $m < 2k \leq 2m$, meaning that only $m-k < m/2$ bits are flipped three times, giving fewer than $(n+2(m/2))/m = n/m + 1$ moves in total.
Notice that this fact pins down the exact minimum number of moves needed. If $m$ and $n$ are both even, then the minimum number of moves needed is the unique integer in the range $[n/m, n/m+1)$. If $m$ is odd, then it's the unique integer in the range $[n/m, n/m+2)$ whose parity agrees with the parity of $n$.
Proof of (3): Take $n$ even and $m = n-1$. Then the only possible moves are to flip every bit except the $i$th one, where $1 \leq i \leq n$. By parity concerns, in order to flip every bit, we must do an even number of moves in total. But for every $i$, we must do moves other than the $i$th an odd number of times, because moves other than the $i$th are exactly what flip the $i$th bit. It follows that we must do the $i$th move an odd number of times (hence at least once) for every $i$, meaning that the shortest solution is to do the $i$th move exactly once for every $i$.