0
$\begingroup$

I had posted earlier a question regarding ranking max "n" consecutive "0"s and "1"s in a "K"-bit string -

Order in a subset


I got clarification regarding how it can be solved by using DFA (Deterministic Finite Automation) -

https://cstheory.stackexchange.com/q/8200/5038

https://cs.stackexchange.com/a/71379/755.


However, I am also looking for details of how to implement it in a programming language (in polynomial time - by iterating the given binary string bit-by-bit).

Much appreciated if you can provide some pseudo-code regarding it.

string GetRank(string max_consecutive_n_0s_and_1s_bit_value)
{
    //iterate "K" bits and find the rank in the range of 2^K values
    //...

    return rank;
}

string Unrank(string rank)
{
    //unrank and get the original value of max_consecutive_n_0s_and_1s_bit_value in the range of 2^K values
    //...

    return max_consecutive_n_0s_and_1s_bit_value;
}

Many thanks.

$\endgroup$
1
  • $\begingroup$ "Please convert the algorithm to code/pseudo-code" or "Please do a task for me" are generally not considered appropriate for this site. Generally, if you understand an algorithm, the exercise of implementing it is something you should be able to do on your own. I suggest you try working through some examples to make sure you understand the example, then try to implement it on your own. If you have a specific, focused question about some aspect you are stuck on, you can ask about that, but just asking us to convert to pseudocode for you probably is not a good fit here. $\endgroup$
    – D.W.
    Oct 6, 2023 at 17:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.