3 Counting k-inversions A k-inversion in a bitstring b is when a 1 in the bitstring appears k indices before a 0; th is, when b; = 1 and bi+k = 0, for some i. For example, the string 010010 has two 1-inversio (starting at the second and fifth bits), one 2-inversion (starting at the second bit), and o 4-inversion (starting at the second bit). Devise an algorithm which, given a bitstring b of length n, counts all the k-inversions, each k from 1 to n - 1. Your algorithm should run faster than (n²) time. You can assur arithmetic on real numbers can be done in constant time. Give a 3-part solution.
3 Counting k-inversions A k-inversion in a bitstring b is when a 1 in the bitstring appears k indices before a 0; th is, when b; = 1 and bi+k = 0, for some i. For example, the string 010010 has two 1-inversio (starting at the second and fifth bits), one 2-inversion (starting at the second bit), and o 4-inversion (starting at the second bit). Devise an algorithm which, given a bitstring b of length n, counts all the k-inversions, each k from 1 to n - 1. Your algorithm should run faster than (n²) time. You can assur arithmetic on real numbers can be done in constant time. Give a 3-part solution.
Related questions
Question
![3 Counting k-inversions
A k-inversion in a bitstring b is when a 1 in the bitstring appears k indices before a 0; that
is, when b; = 1 and bi+k = 0, for some i. For example, the string 010010 has two 1-inversions
(starting at the second and fifth bits), one 2-inversion (starting at the second bit), and one
4-inversion (starting at the second bit).
Devise an algorithm which, given a bitstring b of length n, counts all the k-inversions, for
each k from 1 to n - 1. Your algorithm should run faster than (n²) time. You can assume
arithmetic on real numbers can be done in constant time.
Give a 3-part solution.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6d711242-a88c-4a58-a190-33258ba50e1c%2F6e4ac82a-0344-47f0-9d15-fb4e233dba70%2F73xrs5_processed.png&w=3840&q=75)
Transcribed Image Text:3 Counting k-inversions
A k-inversion in a bitstring b is when a 1 in the bitstring appears k indices before a 0; that
is, when b; = 1 and bi+k = 0, for some i. For example, the string 010010 has two 1-inversions
(starting at the second and fifth bits), one 2-inversion (starting at the second bit), and one
4-inversion (starting at the second bit).
Devise an algorithm which, given a bitstring b of length n, counts all the k-inversions, for
each k from 1 to n - 1. Your algorithm should run faster than (n²) time. You can assume
arithmetic on real numbers can be done in constant time.
Give a 3-part solution.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)