[algogeeks] Algo

2011-08-30 Thread Naman Mahor
Given n unsigned integer, output 2 integers which has the maximum result
after XOR.


-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Probability

2011-08-29 Thread Naman Mahor
abhishek's answer.
plz  clear my confusion
that i hv mentioned above.
On Mon, Aug 29, 2011 at 6:04 PM, vishwa  wrote:

> @naman: whose answer man
>
>
> On Mon, Aug 29, 2011 at 5:56 PM, Naman Mahor wrote:
>
>> ur answer is correct but i hv a confusion that all four shots fire at a
>> time so there may be probability that all shots hits the craft. but ur
>> assuming that first hit + first not hit * second hit+..
>> plz clear my confustion
>>
>> On Mon, Aug 29, 2011 at 5:49 PM, Abhishek Yadav <
>> algowithabhis...@gmail.com> wrote:
>>
>>> i guess it would be    0.7 + 0.3*0.6 + 0.3*0.4*0.5 + 0.3*0.4*0.5*0.4
>>> =.964.correct me if i am wrong.??
>>>
>>> On Mon, Aug 29, 2011 at 5:34 PM, Naman Mahor wrote:
>>>
>>>> An anti aircraft gun can fire four shots at a time. If the probabilities
>>>> of the first, second, third and the last shot hitting the enemy aircraft 
>>>> are
>>>> 0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an
>>>> enemy aircraft will bring the aircraft down?
>>>>
>>>> --
>>>> 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 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 algogeeks@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 algogeeks@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 algogeeks@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 algogeeks@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] Probability

2011-08-29 Thread Naman Mahor
i hv googled it and the answer is like
The enemy aircraft will be brought down even if one of the four shots hits
the aircraft.

The opposite of this situation is that none of the four shots hit the
aircraft.

The probability that none of the four shots hit the aircraft is given by
(1-0.7)(1-0.6)(1-0.5)(1-0.4) = 0.3*0.4*0.5*0.6 = 0.036

So, the probability that at least one of the four hits the aircraft = 1 –
0.036 = 0.964.

On Mon, Aug 29, 2011 at 5:54 PM, vishwa  wrote:

> is it 0.55...
>
>
> On Mon, Aug 29, 2011 at 5:49 PM, Abhishek Yadav <
> algowithabhis...@gmail.com> wrote:
>
>> i guess it would be    0.7 + 0.3*0.6 + 0.3*0.4*0.5 + 0.3*0.4*0.5*0.4
>> =.964.correct me if i am wrong.??
>>
>>
>> On Mon, Aug 29, 2011 at 5:34 PM, Naman Mahor wrote:
>>
>>> An anti aircraft gun can fire four shots at a time. If the probabilities
>>> of the first, second, third and the last shot hitting the enemy aircraft are
>>> 0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an
>>> enemy aircraft will bring the aircraft down?
>>>
>>> --
>>> 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 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 algogeeks@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 algogeeks@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 algogeeks@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] Probability

2011-08-29 Thread Naman Mahor
ur answer is correct but i hv a confusion that all four shots fire at a time
so there may be probability that all shots hits the craft. but ur assuming
that first hit + first not hit * second hit+..
plz clear my confustion

On Mon, Aug 29, 2011 at 5:49 PM, Abhishek Yadav
wrote:

> i guess it would be    0.7 + 0.3*0.6 + 0.3*0.4*0.5 + 0.3*0.4*0.5*0.4
> =.964.correct me if i am wrong.??
>
> On Mon, Aug 29, 2011 at 5:34 PM, Naman Mahor wrote:
>
>> An anti aircraft gun can fire four shots at a time. If the probabilities
>> of the first, second, third and the last shot hitting the enemy aircraft are
>> 0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an
>> enemy aircraft will bring the aircraft down?
>>
>> --
>> 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 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 algogeeks@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 algogeeks@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] Probability

2011-08-29 Thread Naman Mahor
An anti aircraft gun can fire four shots at a time. If the probabilities of
the first, second, third and the last shot hitting the enemy aircraft are
0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an
enemy aircraft will bring the aircraft down?

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c programe explain

