@yogesh
your code is simple one and excellent to understand;
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@Dave: Thanks for the link.
Just a point of discussion - this kind of code would probably never pass
code-review (or would be heavily documented with references and warnings
that say HANDS OFF ;) )
--
DK
http://twitter.com/divyekapoor
http://www.divye.in
--
You received this message because
@DK. Yes. But you must admit that it is a bit-twiddler's delight!
Dave
On Jul 10, 3:58 pm, DK divyekap...@gmail.com wrote:
@Dave: Thanks for the link.
Just a point of discussion - this kind of code would probably never pass
code-review (or would be heavily documented with references and
@Piyush: See http://groups.google.com/group/algogeeks/msg/2b64c4f96fa3598e
for a one-line algorithm.
Dave
On Jul 9, 4:23 am, Piyush Sinha ecstasy.piy...@gmail.com wrote:
I found a good question to try for bit manipulation.Try it... :)
Given an integer x, find out the smallest integer
@Dave..canu u explain ur algo to approach this formula??
On 7/10/11, Dave dave_and_da...@juno.com wrote:
@Piyush: See http://groups.google.com/group/algogeeks/msg/2b64c4f96fa3598e
for a one-line algorithm.
Dave
On Jul 9, 4:23 am, Piyush Sinha ecstasy.piy...@gmail.com wrote:
I found a good
@Piyush: The referenced web page includes a powerpoint presentation
that explains it. Did you read the presentation before asking? If not,
why not?
Dave
On Jul 9, 5:04 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote:
@Dave..canu u explain ur algo to approach this formula??
On 7/10/11, Dave
No. It can be applied to any positive number N.
The solution above splits the numbers by the least significant bit,
choose the group with missing number, and then drop the last bit and
continue.
In this way the set [0,N] is partitioned (almost) evenly into 2 groups:
{2k | k=0,1,...,N/2} and
I think Q1 is NP hard problem since the number of bits grows exponentially
as the array size increases.
On Mon, Jan 17, 2011 at 1:13 PM, juver++ avpostni...@gmail.com wrote:
@awesomeandroid
Your solution for Q1 is wrong. It can be applied only for such numbers N =
2^k, so number should power
@above, no :) it is solvable in linear time.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@juver i am really sorry ,i forget to mention.ya this soln will work
only if n is even power of 2.
Regards
Priyaranjan
http://code-forum.blogspot.com
On Jan 17, 12:43 pm, juver++ avpostni...@gmail.com wrote:
@awesomeandroid
Your solution for Q1 is wrong. It can be applied only for such
Q1: initially compute xor of all the values from 0 to n in a variable Temp
so temp = 0^1^2^n
let result is used to store the missing number
for each ith bit of missing number where i = 0-31 we can find it as
following
ith bit of result = (xor of all ith bits of values of array) xored with
@Sunny Good!
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this
@abobe
my solution is wrong when number is even (but it can be avoided with some
corrections into an implementation),
btw, you have a mistake: N=3(011), Next smallest: 6(110) ,* Should be 101
(5)!*
In other cases my version is correct.
--
You received this message because you are subscribed
Yes, I guess following correction in step 1 for Next Smallest should
fix it:
1. Find the leftmost 1 [ Not rightmost].
On Jan 18, 12:48 am, juver++ avpostni...@gmail.com wrote:
@abobe
my solution is wrong when number is even (but it can be avoided with some
corrections into an implementation),
Yes, I guess following correction in step 1 for Next Smallest should
fix it:
1. Find the leftmost 1 [ Not rightmost].
On Jan 18, 12:48 am, juver++ avpostni...@gmail.com wrote:
@abobe
my solution is wrong when number is even (but it can be avoided with some
corrections into an implementation),
Yes, Following should do for next smallest:
1. Find rightmost 01 pair
2. swap these two bits (make it 10)
e.g.
N=3(011), Next smallest: 5(101)
N=10(1010), Next smallest: 12(1100)
N=14(01110), Next Smallest: 22(10110)
On Jan 18, 12:48 am, juver++ avpostni...@gmail.com wrote:
@abobe
my solution
Q2:
next smallest:
if N is even (so, its least significant bit is 0) simply add one
bit, Next_Smallest = N + 1
else {
//locate rightmost 0 in the binary representation of N at index X,
//at index X-1 there is 1, so you need to swap it with 0 at X.
K = N+1, after this rightmost
Q2.next higher number having equal number of 1's
http://code-forum.blogspot.com/2011/01/next-higher-number-having-equal-number.html
Regards
Priyaranjan
On Jan 16, 9:09 pm, Decipher ankurseth...@gmail.com wrote:
Q1)An array A[1 n] contains all the integers from 0 to n except for one
number
for Q1. you can do it in o(n) time
Call your missing number M.
You can split your array into two parts depending on whether the least
significant bit of A[i] is a 1 or a 0. The smaller of the two parts
(call it P_1) is at most (n-1)/2 elements in size, and it tells you
whether M's least
@awesomeandroid
Your solution for Q1 is wrong. It can be applied only for such numbers N =
2^k, so number should power of 2.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To
20 matches
Mail list logo