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
Expert Solution
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