Re: [algogeeks] Re: how would you find the integer pairs which sum to m in o(n) time complexity

2010-11-16 Thread MOHIT ....
@bittu : for that array should be short... -- 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] Next Input Number

2010-11-16 Thread siddharth srivastava
Input a number and then find the next higher number such that for both the number (inputted and the next higher number) in binary representation contains equal number os ones. Example: Input:3(0011) Ouput:5(0101) -- Siddharth Srivastava When you have learned to snatch

Re: [algogeeks] palindrome problem

2010-11-16 Thread cheng lee
how to do that in O(|s|^2)? 2010/11/16 anoop chaurasiya anoopchaurasi...@gmail.com will O(|s|^2) dp workor u need something more efficient than that On Tue, Nov 16, 2010 at 1:51 PM, lichenga2404 lichenga2...@gmail.comwrote: A palindrome is a string which is identical to itself in

[algogeeks] Re: Next Input Number

2010-11-16 Thread Dave
@Siddharth: Try this (nnwtsnoob = next number with the same number of one bits): unsigned nnwtsnoob(unsigned x) { return (x+(x(-x)))|(((x^(x+(x(-x2)/(x(-x))); } For the explanation/justification, see http://groups.google.com/group/programming-puzzles/msg/3a05b3c8b4042d5b. Dave On Nov

Re: [algogeeks] palindrome problem

2010-11-16 Thread anoop chaurasiya
the idea for O(|S|^2) is as follows Let string be s[1..n] p[i][j]=1 if s[i...j] is a palindrome p[i][j]=0 otherwise. we can precalculate table p[i][j] as follows..in O(|s|^2) p[i][i]= 1 p[i][i+1]=1 if s[i]==s[i+1], 0 otherwise for all others.. p[i][j]= (s[i]==s[j] p[i+1][j-1]==1). now let