2011-08-21 Thread Naman Mahor
const char* into char * is error not warning
i hv run it on DEV c++;

On Sun, Aug 21, 2011 at 11:01 PM, Sanjay Rajpal  wrote:

> i didnt run it, this concept is given in J.K.Chhabra book.
>
>
> Sanju
> :)
>
>
>
> On Sun, Aug 21, 2011 at 10:29 AM, Puneet Chawla  > wrote:
>
>> ohh srry.i didn't run it...sry again..
>>
>>
>> On Sun, Aug 21, 2011 at 10:58 PM, Sanjay Rajpal  wrote:
>>
>>>  it is a warning dear, not an error :)
>>>
>>>
>>> Sanju
>>> :)
>>>
>>>
>>>
>>> On Sun, Aug 21, 2011 at 10:27 AM, Puneet Chawla <
>>> puneetchawla...@gmail.com> wrote:
>>>
 okk tht i knew bt my point is We are converting const char* into char *
 here means "Interview" const char* into char *


 On Sun, Aug 21, 2011 at 10:55 PM, Sanjay Rajpal wrote:

>  See precedence of ++ is greater than that of +=.
>
> so ii=7.
> Now in the statement funct(ii+++"Campus Interview"), when +++ will be
> parsed, it'll be ++ +, so
> ii++ + "Campus Interview" will be 7 + "Campus Interview" , which is
> equivalent to "Campus Interview"[7].
>
> Now to the function address passed starts from Interview.
>
> hence the result.
> Sanju
> :)
>
>
>
> On Sun, Aug 21, 2011 at 10:23 AM, Sanjay Rajpal wrote:
>
>>  the o/p wil be Interview.
>>
>>
>>
>> Sanju
>> :)
>>
>>
>>
>> On Sun, Aug 21, 2011 at 10:20 AM, SuDhir mIsHra <
>> sudhir08.mis...@gmail.com> wrote:
>>
>>>  funct(char* str)
>>> {
>>> printf("%s\n",str);
>>> }
>>> main()
>>> {
>>> static int ii = 1;
>>> int jj = 5;
>>> ii+=++jj;
>>> funct(ii+++"Campus Interview");
>>> }
>>>
>>> --
>>> 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 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 algogeeks@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.
>



 --
 With regards
   
 Puneet Chawla
 Computer Engineering Student
 NIT Kurukshetra

 --
  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 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 algogeeks@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.
>>>
>>
>>
>>
>> --
>> With regards
>>   
>> Puneet Chawla
>> Computer Engineering Student
>> NIT Kurukshetra
>>
>> --
>> 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 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 algogeeks@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 algogeeks@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] why the output 16

2011-08-21 Thread Naman Mahor
 8==0?1:8* (8-1*(8-1-1))
this will execute as 8*(8-1(8-2)) => 8*(8-1*6)>8*(8-6)===>8*2===>16


On Sat, Aug 20, 2011 at 7:02 PM, SuDhir mIsHra wrote:

> #include
> #define FUNC1(i) (i*(i-1))
> #define FUNC2(i) (i==0?1:i*FUNC1(i-1))
> main()
> {
> int i=8;
>
>
> printf("\n%d",FUNC2(i));
> }
>
> --
> 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 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 algogeeks@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] sol

2011-08-21 Thread Naman Mahor
@sanjay
u r right

On Sun, Aug 21, 2011 at 1:18 PM, Sanjay Rajpal  wrote:

