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.

icon
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer