Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread aswath G B
@Dave

 Slight change u have to do

#include
main()
{
 int a = 24;
 int b = (a | 7)+1;  //This Line U have to change.& not  a || 7.
 printf("%d",b);
 return 0;
}

tats it


btw it is nice one line easy soln...

On Sat, Sep 25, 2010 at 10:17 PM, Dave  wrote:

> answer = (x || 7) + 1;
>
> Dave
>
> On Sep 25, 6:56 am, Krunal Modi  wrote:
> > Q: Write an algorithm to compute the next multiple of 8 for a given
> > positive integer using bitwise operators.
> >
> > Example,
> > (a) For the number 12, the next multiple of 8 is 16.
> > (b) For the number 16, the next multiple of 8 is 24.
> > -
> > I have written a code using bitwise operators...but, I am not happy
> > with the solutionIs there any ONE LINE solution ?
> > Here, is my code.
> > Approach: shift left till LSB is 0 (say n number of times) then, OR
> > with 1, finally shift right (same number of times).
> >
> > #include
> >
> > int main(){
> > int count,m,n,ans,t;
> >
> > printf("Enter any number :");
> > scanf("%d",&n);
> >
> > m=8; //multiple of 8 !!
> > ans=0;
> > while(ans<=n){
> > t = m;
> > while(t){
> > count=0;
> > while(ans&1){
> > count++;
> > ans = ans>>1;
> > }
> > ans = ans|1;
> > ans = ans< > t--;
> > }
> > }
> >
> > printf("[%d]\n",ans);
> >
> > return 0;
> >
> >
> >
> > }- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.
>
>


-- 
http://aswath78.blogspot.com

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread kusuma sanjeev
@Saurab: Nice solution

On Sun, Sep 26, 2010 at 11:27 AM, saurabh agrawal wrote:

> Simple one line solution without looping and efficient :
>
> i=(i&7)?(i|7)+1:i)
>
>
> On Sun, Sep 26, 2010 at 8:43 AM, coolfrog$ <
> dixit.coolfrog.div...@gmail.com> wrote:
>
>> @Dave
>> very nice one line solution..
>>  we all are revolving around x>>3 concept...
>>
>>
>> On Sat, Sep 25, 2010 at 10:17 PM, Dave  wrote:
>>
>>> answer = (x || 7) + 1;
>>>
>>> Dave
>>>
>>> On Sep 25, 6:56 am, Krunal Modi  wrote:
>>> > Q: Write an algorithm to compute the next multiple of 8 for a given
>>> > positive integer using bitwise operators.
>>> >
>>> > Example,
>>> > (a) For the number 12, the next multiple of 8 is 16.
>>> > (b) For the number 16, the next multiple of 8 is 24.
>>> > -
>>> > I have written a code using bitwise operators...but, I am not happy
>>> > with the solutionIs there any ONE LINE solution ?
>>> > Here, is my code.
>>> > Approach: shift left till LSB is 0 (say n number of times) then, OR
>>> > with 1, finally shift right (same number of times).
>>> >
>>> > #include
>>> >
>>> > int main(){
>>> > int count,m,n,ans,t;
>>> >
>>> > printf("Enter any number :");
>>> > scanf("%d",&n);
>>> >
>>> > m=8; //multiple of 8 !!
>>> > ans=0;
>>> > while(ans<=n){
>>> > t = m;
>>> > while(t){
>>> > count=0;
>>> > while(ans&1){
>>> > count++;
>>> > ans = ans>>1;
>>> > }
>>> > ans = ans|1;
>>> > ans = ans<>> > t--;
>>> > }
>>> > }
>>> >
>>> > printf("[%d]\n",ans);
>>> >
>>> > return 0;
>>> >
>>> >
>>> >
>>> > }- Hide quoted text -
>>> >
>>> > - Show quoted text -
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>> --
>> *Divesh*
>> (¨`·.·´¨) Always
>>   `·.¸(¨`·.·´¨ ) Keep
>>   (¨`·.·´¨)¸.·´Smiling!
>>`·.¸.·´" Life can give u 100's of reason 2cry,but u can give life
>> 1000's
>> of reasons 2Smile"
>>
>>  --
>> 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.
>>
>
>  --
> 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.
>



-- 
Rgds,
• » кυѕυмα ѕαηנєєν « •

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread saurabh agrawal
Simple one line solution without looping and efficient :

i=(i&7)?(i|7)+1:i)

On Sun, Sep 26, 2010 at 8:43 AM, coolfrog$
wrote:

> @Dave
> very nice one line solution..
>  we all are revolving around x>>3 concept...
>
>
> On Sat, Sep 25, 2010 at 10:17 PM, Dave  wrote:
>
>> answer = (x || 7) + 1;
>>
>> Dave
>>
>> On Sep 25, 6:56 am, Krunal Modi  wrote:
>> > Q: Write an algorithm to compute the next multiple of 8 for a given
>> > positive integer using bitwise operators.
>> >
>> > Example,
>> > (a) For the number 12, the next multiple of 8 is 16.
>> > (b) For the number 16, the next multiple of 8 is 24.
>> > -
>> > I have written a code using bitwise operators...but, I am not happy
>> > with the solutionIs there any ONE LINE solution ?
>> > Here, is my code.
>> > Approach: shift left till LSB is 0 (say n number of times) then, OR
>> > with 1, finally shift right (same number of times).
>> >
>> > #include
>> >
>> > int main(){
>> > int count,m,n,ans,t;
>> >
>> > printf("Enter any number :");
>> > scanf("%d",&n);
>> >
>> > m=8; //multiple of 8 !!
>> > ans=0;
>> > while(ans<=n){
>> > t = m;
>> > while(t){
>> > count=0;
>> > while(ans&1){
>> > count++;
>> > ans = ans>>1;
>> > }
>> > ans = ans|1;
>> > ans = ans<> > t--;
>> > }
>> > }
>> >
>> > printf("[%d]\n",ans);
>> >
>> > return 0;
>> >
>> >
>> >
>> > }- Hide quoted text -
>> >
>> > - Show quoted text -
>>
>> --
>> 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.
>>
>>
>
>
> --
> *Divesh*
> (¨`·.·´¨) Always
>   `·.¸(¨`·.·´¨ ) Keep
>   (¨`·.·´¨)¸.·´Smiling!
>`·.¸.·´" Life can give u 100's of reason 2cry,but u can give life 1000's
>
> of reasons 2Smile"
>
>  --
> 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.
>

-- 
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.



Re: [algogeeks] Re: BST in BT

2010-09-25 Thread mac adobe
@parody :..and how would that find me a maximum size BST ..  ??

( for checking if this BT is BST i would do inorder traversal and see if it
is increasing )



On Sun, Sep 26, 2010 at 11:10 AM, mac adobe  wrote:

> No parody .. that would be another  doubt :(
>
>
> On Sat, Sep 25, 2010 at 11:03 PM, prodigy <1abhishekshu...@gmail.com>wrote:
>
>> By maintaining a current maximum and a global maximum. You do know how
>> to verify  a BT is BST .
>>
>> http://pastebin.com/xwXXTEnP
>>
>> On Sep 25, 9:04 pm, mac adobe  wrote:
>> > How would you identify a binary search tree of maximum nodes in a binary
>> > tree ?
>>
>> --
>> 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.
>>
>>
>

-- 
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.



Re: [algogeeks] Re: BST in BT

2010-09-25 Thread mac adobe
No parody .. that would be another  doubt :(

On Sat, Sep 25, 2010 at 11:03 PM, prodigy <1abhishekshu...@gmail.com> wrote:

> By maintaining a current maximum and a global maximum. You do know how
> to verify  a BT is BST .
>
> http://pastebin.com/xwXXTEnP
>
> On Sep 25, 9:04 pm, mac adobe  wrote:
> > How would you identify a binary search tree of maximum nodes in a binary
> > tree ?
>
> --
> 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.
>
>

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread coolfrog$
@Dave
very nice one line solution..
 we all are revolving around x>>3 concept...


On Sat, Sep 25, 2010 at 10:17 PM, Dave  wrote:

> answer = (x || 7) + 1;
>
> Dave
>
> On Sep 25, 6:56 am, Krunal Modi  wrote:
> > Q: Write an algorithm to compute the next multiple of 8 for a given
> > positive integer using bitwise operators.
> >
> > Example,
> > (a) For the number 12, the next multiple of 8 is 16.
> > (b) For the number 16, the next multiple of 8 is 24.
> > -
> > I have written a code using bitwise operators...but, I am not happy
> > with the solutionIs there any ONE LINE solution ?
> > Here, is my code.
> > Approach: shift left till LSB is 0 (say n number of times) then, OR
> > with 1, finally shift right (same number of times).
> >
> > #include
> >
> > int main(){
> > int count,m,n,ans,t;
> >
> > printf("Enter any number :");
> > scanf("%d",&n);
> >
> > m=8; //multiple of 8 !!
> > ans=0;
> > while(ans<=n){
> > t = m;
> > while(t){
> > count=0;
> > while(ans&1){
> > count++;
> > ans = ans>>1;
> > }
> > ans = ans|1;
> > ans = ans< > t--;
> > }
> > }
> >
> > printf("[%d]\n",ans);
> >
> > return 0;
> >
> >
> >
> > }- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.
>
>


-- 
*Divesh*
(¨`·.·´¨) Always
  `·.¸(¨`·.·´¨ ) Keep
  (¨`·.·´¨)¸.·´Smiling!
   `·.¸.·´" Life can give u 100's of reason 2cry,but u can give life 1000's
of reasons 2Smile"

-- 
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.



Re: [algogeeks] Bitwise operator - Adobe

2010-09-25 Thread Terence

 If +,-,*,/ is completely forbidden, I think at least one loop is needed.
Here is my solution:

int next8mult (int n)
{
   n = (n & ~7);// clear the least 3 bit to make 
multiple of 8

   int r = 8;
   while(r) {  // add 8 to n
  int r1 = (n&r) << 1; // get carry bit
  n ^= r;  // perform bit addition
  r = r1;  // continue with carry.
   }
  return n;
}

On 2010-9-25 19:56, Krunal Modi wrote:

Q: Write an algorithm to compute the next multiple of 8 for a given
positive integer using bitwise operators.

Example,
(a) For the number 12, the next multiple of 8 is 16.
(b) For the number 16, the next multiple of 8 is 24.
-
I have written a code using bitwise operators...but, I am not happy
with the solutionIs there any ONE LINE solution ?
Here, is my code.
Approach: shift left till LSB is 0 (say n number of times) then, OR
with 1, finally shift right (same number of times).


#include

int main(){
 int count,m,n,ans,t;


 printf("Enter any number :");
 scanf("%d",&n);

 m=8; //multiple of 8 !!
 ans=0;
 while(ans<=n){
 t = m;
 while(t){
 count=0;
 while(ans&1){
 count++;
 ans = ans>>1;
 }
 ans = ans|1;
 ans = ans<

--
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.



[algogeeks] Re: ReVerse a string using recursion

2010-09-25 Thread Gene
Here is another approach.  Remove the first character.  Reverse the
rest of the string recursively.  Append the character at the end.
Others have given solutions along these lines, but they have various
mistakes.  Here's one that I believe is correct.  As pointed out
already, this is not a good place to apply recursion, but it's an
interesting puzzle.

#include 
#include 

// Reverse src having length len to dst.
char *reverse(char *dst, char *src, int len)
{
  if (len > 0) {
char ch = src[0];   // get 1st char
reverse(dst, &src[1], len - 1); // reverse rest
dst[len - 1] = ch;  // append 1st at end
  }
  return dst;
}

char *strrev(char *s) { return reverse(s, s, strlen(s)); }

int main(void) {
  char s[] = "The quick brown fox jumped...";
  printf("%s\n", strrev(s));
  return 0;
}

On Sep 23, 1:59 pm, Albert  wrote:
> How to reverse a String using recursion in C without using any extra
> memory?
>
> the question seems to be simple.
>
> char* strrev(char *)
> {
>     ...
>     ...
>     ...
>
> }
>
> Try to give all the answers for this prototype.

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Baljeet Kumar
@rajess
It works for all the cases.

On Sat, Sep 25, 2010 at 8:42 PM, rajess  wrote:

> this wont work if x=24 i.e.multiple of 8
>
> On Sep 25, 6:00 pm, Baljeet Kumar  wrote:
> > solution = ((x>>3) + 1)<<3;
> >
> > On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal  >wrote:
> >
> > > let the number be x .
> >
> > > solution = x - (x%8) + 8;
> >
> > > --
> > > 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.
> >
> > --
> > Baljeet Kumar
>
> --
> 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.
>
>


-- 
Baljeet Kumar

-- 
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.



Re: [algogeeks] Re: ReVerse a string using recursion

2010-09-25 Thread Nishant Agarwal
@albert
why r u asking for a non optimal solution??

On Sat, Sep 25, 2010 at 11:24 PM, albert theboss wrote:

> please let me know solution using extra memory.
>
> --
> 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.
>



-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT Allahabad
*

-- 
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.



Re: [algogeeks] Re: ReVerse a string using recursion

2010-09-25 Thread albert theboss
please let me know solution using extra memory.

-- 
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.



Re: [algogeeks] Re: Number problem

2010-09-25 Thread Yellow Sapphire
My code failed because it was reversing the digits and thus 0 was getting
added in the front which resulted in nothing.

If allowed we can use a char array else will have to find a solution which
does not reverse the digits of the number.

-- 
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.



[algogeeks] Re: BST in BT

2010-09-25 Thread prodigy
By maintaining a current maximum and a global maximum. You do know how
to verify  a BT is BST .

http://pastebin.com/xwXXTEnP

On Sep 25, 9:04 pm, mac adobe  wrote:
> How would you identify a binary search tree of maximum nodes in a binary
> tree ?

-- 
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.



[algogeeks] Re: ReVerse a string using recursion

2010-09-25 Thread Krunal Modi
I agree with Nishant.
For inplace replacement we need to swap two place for that we need
index, which is not possible without additional variables.

-- 
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.



[algogeeks] Re: next multiple of 8

2010-09-25 Thread Dave
Simpler: answer = (x || 7) + 1

Dave

On Sep 25, 10:14 am, rajess  wrote:
> scan last(left) 4 bits .if the bits are not 1000.make them 1000.else
> scan from left till u find first one(1).make this bit 1.and make
> last(left) bits as 1000

-- 
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.



[algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Dave
answer = (x || 7) + 1;

Dave

On Sep 25, 6:56 am, Krunal Modi  wrote:
> Q: Write an algorithm to compute the next multiple of 8 for a given
> positive integer using bitwise operators.
>
> Example,
> (a) For the number 12, the next multiple of 8 is 16.
> (b) For the number 16, the next multiple of 8 is 24.
> -
> I have written a code using bitwise operators...but, I am not happy
> with the solutionIs there any ONE LINE solution ?
> Here, is my code.
> Approach: shift left till LSB is 0 (say n number of times) then, OR
> with 1, finally shift right (same number of times).
>
> #include
>
> int main(){
>         int count,m,n,ans,t;
>
>         printf("Enter any number :");
>         scanf("%d",&n);
>
>         m=8; //multiple of 8 !!
>         ans=0;
>         while(ans<=n){
>                 t = m;
>                 while(t){
>                         count=0;
>                         while(ans&1){
>                                 count++;
>                                 ans = ans>>1;
>                         }
>                         ans = ans|1;
>                         ans = ans<                         t--;
>                 }
>         }
>
>         printf("[%d]\n",ans);
>
>         return 0;
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

-- 
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.



[algogeeks] BST in BT

2010-09-25 Thread mac adobe
How would you identify a binary search tree of maximum nodes in a binary
tree ?

-- 
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.



[algogeeks] next multiple of 8

2010-09-25 Thread rajess
scan last(left) 4 bits .if the bits are not 1000.make them 1000.else
scan from left till u find first one(1).make this bit 1.and make
last(left) bits as 1000

-- 
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.



[algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread rajess
this wont work if x=24 i.e.multiple of 8

On Sep 25, 6:00 pm, Baljeet Kumar  wrote:
> solution = ((x>>3) + 1)<<3;
>
> On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal wrote:
>
> > let the number be x .
>
> > solution = x - (x%8) + 8;
>
> > --
> > 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 > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Baljeet Kumar

-- 
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.



Re: [algogeeks] Re: Adobe Question

2010-09-25 Thread Nikhil Jindal
The answer would be:
(log1+1) + (log2+1) + (log3+1) + (log4+1) + ... + (log(n-1)+1)
which is equal to:
(log1+log2+log3+...+log(n-1)) + (n-1)
==> *log((n-1)!) + (n-1)*
where, log everywhere is assumed to be in base 2
*This according to me will be the final answer!*
*
*
*Cheers*
*Nikhil Jindal
*
On Fri, Sep 24, 2010 at 8:10 PM, SVIX wrote:

> what's the datatype of j? mathematically speaking, the while loop is
> infinite for every j>0...
>
> On Sep 23, 6:19 am, Krunal Modi  wrote:
> > for(k=1 ; k >   j=k;
> >   while(j>0){
> >  j=j/2;
> >   }
> >
> > }
> >
> > How many times while loop gets executed (for any n) ?
> >
> > I don't want answer in terms of series (i.e, don't want any sigma, I
> > have that)
>
> --
> 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.
>
>

Please access the attached hyperlink for an important electronic communications 
disclaimer: http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Baljeet Kumar
solution = ((x>>3) + 1)<<3;

On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal wrote:

> let the number be x .
>
> solution = x - (x%8) + 8;
>
> --
> 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.
>



-- 
Baljeet Kumar

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Rahul Singal
let the number be x .

solution = x - (x%8) + 8;

-- 
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.



Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread rahul
Example,
(a) For the number 12, the next multiple of 8 is 16.
(b) For the number 16, the next multiple of 8 is 24.

did u mean next multiple of 8 greater than given number(12 or 16). ?

On Sat, Sep 25, 2010 at 5:28 PM, Krunal Modi  wrote:

> Basically, I am starting from (ans=)0 & checking if it has become
> greater than n, if not repeat(means, add 8) else answer is found.
>
> --
> 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.
>
>

-- 
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.



Re: [algogeeks] Amazon Interview

2010-09-25 Thread Soundar
http://michael.dipperstein.com/rle/index.html


Step 1. Set the previous symbol equal to an unmatchable value.
Step 2. Read the next symbol from the input stream.
Step 3. If the symbol is an EOF exit.
Step 4. Write out the current symbol.
Step 5. If the symbol is an does not match the previous symbol, set
the previous symbol to the current symbol, and go to step 2.
Step 6. Read and count additional symbols until a non-matching symbol
is found. This is the run length.
Step 7. Write out the run length.
Step 8. Write out the non-matching symbol.
Step 9. Set the previous symbol to the non-matching symbol, and go to 
step 2.

-- 
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.



[algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Krunal Modi
Basically, I am starting from (ans=)0 & checking if it has become
greater than n, if not repeat(means, add 8) else answer is found.

-- 
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.



[algogeeks] Bitwise operator - Adobe

2010-09-25 Thread Krunal Modi
Q: Write an algorithm to compute the next multiple of 8 for a given
positive integer using bitwise operators.

Example,
(a) For the number 12, the next multiple of 8 is 16.
(b) For the number 16, the next multiple of 8 is 24.
-
I have written a code using bitwise operators...but, I am not happy
with the solutionIs there any ONE LINE solution ?
Here, is my code.
Approach: shift left till LSB is 0 (say n number of times) then, OR
with 1, finally shift right (same number of times).


#include

int main(){
int count,m,n,ans,t;


printf("Enter any number :");
scanf("%d",&n);

m=8; //multiple of 8 !!
ans=0;
while(ans<=n){
t = m;
while(t){
count=0;
while(ans&1){
count++;
ans = ans>>1;
}
ans = ans|1;
ans = ans

Re: [algogeeks] Re: Number problem

2010-09-25 Thread Nishant Agarwal
Here's the code
int rem_dup(int n)
{
int *a,i,c,t,d,count[10]={0},arr[20],j=0,sum=0;
a=(int *)malloc(sizeof(a));
for(i=0;n>0;i++)//storing each digit of number in an array
{
a[i]=n%10;
n=n/10;
}
c=d=i-1;
i=0;
while(i wrote:

> @Saurabh: Doesn't this turn 10 into 1? You need to count the digits in
> the number as you are reversing it, and replace the second while loop
> with a for loop with that many iterations.
>
> Dave
>
> On Sep 21, 11:28 pm, saurabh agrawal  wrote:
> > @dave:
> > your code is producing 4526 for input=24526 instead of 2456
> > Here's corrected code :)
> > /CODE///
> > int function(int n){
> > int a[10]={0},temp=0,result =0;
> > while(n){   //reverse the number..
> >  temp=10*temp+n%10;
> >  n/=10;
> > }
> > n=temp;
> > while(n){   ///remove duplicate digits...
> >  if(a[n%10]==0){
> >  a[n%10]=1;
> >  result=10*result+n%10;
> >  }
> > n/=10;
> > }
> > return result;}
> >
> > ///END/
> >
> >
> >
> > On Wed, Sep 22, 2010 at 8:51 AM, Dave  wrote:
> > > @Saurabh: Doesn't your code turn 123 into 321? Try this:
> >
> > > int function(int n)
> > > {
> > >int a[10]={0};
> > >int result=0;
> > > int place=1;
> > > while(n){
> > >if(a[n%10]==0){
> > >a[n%10]=1;
> > > result+=(n%10)*place;
> > >place*=10;
> > >}
> > >n/=10;
> > >}
> > >return result;
> > > }
> >
> > > Dave
> >
> > > On Sep 21, 3:12 pm, saurabh agrawal  wrote:
> > > > int function(int n){
> >
> > > > int a[10]={0};
> > > > int result =0;
> > > > while(n){
> > > > if(a[n%10]==0){
> > > > a[n%10]=1;
> > > > result=10*result+n%10;
> > > > }
> > > > n/=10;}
> >
> > > > return result;`
> >
> > > > }
> > > > On Wed, Sep 22, 2010 at 12:39 AM, Albert 
> > > wrote:
> > > > > Given a number find the number by eliminating the duplicate digits
> in
> > > > > the number..
> >
> > > > > for eg:   24526  ans is 2456
> > > > > .
> >
> > > > > int function(int n)
> > > > > {
> >
> > > > >  .
> > > > >  .
> > > > >  .
> >
> > > > > }
> >
> > > > > Give all sort of solutions to this problem.
> >
> > > > > Efficiency in the code is important 
> >
> > > > > --
> > > > > 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.-Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > --
> > > 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.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.
>
>


-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT Allahabad
*

-- 
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.



Re: [algogeeks] Re: Number problem

2010-09-25 Thread Nishant Agarwal
@yellow
your code turns 1000,100,10,2270,12130 to 1,1,1,27,123 repectively
simply it removes all trailing zeros ...

On Wed, Sep 22, 2010 at 8:10 PM, Yellow Sapphire wrote:

> My Solution.
>
> Almost same as above but the flag is set by using bits.
>
> #define SETFLAG(flag, pos) (flag=flag | (1< #define IS_FLAG_SET(flag,pos) (flag & (1<
> int remove_dup(int n)
> {
>int temp=0, temp2=0;
>unsigned int flag=0;
>
>/*
> * Reverse the number
> */
>while (n>0 && (temp=temp*10 + n%10), n=n/10);
>
>/*
> * Find duplicates by setting the bits in the flag
> */
>n=temp;
>temp=0;
>while (n>0) {
>temp2=n%10;
>if(!IS_FLAG_SET(flag, temp2)) {
>temp=temp*10 + temp2;
>SETFLAG(flag, temp2);
>}
>n=n/10;
>}
>return temp;
> }
>
> --
> 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.
>
>


-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT Allahabad
*

-- 
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.



Re: [algogeeks] Fwd: another help please

2010-09-25 Thread rahul rai
Yes , i. Can , and i did , but is't there a shortcut . I want to know that

2010/9/24, mohit ranjan :
> Dear Rahul,
>
> Can you try writing hex digits in binary and try.
>
> 0x77 --> 0111 0111
> 0x03 -->  0011
> ---
> AND   0011 --> 0x03
>
>
> Cheers !
> Mohit
>
>
> On Thu, Sep 23, 2010 at 10:25 PM, rahul rai  wrote:
>
>>
>> Rahul K Rai
>> rahulpossi...@gmail.com
>>
>>
>> -- Forwarded message --
>> From: rahul rai 
>> Date: 2010/9/23
>> Subject: another help please
>> To: Baljeet Kumar 
>>
>>
>>
>> Rahul K Rai
>>
>>
>> please explain me this please
>> rahulpossi...@gmail.com
>>
>>  --
>> 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.
>>
>
> --
> 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.
>
>


-- 
Rahul K Rai
rahulpossi...@gmail.com

-- 
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.



Re: [algogeeks] Re: Microsoft interview question

2010-09-25 Thread mohit ranjan
@Ashita,

Your logic is fine for one vs one game, but as per question it's "one vs
many game"
Any idea what is that ?


Mohit

On Sat, Sep 25, 2010 at 1:18 PM, ashita dadlani  wrote:

> 1.The soldiers are initially placed at row 2 or row 7th(each-one of white
> and either of black).Also let white ones be at row 2.So they can never be at
> row 1st.Incase it is so in the game,its not a valid game.
> 2.There are Bishops.Each color has one of its Bishop which moves diagonally
> on all white squares,and the other on all black squares.Incase it is not
> so,the game cannot be valid.
> 3.Now suppose,no black soldier ever moved.That is,all the black soldiers
> are at row 7th.This means that the elephant(i am sorry,I generally mess up
> with their names..:P) of any other player(except horse) cannot be in any row
> but 8th one.
>
> I know only 3 test cases.Incase any one has more,please elaborate.
> PS:Vrinda,I also got the same question..:P
>
>
> On Sat, Sep 25, 2010 at 2:49 AM, Gene  wrote:
>
>> Valid must mean that you can get from an initial board to the the
>> current game state by a series of legal moves.
>>
>> This is a classic branch and bound game tree search problem.  You
>> could search either from a starting configuration and try to "find"
>> the current game state.  Or start from the current state, use
>> 'backward' moves, and try to find the initial configuration.  In this
>> case, you'd have to include backward moves that 'untake' pieces that
>> are missing from the current state.
>>
>> Or you could do a simultaneous search from both ends, looking for
>> common states in the middle.
>>
>> You'd generally use a heuristic search. Problems like this often work
>> well with A-Star.  The heuristic evaluator would favor states closer
>> to the desired end (either start or current).
>>
>> Gene
>>
>> On Sep 24, 6:26 am, vrinda vasishth  wrote:
>> > Asked in microsoft interview
>> >
>> > "Given a snapshot of an ongoing chess game, which probably is a one vs
>> many
>> > game,  identify whether it is a valid game or not."
>> >
>> > It would be great if someone would clarify on what conditions does
>> > "validity" of the game depend..
>> >
>> > --Vrinda
>>
>> --
>> 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.
>>
>>
>   --
> 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.
>

-- 
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.