> @naman : if there is a carry that will be produced, the result will not be
> the sum.
> e.g
>
> 13 + 17 :  1101 + 00010001
> On Xoring, the result is 0001 1100 which is 28.
>
> Sanju
> :)
>
>
>
> On Sun, Aug 21, 2011 at 12:44 AM, Naman Mahor wrote:
>
>> sum of a and b will print
>>
>>
>> On Sun, Aug 21, 2011 at 11:36 AM, Puneet Chawla <
>> puneetchawla...@gmail.com> wrote:
>>
>>> If a,b are not equal then this statement will always return true status
>>> as a^b=true so true bit-wise or-ed with anyone will return true.
>>>
>>>
>>> On Sun, Aug 21, 2011 at 10:38 AM, SHUBHAM BANSAL <
>>> shubham.bans...@gmail.com> wrote:
>>>
>>>> ((a^b) | ((a&b)<<1))
>>>> sorry tht was bitwise or..by mistak i hd wrote logicl or
>>>> SHUBHAM BANSAL
>>>> COMP DEPT..
>>>> NIT KKr
>>>>
>>>>
>>>>
>>>> On Sun, Aug 21, 2011 at 9:30 AM, Sanjay Rajpal wrote:
>>>>
>>>>> Yes if a or b are non zero, the result is always 1.
>>>>> Sanju
>>>>> :)
>>>>>
>>>>>
>>>>>
>>>>> On Sat, Aug 20, 2011 at 8:57 PM, Naman Mahor wrote:
>>>>>
>>>>>> @sanjay
>>>>>> assume that the value of a=0,b=0;
>>>>>> so a^b=0
>>>>>> and (a&b)<<1 =0
>>>>>> so answer will zero.
>>>>>> so the result will not always 1. it can be 0 or 1 depends on the value
>>>>>> of a n b.
>>>>>>
>>>>>>
>>>>>> On Sun, Aug 21, 2011 at 12:12 AM, Sanjay Rajpal wrote:
>>>>>>
>>>>>>>  || is a short-circuit operator(LOGICAL OR).
>>>>>>>
>>>>>>> if first condition is true, then second is not evaluated, only if
>>>>>>> first is false, second is evaluated.
>>>>>>>
>>>>>>> If a==b, then second condition will evaluate to true, else first
>>>>>>> condition will be evaluated, which are true here both.
>>>>>>>
>>>>>>> So the result is always 1.
>>>>>>> Sanju
>>>>>>> :)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sat, Aug 20, 2011 at 11:37 AM, Atul Modi wrote:
>>>>>>>
>>>>>>>> || is not bitwise or...it is logical orso it is basically for
>>>>>>>> the two ops (a^b) being succesful n (a&b)<<1 returning 1 on 
>>>>>>>> successthus
>>>>>>>> the ans. is 1 i think
>>>>>>>>
>>>>>>>> On Sat, Aug 20, 2011 at 11:59 PM, Aditya Virmani <
>>>>>>>> virmanisadi...@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> @priya..wht if a=b=0 ? or a=b= 1000 
>>>>>>>>>
>>>>>>>>>  On Sat, Aug 20, 2011 at 11:33 PM, priya ramesh <
>>>>>>>>> love.for.programm...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> the answer is 1
>>>>>>>>>> sum=1
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 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 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 algogeeks@googlegroups.com.
>>>>>>>>> To unsubscribe from this group, send email to
>>>>&g

Re: [algogeeks] sol

2011-08-21 Thread Naman Mahor
sum of a and b will print

On Sun, Aug 21, 2011 at 11:36 AM, Puneet Chawla
wrote:

