Algo_F_OF_K(int k)
{
    if( k & k-1 == 0 ) // check if its a power of 2
    {
        f(k) = i  // if ith bit is set in the binary representation of k.
    }
    else if(  k & k+1 == 0 ) // if all the lower order bits are set in K
    {
        f(k) = 1;
    }
    else
    {
        f(k) = f(j) + 1  // j is the largest number less than k with same
number of 1's set in its binary representation as k.
    }
}

@vicky : did you solved it using any recurrence relation (if that can be
applied for this prob) ?

On Fri, Jul 2, 2010 at 12:17 PM, venkat kumar <svenkatkuma...@gmail.com>wrote:

>  what is the website having collection of ms questions?
>
>
>
> On Thu, Jul 1, 2010 at 6:48 PM, vicky <mehta...@gmail.com> wrote:
>
>> Actually i saw a forum of MS questions and same as i wrote was written
>> there. I too was confused but finally came to conclusion as u.
>> Anyways........
>>
>> On Jul 1, 5:51 pm, Gene <gene.ress...@gmail.com> wrote:
>> > On Jul 1, 6:46 am, vicky <mehta...@gmail.com> wrote:
>> >
>> > > It took me more time to understand this problem then solving after i
>> > > understood.
>> > > You guys too have a look @ it.::::::::::::::::::
>> > > Let f(k) = y where k is the y-th number in the increasing sequence of
>> > > non-negative
>> > > integers with the same number of ones in its binary representation as
>> > > y, e.g. f(0) = 1, f(1) => 1, f(2) = 2, f(3) = 1, f(4) = 3, f(5) = 2,
>> f(6) = 3
>> > > and so on.
>> > > Given k >= 0, compute f(k).
>> >
>> > There must be a mistake in you problem statement or examples.  It only
>> > makes sense if you change it as follows:
>> >
>> > Let f(k) = y where k is the y-th number in the increasing sequence of
>> > non-negative integers with the same number of ones in its
>> > binary representation as k, <<-- change this from y to k.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to