Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Here is a simple code for a randomized skip-list:

Coin_Side flip()
{
    if ( random() % 2 == 0 )
        return HEADS;
    else
        return TAILS;
}

Note: random() returns an integer that uses a modulus of the form M = 2^B. Then, what is the expected performance of the skip list algorithm?

So we have: (ax mod M) mod 2 = (ax mod 2^B) mod 2 = (ax mod 2) mod 2^B

I can see than ((ax mod 2) == 0) will be true if ax is even. Then, by adding mod 2^B, we will skip more values in the skip-list. We would have only the even numbers that are multiples of 2^B. So would that make the algorithm better or worse?

share|improve this question
    
Could you explain the nature of the problem a bit better? It looks like you are trying to determine the level in a skip list and worried about the random. Is this an issue with how far the list skips? or the implementation of random? or something else? –  MichaelT Jul 21 '13 at 16:18
    
It's all of that actually. If we change the implementation of random by (ax mod 2^B), will that improve the algorithm of researching a key in a skip-list, considering we're skiping more values than we're supposed to? –  Nicolas Jul 21 '13 at 16:31
    
It does matter how you select the random level, but I don't think it does in the way you are thinking. You might want to read Skip Lists: A Probabilistic Alternative to Balanced Trees and A Skip List Cookbook which have some analysis on the probabilities and impact on the structure. However, I don't think it matters in the way you think it does. –  MichaelT Jul 21 '13 at 16:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.