> If a,b are not equal then this statement will always return true status as
> a^b=true so true bit-wise or-ed with anyone will return true.
>
>
> On Sun, Aug 21, 2011 at 10:38 AM, SHUBHAM BANSAL <
> shubham.bans...@gmail.com> wrote:
>
>> ((a^b) | ((a&b)<<1))
>> sorry tht was bitwise or..by mistak i hd wrote logicl or
>> SHUBHAM BANSAL
>> COMP DEPT..
>> NIT KKr
>>
>>
>>
>> On Sun, Aug 21, 2011 at 9:30 AM, Sanjay Rajpal  wrote:
>>
>>> Yes if a or b are non zero, the result is always 1.
>>> Sanju
>>> :)
>>>
>>>
>>>
>>> On Sat, Aug 20, 2011 at 8:57 PM, Naman Mahor wrote:
>>>
>>>> @sanjay
>>>> assume that the value of a=0,b=0;
>>>> so a^b=0
>>>> and (a&b)<<1 =0
>>>> so answer will zero.
>>>> so the result will not always 1. it can be 0 or 1 depends on the value
>>>> of a n b.
>>>>
>>>>
>>>> On Sun, Aug 21, 2011 at 12:12 AM, Sanjay Rajpal wrote:
>>>>
>>>>>  || is a short-circuit operator(LOGICAL OR).
>>>>>
>>>>> if first condition is true, then second is not evaluated, only if first
>>>>> is false, second is evaluated.
>>>>>
>>>>> If a==b, then second condition will evaluate to true, else first
>>>>> condition will be evaluated, which are true here both.
>>>>>
>>>>> So the result is always 1.
>>>>> Sanju
>>>>> :)
>>>>>
>>>>>
>>>>>
>>>>> On Sat, Aug 20, 2011 at 11:37 AM, Atul Modi wrote:
>>>>>
>>>>>> || is not bitwise or...it is logical orso it is basically for the
>>>>>> two ops (a^b) being succesful n (a&b)<<1 returning 1 on successthus 
>>>>>> the
>>>>>> ans. is 1 i think
>>>>>>
>>>>>> On Sat, Aug 20, 2011 at 11:59 PM, Aditya Virmani <
>>>>>> virmanisadi...@gmail.com> wrote:
>>>>>>
>>>>>>> @priya..wht if a=b=0 ? or a=b= 1000 
>>>>>>>
>>>>>>>  On Sat, Aug 20, 2011 at 11:33 PM, priya ramesh <
>>>>>>> love.for.programm...@gmail.com> wrote:
>>>>>>>
>>>>>>>> the answer is 1
>>>>>>>> sum=1
>>>>>>>>
>>>>>>>> --
>>>>>>>> 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 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 algogeeks@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 algogeeks@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 algogeeks@googlegroups.com.
>>>>

Re: [algogeeks]

2011-08-21 Thread Naman Mahor
#include
using namespace std;
class base
   {
   public:
   int bval;
   base(){bval=0;}
   };
class deri:public base
   {
   public:
   int dval;
   deri(){dval=1;}
   };
void SomeFunc(base *arr,int size)
{
for(int i=0; ibval<bval)<wrote:

> Wil u please explain in context of o/p.means how 1 whn SomeFunc(DeriArr,5);
> stmt is executed how 0 and 1 will come..???
>
>
> On Sun, Aug 21, 2011 at 12:40 PM, Naman Mahor wrote:
>
>> because the pointer of base class will move by 2 bytes every time but the
>> size of derived class is 4 byte.
>>
>>
>> On Sun, Aug 21, 2011 at 12:31 PM, Puneet Chawla <
>> puneetchawla...@gmail.com> wrote:
>>
>>> class base
>>>{
>>>public:
>>>int bval;
>>>base(){bval=0;}
>>>};
>>> class deri:public base
>>>{
>>>public:
>>>int dval;
>>>deri(){dval=1;}
>>>};
>>> void SomeFunc(base *arr,int size)
>>> {
>>> for(int i=0; i>>cout<bval;
>>> cout<>> }
>>> int main()
>>> {
>>> base BaseArr[5];
>>> SomeFunc(BaseArr,5);
>>> deri DeriArr[5];
>>> SomeFunc(DeriArr,5);
>>> system("pause");
>>> return 0;
>>> }
>>>
>>> 0
>>> 01010
>>> Will somebody tell me why it's showing this..??
>>>
>>> --
>>> With regards
>>>   
>>> Puneet
>>>
>>>  --
>>> 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 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 algogeeks@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.
>>
>
>
>
> --
> With regards
>   
> Puneet
>
>  --
> 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 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 algogeeks@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]

2011-08-21 Thread Naman Mahor
because the pointer of base class will move by 2 bytes every time but the
size of derived class is 4 byte.

On Sun, Aug 21, 2011 at 12:31 PM, Puneet Chawla
wrote:

> class base
>{
>public:
>int bval;
>base(){bval=0;}
>};
> class deri:public base
>{
>public:
>int dval;
>deri(){dval=1;}
>};
> void SomeFunc(base *arr,int size)
> {
> for(int i=0; icout cout< }
> int main()
> {
> base BaseArr[5];
> SomeFunc(BaseArr,5);
> deri DeriArr[5];
> SomeFunc(DeriArr,5);
> system("pause");
> return 0;
> }
>
> 0
> 01010
> Will somebody tell me why it's showing this..??
>
> --
> With regards
>   
> Puneet
>
>  --
> 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 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 algogeeks@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 of nodes at each level in binary tree

2011-08-20 Thread Naman Mahor
it can be done by bfs with slight modification. so in bfs we use queue we
have to add a dummy node in queue. So this node will tell us that end of
level has come.so we can find out the no of node at any level using bfs.

On Sun, Aug 21, 2011 at 1:34 AM, Dave  wrote:

> @Sagar: The problem doesn't say that the tree is complete. The number
> of nodes in level i can be anything between 1 and 2^i. The question is
> asking how to count the nodes in each level efficiently.
>
> Dave
>
> On Aug 20, 3:00 pm, sagar pareek  wrote:
> > and total number of nodes( leaves+internal ) present in a ith level tree
> is
> > 2^(i+1)-1
> >
> >
> >
> >
> >
> > On Sun, Aug 21, 2011 at 1:28 AM, sagar pareek 
> wrote:
> > > 2(power)i  or 2^i
> > > where i is level  i=0,1,2,3..
> >
> > > On Sun, Aug 21, 2011 at 1:27 AM, bugaboo 
> wrote:
> >
> > >> Anyone knows the algorithm to count the number of nodes at each level
> > >> in a binary tree. Providing the approach and logic better than the
> > >> actual code itself.
> >
> > >> --
> > >> 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 group at
> > >>http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > **Regards
> > > SAGAR PAREEK
> > > COMPUTER SCIENCE AND ENGINEERING
> > > NIT ALLAHABAD
> >
> > --
> > **Regards
> > SAGAR PAREEK
> > 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 algogeeks@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 algogeeks@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] sol

2011-08-20 Thread Naman Mahor
@sanjay
assume that the value of a=0,b=0;
so a^b=0
and (a&b)<<1 =0
so answer will zero.
so the result will not always 1. it can be 0 or 1 depends on the value of a
n b.

On Sun, Aug 21, 2011 at 12:12 AM, Sanjay Rajpal  wrote:

> || is a short-circuit operator(LOGICAL OR).
>
> if first condition is true, then second is not evaluated, only if first is
> false, second is evaluated.
>
> If a==b, then second condition will evaluate to true, else first condition
> will be evaluated, which are true here both.
>
> So the result is always 1.
> Sanju
> :)
>
>
>
> On Sat, Aug 20, 2011 at 11:37 AM, Atul Modi  wrote:
>
>> || is not bitwise or...it is logical orso it is basically for the two
>> ops (a^b) being succesful n (a&b)<<1 returning 1 on successthus the ans.
>> is 1 i think
>>
>> On Sat, Aug 20, 2011 at 11:59 PM, Aditya Virmani <
>> virmanisadi...@gmail.com> wrote:
>>
>>> @priya..wht if a=b=0 ? or a=b= 1000 
>>>
>>>  On Sat, Aug 20, 2011 at 11:33 PM, priya ramesh <
>>> love.for.programm...@gmail.com> wrote:
>>>
 the answer is 1
 sum=1

 --
 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 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 algogeeks@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 algogeeks@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 algogeeks@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 algogeeks@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] Puzzle

2011-08-20 Thread Naman Mahor
21

On Sat, Aug 20, 2011 at 5:16 PM, Nikhil Gupta wrote:

> Each side of a given polygon is parallel to either the X or the Y axis. A
> corner of such a polygon is said to be convex if the internal angle is 90o or
> concave if the internal angle is 270o. If the number of convex corners in
> such a polygon is 25, the number of concave corners must be
> 21
> 23
> 22
> 20
> --
> Nikhil Gupta
>
> --
> 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 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 algogeeks@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] Challenge

2011-08-20 Thread Naman Mahor
it is O(m+n). sure??

On Sat, Aug 20, 2011 at 2:52 PM, Sanjay Rajpal  wrote:

>  We are given a 2-D array of 0s and 1s.
> We have to determine which row contains maximum no. of 1s in the array in
> O(m+n);
> where m - no. of rows and n - no. of columns.
>
> Sanju
> :)
>
>  --
> 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 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 algogeeks@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] Google Question:Given a BST and a number, Find the closest node to that number in the BST.

2011-08-20 Thread Naman Mahor
i think there will be three candidate..
1. TreeSuccessor(nd)  2. TreePredecessor(nd) 3. nd it self.


On Sat, Aug 20, 2011 at 12:56 PM, Abhishek Yadav  wrote:

> Hey i tried it now and got to another solution
> O(log n) solution:
> 1. try searching for the number , if found,return the node, otherwise, you
> will ultimately reach a leaf node say 'nd'
> 2.  Now the two candidates for the answer would be
>1. TreeSuccessor(nd)  2. TreePredecessor(nd)
> Now compare the original number with these two and minimum would be the
> answer.
>
> (TreeSuccessor and TreePredecessor are the next and previous node resp. in
> the Inorder traversal of the tree.)
>
> On Sat, Aug 20, 2011 at 12:46 PM, Dipankar Patro wrote:
>
>> why traverse the whole tree?
>>
>> at each root keep the difference in a min_diff and min_ele.
>> if the entered value is less root then move to left or right.
>> repeat above two until whole tree is checked or min_diff becomes 0.
>>
>> pseudo code:
>>
>> min_diff = INF; // global variables
>> min_ele = 0;
>>
>> find_min_diff(node *root, int num)
>> {
>>
>>  if (root == null)
>>  return;
>>
>> // update the difference
>>  if(abs(root->val - num) < min_diff)
>>  {
>>   min_diff = abs(root->val - num);
>>   min_ele = root->val;
>>  }
>>  if ( min_diff == 0)
>>   return; // search is over
>>
>> // proceed to next element in tree which might be closer to the num
>>  if ( num < root-> val)
>>find_min_ele(root->left, num);
>>  else
>>find_min_ele(root->right, num);
>> }
>>
>> ^^ Complexity : O(logn)
>>
>> On 20 August 2011 12:36, Abhishek Yadav wrote:
>>
>>> yes, the interviewer said that there is a solution in O(log n)
>>>
>>>
>>> On Sat, Aug 20, 2011 at 12:29 PM, sukran dhawan 
>>> wrote:
>>>
 ur traversing the tree once so it shud be o(n).does the question demand
 0(logn) ?

  On Sat, Aug 20, 2011 at 12:27 PM, Abhishek Yadav <
 algowithabhis...@gmail.com> wrote:

> what would be the complexity of your solution O(n) or O(log n)..?
>
>  On Sat, Aug 20, 2011 at 12:19 PM, sukran dhawan <
> sukrandha...@gmail.com> wrote:
>
>> traverse bst inorder and each time u encounter a node find the
>> difference between the element and given element in question . if the
>> absolute difference is minimum after traversing the tree that is the 
>> element
>> . u can getback the element using another element which keeps sign of the
>> element so that original element can be obtained from diff
>>
>> On Sat, Aug 20, 2011 at 12:15 PM, Abhishek Yadav <
>> algowithabhis...@gmail.com> wrote:
>>
>>> Given a BST and a number, Find the closest node to that number in the
>>> BST. Give an algorithm for that.
>>> Let there be binary search tree having nodes with values
>>> 12,34,64,23,64,25,76,6 and the number given is 28, then the answer
>>> would be 25 as it is the closest node.
>>>
>>> --
>>> 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 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 algogeeks@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 algogeeks@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 algogeeks@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 algogeeks@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] probability

2011-08-20 Thread Naman Mahor
let's say A keep tossing a fair coin, until he get 2 consecutive heads,
define X to be the number of tosses for this process; B keep tossing another
fair coin, until he get 3 consecutive heads, define Y to be the number of
the tosses for this process.Calculate P{X>Y}

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.