Re: [algogeeks] microsoft ques

2011-07-12 Thread Neeraj Gupta
Oppalis algo-
Please let me know if there is a bug in it.
http://www.ideone.com/u1m07
On Wed, Jul 13, 2011 at 11:36 AM, Aniket Dutta wrote:

> @sunny: right thanks for correcting
>
>
> On Wed, Jul 13, 2011 at 11:33 AM, sunny agrawal 
> wrote:
>
>> @Aniket Dutta
>> Solution for your case will be 96
>>
>> Algorithm Posted by Oppilas will do and is O(n).
>>
>>
>> On Wed, Jul 13, 2011 at 11:28 AM, Aniket Dutta 
>> wrote:
>>
>>> @vaibhav: Sir ur algo fails in this array {2,-8,-3,1,2} it should give
>>> answer as 24 but ur algo gives 2
>>>
>>>
>>> On Wed, Jul 13, 2011 at 11:02 AM, varun pahwa 
>>> wrote:
>>>
 please ignore my previous post that solution is wrong.


 On Wed, Jul 13, 2011 at 11:01 AM, sameer.mut...@gmail.com <
 sameer.mut...@gmail.com> wrote:

> @kranthi :
>
> d solution u ve given is only for 2 continuous elements..
> wr as d question doesnt limit it to 2.. It can be d product of any no.
> of continuous elements.
> So if the array is 200, 5, -2, -3, -1
> den ans shd be 200*5*-2*-3 = 6000
>
> N if m workin ur algo in d right way, den it ll give 1000
>
> On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar <
> damarlakran...@gmail.com> wrote:
>
>> I think this is the solution what u need U can do in O(n) time...
>>
>>
>>> #include
 using namespace std;

 main()
 {
 int a[7] = { 0, 0, 0, 19, 380, -1, 2};
 int prod, nprod;
 bool x = false;

 for(int i=0;i<6;i++)
 {
 nprod = a[i] * a[i+1];
 cout<>>> if( x == false)
 {
 x = true;
 prod = nprod;
 }
 else if( x== true && prod < nprod )
 prod = nprod;
 }

 cout<<"\nResult: "<>>> }

>>>
>>>
>> --
>> Regards:
>> ---
>> D Kranthi kumar
>> Computer Science & Engg.
>> 1st Mtech, IIT Madras.
>>
>>  --
>> 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.
>



 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

  --
 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.
>>>
>>
>>
>>
>> --
>> Sunny Aggrawal
>> B-Tech IV year,CSI
>> Indian Institute Of Technology,Roorkee
>>
>>
>>  --
>> 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 gr

Re: [algogeeks] microsoft ques

2011-07-12 Thread Aniket Dutta
@sunny: right thanks for correcting

On Wed, Jul 13, 2011 at 11:33 AM, sunny agrawal wrote:

> @Aniket Dutta
> Solution for your case will be 96
>
> Algorithm Posted by Oppilas will do and is O(n).
>
>
> On Wed, Jul 13, 2011 at 11:28 AM, Aniket Dutta wrote:
>
>> @vaibhav: Sir ur algo fails in this array {2,-8,-3,1,2} it should give
>> answer as 24 but ur algo gives 2
>>
>>
>> On Wed, Jul 13, 2011 at 11:02 AM, varun pahwa 
>> wrote:
>>
>>> please ignore my previous post that solution is wrong.
>>>
>>>
>>> On Wed, Jul 13, 2011 at 11:01 AM, sameer.mut...@gmail.com <
>>> sameer.mut...@gmail.com> wrote:
>>>
 @kranthi :

 d solution u ve given is only for 2 continuous elements..
 wr as d question doesnt limit it to 2.. It can be d product of any no.
 of continuous elements.
 So if the array is 200, 5, -2, -3, -1
 den ans shd be 200*5*-2*-3 = 6000

 N if m workin ur algo in d right way, den it ll give 1000

 On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar <
 damarlakran...@gmail.com> wrote:

> I think this is the solution what u need U can do in O(n) time...
>
>
>> #include
>>> using namespace std;
>>>
>>> main()
>>> {
>>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>>> int prod, nprod;
>>> bool x = false;
>>>
>>> for(int i=0;i<6;i++)
>>> {
>>> nprod = a[i] * a[i+1];
>>> cout<>> if( x == false)
>>> {
>>> x = true;
>>> prod = nprod;
>>> }
>>> else if( x== true && prod < nprod )
>>> prod = nprod;
>>> }
>>>
>>> cout<<"\nResult: "<>> }
>>>
>>
>>
> --
> Regards:
> ---
> D Kranthi kumar
> Computer Science & Engg.
> 1st Mtech, IIT Madras.
>
>  --
> 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.

>>>
>>>
>>>
>>> --
>>> Varun Pahwa
>>> B.Tech (IT)
>>> 7th Sem.
>>> Indian Institute of Information Technology Allahabad.
>>> Ph : 09793899112
>>> Official Email :: rit2008...@iiita.ac.in
>>> Another Email :: varunpahwa.ii...@gmail.com
>>>
>>> People who fail to plan are those who plan to fail.
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Sunny Aggrawal
> B-Tech IV year,CSI
> Indian Institute Of Technology,Roorkee
>
>
>  --
> 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] microsoft ques

2011-07-12 Thread sunny agrawal
@Aniket Dutta
Solution for your case will be 96

Algorithm Posted by Oppilas will do and is O(n).

On Wed, Jul 13, 2011 at 11:28 AM, Aniket Dutta wrote:

> @vaibhav: Sir ur algo fails in this array {2,-8,-3,1,2} it should give
> answer as 24 but ur algo gives 2
>
>
> On Wed, Jul 13, 2011 at 11:02 AM, varun pahwa wrote:
>
>> please ignore my previous post that solution is wrong.
>>
>>
>> On Wed, Jul 13, 2011 at 11:01 AM, sameer.mut...@gmail.com <
>> sameer.mut...@gmail.com> wrote:
>>
>>> @kranthi :
>>>
>>> d solution u ve given is only for 2 continuous elements..
>>> wr as d question doesnt limit it to 2.. It can be d product of any no. of
>>> continuous elements.
>>> So if the array is 200, 5, -2, -3, -1
>>> den ans shd be 200*5*-2*-3 = 6000
>>>
>>> N if m workin ur algo in d right way, den it ll give 1000
>>>
>>> On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar <
>>> damarlakran...@gmail.com> wrote:
>>>
 I think this is the solution what u need U can do in O(n) time...


> #include
>> using namespace std;
>>
>> main()
>> {
>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>> int prod, nprod;
>> bool x = false;
>>
>> for(int i=0;i<6;i++)
>> {
>> nprod = a[i] * a[i+1];
>> cout<> if( x == false)
>> {
>> x = true;
>> prod = nprod;
>> }
>> else if( x== true && prod < nprod )
>> prod = nprod;
>> }
>>
>> cout<<"\nResult: "<> }
>>
>
>
 --
 Regards:
 ---
 D Kranthi kumar
 Computer Science & Engg.
 1st Mtech, IIT Madras.

  --
 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.
>>>
>>
>>
>>
>> --
>> Varun Pahwa
>> B.Tech (IT)
>> 7th Sem.
>> Indian Institute of Information Technology Allahabad.
>> Ph : 09793899112
>> Official Email :: rit2008...@iiita.ac.in
>> Another Email :: varunpahwa.ii...@gmail.com
>>
>> People who fail to plan are those who plan to fail.
>>
>>  --
>> 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.
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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] microsoft ques

2011-07-12 Thread Aniket Dutta
@vaibhav: Sir ur algo fails in this array {2,-8,-3,1,2} it should give
answer as 24 but ur algo gives 2

On Wed, Jul 13, 2011 at 11:02 AM, varun pahwa wrote:

> please ignore my previous post that solution is wrong.
>
>
> On Wed, Jul 13, 2011 at 11:01 AM, sameer.mut...@gmail.com <
> sameer.mut...@gmail.com> wrote:
>
>> @kranthi :
>>
>> d solution u ve given is only for 2 continuous elements..
>> wr as d question doesnt limit it to 2.. It can be d product of any no. of
>> continuous elements.
>> So if the array is 200, 5, -2, -3, -1
>> den ans shd be 200*5*-2*-3 = 6000
>>
>> N if m workin ur algo in d right way, den it ll give 1000
>>
>> On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar > > wrote:
>>
>>> I think this is the solution what u need U can do in O(n) time...
>>>
>>>
 #include
> using namespace std;
>
> main()
> {
> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
> int prod, nprod;
> bool x = false;
>
> for(int i=0;i<6;i++)
> {
> nprod = a[i] * a[i+1];
> cout< if( x == false)
> {
> x = true;
> prod = nprod;
> }
> else if( x== true && prod < nprod )
> prod = nprod;
> }
>
> cout<<"\nResult: "< }
>


>>> --
>>> Regards:
>>> ---
>>> D Kranthi kumar
>>> Computer Science & Engg.
>>> 1st Mtech, IIT Madras.
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Varun Pahwa
> B.Tech (IT)
> 7th Sem.
> Indian Institute of Information Technology Allahabad.
> Ph : 09793899112
> Official Email :: rit2008...@iiita.ac.in
> Another Email :: varunpahwa.ii...@gmail.com
>
> People who fail to plan are those who plan to fail.
>
>  --
> 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] abhijeet srivastva wants to chat

2011-07-12 Thread abhijeet srivastva
---

abhijeet srivastva wants to stay in better touch using some of
Google's coolest new
products.

If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-ea8204aae5-d200b47ece-iFsSd2VFB_j4ZSaiAvTdRcCSgDo
You'll need to click this link to be able to chat with abhijeet srivastva.

To get Gmail - a free email account from Google with over 2,800 megabytes of
storage - and chat with abhijeet srivastva, visit:
http://mail.google.com/mail/a-ea8204aae5-d200b47ece-iFsSd2VFB_j4ZSaiAvTdRcCSgDo

Gmail offers:
- Instant messaging right inside Gmail
- Powerful spam protection
- Built-in search for finding your messages and a helpful way of organizing
  emails into "conversations"
- No pop-up ads or untargeted banners - just text ads and related information
  that are relevant to the content of your messages

All this, and its yours for free. But wait, there's more! By opening a Gmail
account, you also get access to Google Talk, Google's instant messaging
service:

http://www.google.com/talk/

Google Talk offers:
- Web-based chat that you can use anywhere, without a download
- A contact list that's synchronized with your Gmail account
- Free, high quality PC-to-PC voice calls when you download the Google Talk
  client

We're working hard to add new features and make improvements, so we might also
ask for your comments and suggestions periodically. We appreciate your help in
making our products even better!

Thanks,
The Google Team

To learn more about Gmail and Google Talk, visit:
http://mail.google.com/mail/help/about.html
http://www.google.com/talk/about.html

(If clicking the URLs in this message does not work, copy and paste them into
the address bar of your browser).

-- 
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: questions related to C

2011-07-12 Thread Neeraj Gupta
http://www.cplusplus.com/reference/algorithm/swap/

On Wed, Jul 13, 2011 at 10:40 AM, Aniket Dutta wrote:

> what about a generic swap function which works for structures also?
>
>
> On Wed, Jul 13, 2011 at 2:23 AM, Don  wrote:
>
>> To check for overflow, use condition:
>>
>> if (b > (maxuint-a))
>>  return error;
>>
>> Where maxuint is the largest value which can be stored in an unsigned
>> integer.
>>
>> Don
>>
>> On Jul 8, 5:50 am, vikas  wrote:
>> > Q1 - write a generic macro to swap two values (int,float,double,pointers
>> as
>> > well )
>> >
>> > Q2 - Implement your own malloc() and  free() function
>> >
>> > Q3 - Two unsigned ints given a, b you have add these numbers and
>> return
>> > the sum ...Make sure in case of overflow return "error".
>>
>> --
>> 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] abhijeet srivastva wants to chat

2011-07-12 Thread abhijeet srivastva
---

abhijeet srivastva wants to stay in better touch using some of
Google's coolest new
products.

If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-ea8204aae5-4268d417bd-QkyG9UmU5baWrXZ2Wx-CaufDCSM
You'll need to click this link to be able to chat with abhijeet srivastva.

To get Gmail - a free email account from Google with over 2,800 megabytes of
storage - and chat with abhijeet srivastva, visit:
http://mail.google.com/mail/a-ea8204aae5-4268d417bd-QkyG9UmU5baWrXZ2Wx-CaufDCSM

Gmail offers:
- Instant messaging right inside Gmail
- Powerful spam protection
- Built-in search for finding your messages and a helpful way of organizing
  emails into "conversations"
- No pop-up ads or untargeted banners - just text ads and related information
  that are relevant to the content of your messages

All this, and its yours for free. But wait, there's more! By opening a Gmail
account, you also get access to Google Talk, Google's instant messaging
service:

http://www.google.com/talk/

Google Talk offers:
- Web-based chat that you can use anywhere, without a download
- A contact list that's synchronized with your Gmail account
- Free, high quality PC-to-PC voice calls when you download the Google Talk
  client

We're working hard to add new features and make improvements, so we might also
ask for your comments and suggestions periodically. We appreciate your help in
making our products even better!

Thanks,
The Google Team

To learn more about Gmail and Google Talk, visit:
http://mail.google.com/mail/help/about.html
http://www.google.com/talk/about.html

(If clicking the URLs in this message does not work, copy and paste them into
the address bar of your browser).

-- 
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: questions related to C

2011-07-12 Thread Sandeep Jain
Try it. It should work fine.


Regards,
Sandeep Jain



On Wed, Jul 13, 2011 at 10:40 AM, Aniket Dutta wrote:

> what about a generic swap function which works for structures also?
>
>
> On Wed, Jul 13, 2011 at 2:23 AM, Don  wrote:
>
>> To check for overflow, use condition:
>>
>> if (b > (maxuint-a))
>>  return error;
>>
>> Where maxuint is the largest value which can be stored in an unsigned
>> integer.
>>
>> Don
>>
>> On Jul 8, 5:50 am, vikas  wrote:
>> > Q1 - write a generic macro to swap two values (int,float,double,pointers
>> as
>> > well )
>> >
>> > Q2 - Implement your own malloc() and  free() function
>> >
>> > Q3 - Two unsigned ints given a, b you have add these numbers and
>> return
>> > the sum ...Make sure in case of overflow return "error".
>>
>> --
>> 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] microsoft ques

2011-07-12 Thread varun pahwa
please ignore my previous post that solution is wrong.

On Wed, Jul 13, 2011 at 11:01 AM, sameer.mut...@gmail.com <
sameer.mut...@gmail.com> wrote:

> @kranthi :
>
> d solution u ve given is only for 2 continuous elements..
> wr as d question doesnt limit it to 2.. It can be d product of any no. of
> continuous elements.
> So if the array is 200, 5, -2, -3, -1
> den ans shd be 200*5*-2*-3 = 6000
>
> N if m workin ur algo in d right way, den it ll give 1000
>
> On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar 
> wrote:
>
>> I think this is the solution what u need U can do in O(n) time...
>>
>>
>>> #include
 using namespace std;

 main()
 {
 int a[7] = { 0, 0, 0, 19, 380, -1, 2};
 int prod, nprod;
 bool x = false;

 for(int i=0;i<6;i++)
 {
 nprod = a[i] * a[i+1];
 cout<>>> if( x == false)
 {
 x = true;
 prod = nprod;
 }
 else if( x== true && prod < nprod )
 prod = nprod;
 }

 cout<<"\nResult: "<>>> }

>>>
>>>
>> --
>> Regards:
>> ---
>> D Kranthi kumar
>> Computer Science & Engg.
>> 1st Mtech, IIT Madras.
>>
>>  --
>> 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.
>



-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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] Minimum/Maximum Sum path in A Binary Tree

2011-07-12 Thread rajeev bharshetty
Traverse the tree along all possible paths in the tree and calculate sum
along all possible ways and store that in an array , and then find out the
max and min value in the array >

On Wed, Jul 13, 2011 at 7:32 AM, Rajeev Kumar wrote:

> I want to find the maximum or minimum sum path in binary tree(*not BST*)?
> any one have idea?
>
> --
> Thank You
> Rajeev Kumar
>
> --
> 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
Rajeev N B 

-- 
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] microsoft ques

2011-07-12 Thread varun pahwa
#include 

int main()
{
int n = 7;
int a[] = {0, -10, -12, 19, 20, -1, -2};
int max;
int small;
int co;
int pro = 1;
int i;

i = 0;
while(i < n)
{
while(i < n && a[i] == 0)
i++;
max = 1;
co = 0;
small = 2147483647;
while(i < n && a[i] != 0)
{
if(a[i] < 0)
{
co++;
if(small > (-a[i]))
small = -a[i];
}
max *= a[i];
i++;
}
if(co & 1)
max = (-max) / small;
if(pro < max)
pro = max;
}
printf("%d ",pro);
return 0;
}


On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar wrote:

> I think this is the solution what u need U can do in O(n) time...
>
>
>> #include
>>> using namespace std;
>>>
>>> main()
>>> {
>>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>>> int prod, nprod;
>>> bool x = false;
>>>
>>> for(int i=0;i<6;i++)
>>> {
>>> nprod = a[i] * a[i+1];
>>> cout<>> if( x == false)
>>> {
>>> x = true;
>>> prod = nprod;
>>> }
>>> else if( x== true && prod < nprod )
>>> prod = nprod;
>>> }
>>>
>>> cout<<"\nResult: "<>> }
>>>
>>
>>
> --
> Regards:
> ---
> D Kranthi kumar
> Computer Science & Engg.
> 1st Mtech, IIT Madras.
>
>  --
> 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.
>



-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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] microsoft ques

2011-07-12 Thread sameer.mut...@gmail.com
@kranthi :

d solution u ve given is only for 2 continuous elements..
wr as d question doesnt limit it to 2.. It can be d product of any no. of
continuous elements.
So if the array is 200, 5, -2, -3, -1
den ans shd be 200*5*-2*-3 = 6000

N if m workin ur algo in d right way, den it ll give 1000

On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar wrote:

> I think this is the solution what u need U can do in O(n) time...
>
>
>> #include
>>> using namespace std;
>>>
>>> main()
>>> {
>>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>>> int prod, nprod;
>>> bool x = false;
>>>
>>> for(int i=0;i<6;i++)
>>> {
>>> nprod = a[i] * a[i+1];
>>> cout<>> if( x == false)
>>> {
>>> x = true;
>>> prod = nprod;
>>> }
>>> else if( x== true && prod < nprod )
>>> prod = nprod;
>>> }
>>>
>>> cout<<"\nResult: "<>> }
>>>
>>
>>
> --
> Regards:
> ---
> D Kranthi kumar
> Computer Science & Engg.
> 1st Mtech, IIT Madras.
>
>  --
> 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] output

2011-07-12 Thread Sandeep Jain
*Case 1:*
x g()
{
 x b; *// Constructor*
 b.print();
 return b; *// Optimized away*
}
int main()
{
 x b; *// Constructor*
 x t=g(); *// Optimized away*
}

*Case 2:*
x g(x b) *// Copy constructor*
{

 b.print();
 return b; *// Return by value & destructor*
}
int main()
{
 x b; *// Constructor*
 x t=g(b); *// Pass by value and return by value*
}

This has to do with optimization of local objects done by the compiler.
Since in case 1 a local was to created/returned to initialize another local,
so what the compiler does is that it creates object 'b' at a memory location
where object t was to be created. (You may think of the compiler internally
using placement new)

Different compilers have different techniques of optimization.
Refer http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.10
And as per the above link this should not work on MS C++.NET



Regards,
Sandeep Jain



On Wed, Jul 13, 2011 at 10:35 AM, pawan yadav wrote:

> @rahul thanks for reply
> o/p (of 1st program) :
> constructor
> constructor
> print statement
>  destructor
>  destructor
>
>
> here copy constructor is not called ... that's why i have posted this
> program
>
> On Tue, Jul 12, 2011 at 10:42 PM, rahul  wrote:
>
>> Hi,
>>
>> In first program,it will call copy constructor once, while returning
>> object by value.
>> In 2nd program it will call copy constructor twice, once when u pass an
>> object to function by value, and 2nd time when you return an object by value
>> from function.
>>
>> Thanks.
>>
>> On Tue, Jul 12, 2011 at 11:52 PM, segfault wrote:
>>
>>> #include
>>> using namespace std;
>>> class x{
>>>  int p;
>>>  public:
>>>  x(){cout<<"constructor\n";}
>>>  x(const x &y)
>>>  {
>>>  cout<<"copy constructor\n";
>>>  }
>>>  ~x()
>>>  {
>>>  cout<<" destructor\n";
>>>  }
>>>  void print()
>>>  {
>>>  cout<<"print statement\n";
>>>  }
>>> };
>>> x g()
>>> {
>>>  x b;
>>>  b.print();
>>>  return b;
>>> }
>>> int main()
>>> {
>>>  x b;
>>>  x t=g();
>>> }
>>>
>>>
>>>
>>> #include
>>> using namespace std;
>>> class x{
>>>  int p;
>>>  public:
>>>  x(){cout<<"constructor\n";}
>>>  x(const x &y)
>>>  {
>>>  cout<<"copy constructor\n";
>>>  }
>>>  ~x()
>>>  {
>>>  cout<<" destructor\n";
>>>  }
>>>  void print()
>>>  {
>>>  cout<<"print statement\n";
>>>  }
>>> };
>>> x g(x b)
>>> {
>>>
>>>  b.print();
>>>  return b;
>>> }
>>> int main()
>>> {
>>>  x b;
>>>  x t=g(b);
>>> }
>>>
>>>
>>> why first one is not calling copy constructor in function g() while
>>> returning from it
>>> but second one is  calling copy constructor in function g() while
>>> returning from it?
>>>
>>> in both program inside g() b is local but why giving different result.
>>>
>>> bruce ackel page number:467
>>>
>>>
>>>
>>> please explain it.
>>>
>>> --
>>> 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] microsoft ques

2011-07-12 Thread kranthi kumar
I think this is the solution what u need U can do in O(n) time...


> #include
>> using namespace std;
>>
>> main()
>> {
>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>> int prod, nprod;
>> bool x = false;
>>
>> for(int i=0;i<6;i++)
>> {
>> nprod = a[i] * a[i+1];
>> cout<> if( x == false)
>> {
>> x = true;
>> prod = nprod;
>> }
>> else if( x== true && prod < nprod )
>> prod = nprod;
>> }
>>
>> cout<<"\nResult: "<> }
>>
>
>
-- 
Regards:
---
D Kranthi kumar
Computer Science & Engg.
1st Mtech, IIT Madras.

-- 
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] microsoft ques

2011-07-12 Thread vaibhav shukla
keep track of current subsequence product linearly,if product ever drops
below 0 it doesn't contribute to the max.

int get_max_product(int *p,size)
{
 int product=1;
 int i, max=0;
 for(i=0;iwrote:

> @aakash i quite confused abt ur algo can u plz give some example to explain
> it
> thanks
>
>
> On Wed, Jul 13, 2011 at 10:32 AM, shilpa gupta 
> wrote:
>
>> @nicks..if i am getting ur algo right than
>> if input array is
>> 0, -10, -12, 19, 20, -1, -2
>> than array b will be
>> 0, 0, 0, 19, 380, -1, 2
>> so ans ll b 380
>> but ans should b
>> 45600
>>
>> On Wed, Jul 13, 2011 at 10:18 AM, oppilas . wrote:
>>
>>> The O(N) solution which I can think of.
>>> We need to divide the array in subarray's with division point being 0.
>>> Now, in those sub arrays, there are two cases:
>>> First- even number of -ve numbers, then max product of that subarray will
>>> be product of all elements.
>>> If it contains odd number, then take the product of sub array and divide
>>> it with min( MOD(product from start to first- ve number),( last -ve number
>>> till end))
>>>
>>>
>>> On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta >> > wrote:
>>>
 array contain negative numbers also including natural numbers correct
 it...

 On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta >>> > wrote:

> given an array of natural numbers (+ve, 0, -ve) find the maximum
> product of continuous elements.efficient( O(nlogn) or better)solution
> is needed.
> thanks
>
> --
> 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.
>
>


 --
 shilpa gupta
 b tech 2nd year
 computer science and engineering
 mnnit 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.
>>>
>>
>>
>>
>> --
>> shilpa gupta
>> b tech 2nd year
>> computer science and engineering
>> mnnit allahabad
>>
>>
>
>
> --
> shilpa gupta
> b tech 2nd year
> computer science and engineering
> mnnit 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.
>



-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

-- 
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: questions related to C

2011-07-12 Thread Aniket Dutta
what about a generic swap function which works for structures also?

On Wed, Jul 13, 2011 at 2:23 AM, Don  wrote:

> To check for overflow, use condition:
>
> if (b > (maxuint-a))
>  return error;
>
> Where maxuint is the largest value which can be stored in an unsigned
> integer.
>
> Don
>
> On Jul 8, 5:50 am, vikas  wrote:
> > Q1 - write a generic macro to swap two values (int,float,double,pointers
> as
> > well )
> >
> > Q2 - Implement your own malloc() and  free() function
> >
> > Q3 - Two unsigned ints given a, b you have add these numbers and
> return
> > the sum ...Make sure in case of overflow return "error".
>
> --
> 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] microsoft ques

2011-07-12 Thread shilpa gupta
@aakash i quite confused abt ur algo can u plz give some example to explain
it
thanks

On Wed, Jul 13, 2011 at 10:32 AM, shilpa gupta wrote:

> @nicks..if i am getting ur algo right than
> if input array is
> 0, -10, -12, 19, 20, -1, -2
> than array b will be
> 0, 0, 0, 19, 380, -1, 2
> so ans ll b 380
> but ans should b
> 45600
>
> On Wed, Jul 13, 2011 at 10:18 AM, oppilas . wrote:
>
>> The O(N) solution which I can think of.
>> We need to divide the array in subarray's with division point being 0.
>> Now, in those sub arrays, there are two cases:
>> First- even number of -ve numbers, then max product of that subarray will
>> be product of all elements.
>> If it contains odd number, then take the product of sub array and divide
>> it with min( MOD(product from start to first- ve number),( last -ve number
>> till end))
>>
>>
>> On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta 
>> wrote:
>>
>>> array contain negative numbers also including natural numbers correct
>>> it...
>>>
>>> On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta 
>>> wrote:
>>>
 given an array of natural numbers (+ve, 0, -ve) find the maximum
 product of continuous elements.efficient( O(nlogn) or better)solution
 is needed.
 thanks

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


>>>
>>>
>>> --
>>> shilpa gupta
>>> b tech 2nd year
>>> computer science and engineering
>>> mnnit 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.
>>
>
>
>
> --
> shilpa gupta
> b tech 2nd year
> computer science and engineering
> mnnit allahabad
>
>


-- 
shilpa gupta
b tech 2nd year
computer science and engineering
mnnit 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.



Re: [algogeeks] output

2011-07-12 Thread pawan yadav
@rahul thanks for reply
o/p (of 1st program) :
constructor
constructor
print statement
 destructor
 destructor


here copy constructor is not called ... that's why i have posted this
program

On Tue, Jul 12, 2011 at 10:42 PM, rahul  wrote:

> Hi,
>
> In first program,it will call copy constructor once, while returning object
> by value.
> In 2nd program it will call copy constructor twice, once when u pass an
> object to function by value, and 2nd time when you return an object by value
> from function.
>
> Thanks.
>
> On Tue, Jul 12, 2011 at 11:52 PM, segfault wrote:
>
>> #include
>> using namespace std;
>> class x{
>>  int p;
>>  public:
>>  x(){cout<<"constructor\n";}
>>  x(const x &y)
>>  {
>>  cout<<"copy constructor\n";
>>  }
>>  ~x()
>>  {
>>  cout<<" destructor\n";
>>  }
>>  void print()
>>  {
>>  cout<<"print statement\n";
>>  }
>> };
>> x g()
>> {
>>  x b;
>>  b.print();
>>  return b;
>> }
>> int main()
>> {
>>  x b;
>>  x t=g();
>> }
>>
>>
>>
>> #include
>> using namespace std;
>> class x{
>>  int p;
>>  public:
>>  x(){cout<<"constructor\n";}
>>  x(const x &y)
>>  {
>>  cout<<"copy constructor\n";
>>  }
>>  ~x()
>>  {
>>  cout<<" destructor\n";
>>  }
>>  void print()
>>  {
>>  cout<<"print statement\n";
>>  }
>> };
>> x g(x b)
>> {
>>
>>  b.print();
>>  return b;
>> }
>> int main()
>> {
>>  x b;
>>  x t=g(b);
>> }
>>
>>
>> why first one is not calling copy constructor in function g() while
>> returning from it
>> but second one is  calling copy constructor in function g() while
>> returning from it?
>>
>> in both program inside g() b is local but why giving different result.
>>
>> bruce ackel page number:467
>>
>>
>>
>> please explain it.
>>
>> --
>> 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] microsoft ques

2011-07-12 Thread nicks
@shilpa...i derived it from maximum subsequence problemnow finding it
totally incorrectthnx for pointing it out..

On Wed, Jul 13, 2011 at 10:32 AM, shilpa gupta wrote:

> @nicks..if i am getting ur algo right than
> if input array is
> 0, -10, -12, 19, 20, -1, -2
> than array b will be
> 0, 0, 0, 19, 380, -1, 2
> so ans ll b 380
> but ans should b
> 45600
>
> On Wed, Jul 13, 2011 at 10:18 AM, oppilas . wrote:
>
>> The O(N) solution which I can think of.
>> We need to divide the array in subarray's with division point being 0.
>> Now, in those sub arrays, there are two cases:
>> First- even number of -ve numbers, then max product of that subarray will
>> be product of all elements.
>> If it contains odd number, then take the product of sub array and divide
>> it with min( MOD(product from start to first- ve number),( last -ve number
>> till end))
>>
>>
>> On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta 
>> wrote:
>>
>>> array contain negative numbers also including natural numbers correct
>>> it...
>>>
>>> On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta 
>>> wrote:
>>>
 given an array of natural numbers (+ve, 0, -ve) find the maximum
 product of continuous elements.efficient( O(nlogn) or better)solution
 is needed.
 thanks

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


>>>
>>>
>>> --
>>> shilpa gupta
>>> b tech 2nd year
>>> computer science and engineering
>>> mnnit 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.
>>
>
>
>
> --
> shilpa gupta
> b tech 2nd year
> computer science and engineering
> mnnit 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] MS Interview

2011-07-12 Thread Aniket Dutta
you can sort it using external merge sort. if ur file is greater than memory
refer henry F. korth Database System Concept

On Wed, Jul 13, 2011 at 10:26 AM, rShetty  wrote:

> Given a very big file of words, a word in each line, sort the words .
> Please provide the algorithm and explanation .
>
> --
> 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] MS Interview

2011-07-12 Thread saurabh singh
maintain a key.Associate with each word a key.When comparing the string,if
string1>string2 swap the keys instead of the words.Saves enormous time.

On Wed, Jul 13, 2011 at 10:32 AM, nicks  wrote:

> Algorithm along with code is explained very well in K&R refer page 108
>  ;)
>
>
> On Wed, Jul 13, 2011 at 10:26 AM, rShetty  wrote:
>
>> Given a very big file of words, a word in each line, sort the words .
>> Please provide the algorithm and explanation .
>>
>> --
>> 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.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



Re: [algogeeks] MS Interview

2011-07-12 Thread nicks
Algorithm along with code is explained very well in K&R refer page 108;)

On Wed, Jul 13, 2011 at 10:26 AM, rShetty  wrote:

> Given a very big file of words, a word in each line, sort the words .
> Please provide the algorithm and explanation .
>
> --
> 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] microsoft ques

2011-07-12 Thread shilpa gupta
@nicks..if i am getting ur algo right than
if input array is
0, -10, -12, 19, 20, -1, -2
than array b will be
0, 0, 0, 19, 380, -1, 2
so ans ll b 380
but ans should b
45600
On Wed, Jul 13, 2011 at 10:18 AM, oppilas . wrote:

> The O(N) solution which I can think of.
> We need to divide the array in subarray's with division point being 0.
> Now, in those sub arrays, there are two cases:
> First- even number of -ve numbers, then max product of that subarray will
> be product of all elements.
> If it contains odd number, then take the product of sub array and divide it
> with min( MOD(product from start to first- ve number),( last -ve number till
> end))
>
>
> On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta 
> wrote:
>
>> array contain negative numbers also including natural numbers correct
>> it...
>>
>> On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta 
>> wrote:
>>
>>> given an array of natural numbers (+ve, 0, -ve) find the maximum
>>> product of continuous elements.efficient( O(nlogn) or better)solution
>>> is needed.
>>> thanks
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>> --
>> shilpa gupta
>> b tech 2nd year
>> computer science and engineering
>> mnnit 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.
>



-- 
shilpa gupta
b tech 2nd year
computer science and engineering
mnnit 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.



[algogeeks] MS Interview

2011-07-12 Thread rShetty
Given a very big file of words, a word in each line, sort the words .
Please provide the algorithm and explanation .

-- 
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] microsoft ques

2011-07-12 Thread oppilas .
The O(N) solution which I can think of.
We need to divide the array in subarray's with division point being 0.
Now, in those sub arrays, there are two cases:
First- even number of -ve numbers, then max product of that subarray will be
product of all elements.
If it contains odd number, then take the product of sub array and divide it
with min( MOD(product from start to first- ve number),( last -ve number till
end))


On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta wrote:

> array contain negative numbers also including natural numbers correct it...
>
>
> On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta wrote:
>
>> given an array of natural numbers (+ve, 0, -ve) find the maximum
>> product of continuous elements.efficient( O(nlogn) or better)solution
>> is needed.
>> thanks
>>
>> --
>> 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.
>>
>>
>
>
> --
> shilpa gupta
> b tech 2nd year
> computer science and engineering
> mnnit 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] microsoft ques

2011-07-12 Thread nicks
i can think of a O(n) solution for this problem..though i am using extra
space O(n)

take an extra array array b[] apart from given array a[]
where b[i] denotes the maximum product of continuous ending at i

b[0]=a[0]
traverse the given array a[] and update b[] according as -
if(b[i-1]==0)
{
   if(a[i]<=0)
 b[i]=0;
   else
 b[i]=a[i];
}
if(b[i-1] > 0)
{
 if(a[i]>0)
  b[i]=a[i]*b[i-1];
 else
   b[i]=a[i];
}
if(b[i-1]<0)
{
   if(a[i]<0)
   b[i]=a[i]*b[i-1];
   else
   b[i]=a[i];
}

after this traverse the array b[] in O(n) to find the maximum product.



On Wed, Jul 13, 2011 at 10:11 AM, Aakash Johari wrote:

> Just take 2 arrays. MinArr, MaxArr. Where MinArr[i] is Minimum product so
> far. and MaxArr[i] is Max Product so far.
>
> For any position i,
> get MaxArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]);
> get MinArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]);
>
> you will have to take care, when first element is negative. For that, make
> MaxArr[0] = 1.
> and if positive, take MinArr[0] = 1;
>
> and when you strike with a zero, do similar things.
>
>
>
> On Tue, Jul 12, 2011 at 9:13 PM, shilpa gupta wrote:
>
>> given an array of natural numbers (+ve, 0, -ve) find the maximum
>> product of continuous elements.efficient( O(nlogn) or better)solution
>> is needed.
>> thanks
>>
>> --
>> 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.
>>
>>
>
>
> --
> -Aakash Johari
> (IIIT 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] microsoft ques

2011-07-12 Thread Aakash Johari
Just take 2 arrays. MinArr, MaxArr. Where MinArr[i] is Minimum product so
far. and MaxArr[i] is Max Product so far.

For any position i,
get MaxArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]);
get MinArr[i] = max(A[i] * MaxArr[i], A[i] * MinArr[i]);

you will have to take care, when first element is negative. For that, make
MaxArr[0] = 1.
and if positive, take MinArr[0] = 1;

and when you strike with a zero, do similar things.


On Tue, Jul 12, 2011 at 9:13 PM, shilpa gupta wrote:

> given an array of natural numbers (+ve, 0, -ve) find the maximum
> product of continuous elements.efficient( O(nlogn) or better)solution
> is needed.
> thanks
>
> --
> 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.
>
>


-- 
-Aakash Johari
(IIIT 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.



Re: [algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
array contain negative numbers also including natural numbers correct it...

On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta wrote:

> given an array of natural numbers (+ve, 0, -ve) find the maximum
> product of continuous elements.efficient( O(nlogn) or better)solution
> is needed.
> thanks
>
> --
> 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.
>
>


-- 
shilpa gupta
b tech 2nd year
computer science and engineering
mnnit 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.



Re: [algogeeks] microsoft ques

2011-07-12 Thread saurabh singh
it puts back the read character from a buffer back to the buffer.it ensures
that I do not break the sequence of stream,just a defensive strategy.
On Wed, Jul 13, 2011 at 9:04 AM, nicks  wrote:

> @saurabh.nice code very well writtencan u plz explain the use of
> ungetc in your code
>
> On Wed, Jul 13, 2011 at 7:10 AM, saurabh singh wrote:
>
>> Phew I think all cases covered to the best of my knowledge.
>> http://www.ideone.com/xHOQ9
>>  Few that remain include cases like '\'' "\"
>> appear in the source code.can be fixed easily.
>> Also not counting quoted and array initialization {} pairs as depth.
>> Counting the main body as depth level 1.
>>
>>
>>
>> PS:I have not tested it extensively so quite possible few bugs remained
>> unattended.Apologies in that case
>> --
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT 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.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



[algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
given an array of natural numbers (+ve, 0, -ve) find the maximum
product of continuous elements.efficient( O(nlogn) or better)solution
is needed.
thanks

-- 
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: Reversing the order of words in String

2011-07-12 Thread nicks
@saurabh why are you reading the string character by character..why
don't just read it word by word ? . what's the problem in it ?

btw...nice soln...


On Wed, Jul 13, 2011 at 7:32 AM, Gene  wrote:

> You can recognize a word W, recur to print the rest of the words in
> reverse, then print W:
>
> #include 
> #include 
>
> void print_words_in_reverse(char *s)
> {
>  char *e;
>  while (isspace(*s)) s++;
>  if (*s == '\0') return;
>  e = s + 1;
>  while (*e && !isspace(*e)) e++;
>  print_words_in_reverse(e);
>  printf("%.*s ", e - s, s);
> }
>
> int main(void)
> {
>  char line[16 * 1024];
>  fgets(line, sizeof line, stdin);
>  print_words_in_reverse(line);
>  return 0;
> }
>
>
> On Jul 6, 12:40 pm, Tushar Bindal  wrote:
> > good job
> > but how can this be done in one traversal as asked on the Adobe Interview
> > Questions thread<
> https://groups.google.com/forum/#%21msg/algogeeks/oEL8z4wwMJY/FAVdr2M...>
> > .
> >
> >
> >
> >
> >
> > On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta 
> wrote:
> > > I think somebody on this thread has asked this question but i am not
> > > able to find that.
> >
> > > Question was if a string is like "my name is ram", then output should
> > > be "ram is name my".
> >
> > > Wrote the code for same, so sharing.
> >
> > > #include
> > > #include
> > > using namespace std;
> >
> > > void SwapStringChars(string &str, int pos1, int pos2)
> > > {
> > >char ch = str[pos1];
> > >str[pos1] = str[pos2];
> > >str[pos2] = ch;
> > > }
> >
> > > void reverseString(string &str, int left, int right)
> > > {
> > >for(int i = left ; i <= left + (right-left)/2 ; i++)
> > >SwapStringChars(str, i, right + left -i));
> > > }
> >
> > > void reverseWordsInString(string &str)
> > > {
> > >char space = ' ';
> > >int len = str.length();
> > >int startIndex = 0, endIndex = 0;
> > >while(endIndex < len - 1)
> > >{
> > >while(str[endIndex] != space && endIndex <
> len)endIndex++;
> > >reverseString(str, startIndex, endIndex-1);
> > >startIndex = endIndex;
> > >while(str[startIndex] == space)startIndex++;
> > >endIndex = startIndex;
> > >}
> > > }
> >
> > > int main()
> > > {
> > >string str;
> > >cout<<"\nEnter enter the string :";
> > >getline(cin,str);
> >
> > >//Reverse whole string at once
> > >reverseString(str, 0, str.length() - 1);
> >
> > >//Reverse Individual words in string
> > >reverseWordsInString(str);
> > >cout< > >cin.get();
> > >return 0;
> > > }
> >
> > > --
> > > Regards,
> > > Navneet
> >
> > > --
> > > 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.
> >
> > --
> > Tushar Bindal
> > Computer Engineering
> > Delhi College of Engineering
> > Mob: +919818442705
> > E-Mail : tushicom...@gmail.com
> > Website:www.jugadengg.com- 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 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] microsoft ques

2011-07-12 Thread nicks
@saurabh.nice code very well writtencan u plz explain the use of
ungetc in your code

On Wed, Jul 13, 2011 at 7:10 AM, saurabh singh  wrote:

> Phew I think all cases covered to the best of my knowledge.
> http://www.ideone.com/xHOQ9
> Few that remain include cases like '\'' "\"
> appear in the source code.can be fixed easily.
> Also not counting quoted and array initialization {} pairs as depth.
> Counting the main body as depth level 1.
>
>
>
> PS:I have not tested it extensively so quite possible few bugs remained
> unattended.Apologies in that case
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT 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] output

2011-07-12 Thread rahul
Hi,

In first program,it will call copy constructor once, while returning object
by value.
In 2nd program it will call copy constructor twice, once when u pass an
object to function by value, and 2nd time when you return an object by value
from function.

Thanks.

On Tue, Jul 12, 2011 at 11:52 PM, segfault  wrote:

> #include
> using namespace std;
> class x{
>  int p;
>  public:
>  x(){cout<<"constructor\n";}
>  x(const x &y)
>  {
>  cout<<"copy constructor\n";
>  }
>  ~x()
>  {
>  cout<<" destructor\n";
>  }
>  void print()
>  {
>  cout<<"print statement\n";
>  }
> };
> x g()
> {
>  x b;
>  b.print();
>  return b;
> }
> int main()
> {
>  x b;
>  x t=g();
> }
>
>
>
> #include
> using namespace std;
> class x{
>  int p;
>  public:
>  x(){cout<<"constructor\n";}
>  x(const x &y)
>  {
>  cout<<"copy constructor\n";
>  }
>  ~x()
>  {
>  cout<<" destructor\n";
>  }
>  void print()
>  {
>  cout<<"print statement\n";
>  }
> };
> x g(x b)
> {
>
>  b.print();
>  return b;
> }
> int main()
> {
>  x b;
>  x t=g(b);
> }
>
>
> why first one is not calling copy constructor in function g() while
> returning from it
> but second one is  calling copy constructor in function g() while
> returning from it?
>
> in both program inside g() b is local but why giving different result.
>
> bruce ackel page number:467
>
>
>
> please explain it.
>
> --
> 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] Re: Reversing the order of words in String

2011-07-12 Thread Gene
You can recognize a word W, recur to print the rest of the words in
reverse, then print W:

#include 
#include 

void print_words_in_reverse(char *s)
{
  char *e;
  while (isspace(*s)) s++;
  if (*s == '\0') return;
  e = s + 1;
  while (*e && !isspace(*e)) e++;
  print_words_in_reverse(e);
  printf("%.*s ", e - s, s);
}

int main(void)
{
  char line[16 * 1024];
  fgets(line, sizeof line, stdin);
  print_words_in_reverse(line);
  return 0;
}


On Jul 6, 12:40 pm, Tushar Bindal  wrote:
> good job
> but how can this be done in one traversal as asked on the Adobe Interview
> Questions 
> thread
> .
>
>
>
>
>
> On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta  wrote:
> > I think somebody on this thread has asked this question but i am not
> > able to find that.
>
> > Question was if a string is like "my name is ram", then output should
> > be "ram is name my".
>
> > Wrote the code for same, so sharing.
>
> > #include
> > #include
> > using namespace std;
>
> > void SwapStringChars(string &str, int pos1, int pos2)
> > {
> >        char ch = str[pos1];
> >        str[pos1] = str[pos2];
> >        str[pos2] = ch;
> > }
>
> > void reverseString(string &str, int left, int right)
> > {
> >        for(int i = left ; i <= left + (right-left)/2 ; i++)
> >                SwapStringChars(str, i, right + left -i));
> > }
>
> > void reverseWordsInString(string &str)
> > {
> >        char space = ' ';
> >        int len = str.length();
> >        int startIndex = 0, endIndex = 0;
> >        while(endIndex < len - 1)
> >        {
> >                while(str[endIndex] != space && endIndex < len)endIndex++;
> >                reverseString(str, startIndex, endIndex-1);
> >                startIndex = endIndex;
> >                while(str[startIndex] == space)startIndex++;
> >                endIndex = startIndex;
> >        }
> > }
>
> > int main()
> > {
> >        string str;
> >        cout<<"\nEnter enter the string :";
> >        getline(cin,str);
>
> >        //Reverse whole string at once
> >        reverseString(str, 0, str.length() - 1);
>
> >        //Reverse Individual words in string
> >        reverseWordsInString(str);
> >        cout< >        cin.get();
> >        return 0;
> > }
>
> > --
> > Regards,
> > Navneet
>
> > --
> > 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.
>
> --
> Tushar Bindal
> Computer Engineering
> Delhi College of Engineering
> Mob: +919818442705
> E-Mail : tushicom...@gmail.com
> Website:www.jugadengg.com- 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 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] Minimum/Maximum Sum path in A Binary Tree

2011-07-12 Thread Rajeev Kumar
I want to find the maximum or minimum sum path in binary tree(*not BST*)?
any one have idea?

-- 
Thank You
Rajeev Kumar

-- 
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] microsoft ques

2011-07-12 Thread saurabh singh
Phew I think all cases covered to the best of my knowledge.
http://www.ideone.com/xHOQ9
Few that remain include cases like '\'' "\"
appear in the source code.can be fixed easily.
Also not counting quoted and array initialization {} pairs as depth.
Counting the main body as depth level 1.



PS:I have not tested it extensively so quite possible few bugs remained
unattended.Apologies in that case
-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
And sorry for the late response but my original solution in my previous post
doesn't actually  required 2 traversals of the complete string.
A more clearer algo:-
1.Read original string character by character appending to another
string.The string implementation can be that of the std. C++ string.
2.if space or null char encountered,push the *string(and not individual
chars) *in the stack.
3.Now if null occured.pop each string from the stack till it is empty.

This way we do o(n+m) iterations where m is the number of words in the
string.In real world scenario mhttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
@Navneet
This is my version of how delete and strlen must be working.Sorry the
presentation is not in correspondence with the style of the group.Apologies
for that,
*delete[]*
Suppose u are a compiler and u see a line like delete[] a,that will mean
that "Hey the programmer borrowed some memory from heap,he is now giving it
back,let me check with my table how much he took (My friend new must have
put it somewhere in the records).Ok done from the address of a to
a+no_of_blocks_allocated I have given back to heap and recorded it so. (2
steps).But the programmer may be greedy(and foolish) enough to use that
memory again,so I wont allow  that to happen till he makes a proper
request.So here I blacklist this memory for further access till he grants
another request for it."
So delete[] can do the work in 2 or 3 steps of assembler routine no matter
array is of 10 or 100.
Now see for *strlen*:
when the coder uses strlen he actually wants to say "Hey listen I am giving
you the beginning address of a bunch of random characters.I guarantee you
there is a bad guy with value 0 somewhere in there.Find me how many skips
you have to make from the starting address to get to that guy."
Now the poor function is left with no other option to search for that bad
guy looking in every box and counting how many times he skipped.Since he
can't make assumptions that's the only way he can obey his caller.
If you know any better way of searching for the bad guy '\0' let me know
please.



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



[algogeeks] Re: questions related to C

2011-07-12 Thread Don
To check for overflow, use condition:

if (b > (maxuint-a))
  return error;

Where maxuint is the largest value which can be stored in an unsigned
integer.

Don

On Jul 8, 5:50 am, vikas  wrote:
> Q1 - write a generic macro to swap two values (int,float,double,pointers as
> well )
>
> Q2 - Implement your own malloc() and  free() function
>
> Q3 - Two unsigned ints given a, b you have add these numbers and return
> the sum ...Make sure in case of overflow return "error".

-- 
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: questions related to C

2011-07-12 Thread hary rathor
#define SWAP(f,type)
f(type x, type y)\
{\
 type z; z=x, x=y,y=z;  \
}

swap(M_INT, int)
swap(M_FLT,float)
swap(m_double,double)

int main()
{
int p =5,q=4;
float r=5.4,s=6.9;
double v=6.5,w=6.9;
swap(p,q);
swap(r,s);
swap(v,w);

}

-- 
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] Re: swapping values in C

2011-07-12 Thread Don
To make it into valid code, break it into three operations:

void swap(int *a, int *b)
{
  *a ^= *b;
  *b ^= *a;
  *a ^= *b;
}

On Jul 12, 3:25 pm, Dave  wrote:
> @Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence
> point rule, which says that results are undefined if a variable is
> assigned more than one value between sequence points.
>
> Dave
>
> On Jul 12, 3:15 pm, tendua <6fae1ce6347...@gmail.com> wrote:
>
> > # include 
>
> > void swap(int *a, int *b)
> >         {
> >         *a ^= *b ^= *a ^= *b;
> >         }
>
> > int main()
> >         {
> >         int a=45, b= 56;
> > //      a ^= b ^= a ^= b;
> >         swap(&a,&b);
> >         printf("%d %d",a,b);
> >         }
>
> > This code gives output 0, 45
> > While if we uncomment the line in main function and don't use swap
> > function, we get correct value. Explain why the same line when used in
> > swap function gives such output.
>
>

-- 
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] Re: questions related to C

2011-07-12 Thread Dave
@Tendura: This violates the sequence point rule. Results are
undefined.

Dave

On Jul 12, 2:02 pm, tendua <6fae1ce6347...@gmail.com> wrote:
> regarding question to the generic macro to swap int, float, double
>
> # define swap(a,b) ((a)^=(b)^=(a)^=(b))
>
> On Jul 12, 10:08 pm, Aniket Dutta  wrote:
>
>
>
> > c=a+b
> > then find b=c-a;
> > if this b equals previous one then ok else overflow
>
> > On 7/9/11, John Hayes  wrote:
>
> > > regarding question related to overflow
>
> > > int ovr_sum(int *sum,int a,int b)
> > > {
> > >  *sum=a+b
> > >  if(*sum<0)
> > >           return -1; //overflow
> > > else
> > >           return 0; //no problem with the sum (overflow don't occur)
> > > }
> > > On Sat, Jul 9, 2011 at 2:05 PM, John Hayes  
> > > wrote:
>
> > >> generic swap can be written as -> #define Swap(T, a, b) {T temp = a; a=b;
> > >> b=temp;}
>
> > >> this is working fine in gcc
>
> > >> On Sat, Jul 9, 2011 at 1:45 PM, saurabh singh  
> > >> wrote:
>
> > >>> #include
> > >>> #include
> > >>> #include
> > >>> #include
> > >>> void swap(void *p1,void *p2,const unsigned size)
> > >>> {
> > >>>  char *buff=(char*) malloc(size*sizeof(char));
> > >>> if(!buff)
> > >>> {
> > >>>  perror("malloc");
> > >>> exit(11);
> > >>> }
> > >>>  memcpy(buff,p1,size);
> > >>> memcpy(p1,p2,size);
> > >>> memcpy(p2,buff,size);
> > >>>  free(buff);
> > >>> return;
> > >>> }
> > >>> int main()
> > >>> {
> > >>> int a=12,b=24;
> > >>> char c='a',d='b';
> > >>>  float e=1.1f,f=2.3f;
> > >>> char wrd1[]="Hello";
> > >>> char wrd2[]="Bye";
> > >>>  char *p=wrd1;
> > >>> char *q=wrd2;
> > >>> swap(&a,&b,sizeof(int));
> > >>>  swap(&c,&d,sizeof(char));
> > >>> swap(&e,&f,sizeof(float));
> > >>> swap(&p,&q,sizeof(p));
> > >>>  printf("%d\t%d\n",a,b);
> > >>> printf("%c\t%c\n",c,d);
> > >>> printf("%f\t%f\n",e,f);
> > >>>  printf("%s\t%s\n",p,q);
> > >>> return 0;
> > >>> }
> > >>>  Its a generic function not a macro, I know but the idea would be same.
>
> > >>> --
> > >>> Saurabh Singh
> > >>> B.Tech (Computer Science)
> > >>> MNNIT 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.- 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 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] Re: swapping values in C

2011-07-12 Thread Dave
@Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence
point rule, which says that results are undefined if a variable is
assigned more than one value between sequence points.

Dave

On Jul 12, 3:15 pm, tendua <6fae1ce6347...@gmail.com> wrote:
> # include 
>
> void swap(int *a, int *b)
>         {
>         *a ^= *b ^= *a ^= *b;
>         }
>
> int main()
>         {
>         int a=45, b= 56;
> //      a ^= b ^= a ^= b;
>         swap(&a,&b);
>         printf("%d %d",a,b);
>         }
>
> This code gives output 0, 45
> While if we uncomment the line in main function and don't use swap
> function, we get correct value. Explain why the same line when used in
> swap function gives such output.

-- 
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] Re: swapping values in C

2011-07-12 Thread Don
Undefined code can do whatever it wants to.
Don

On Jul 12, 3:15 pm, tendua <6fae1ce6347...@gmail.com> wrote:
> # include 
>
> void swap(int *a, int *b)
>         {
>         *a ^= *b ^= *a ^= *b;
>         }
>
> int main()
>         {
>         int a=45, b= 56;
> //      a ^= b ^= a ^= b;
>         swap(&a,&b);
>         printf("%d %d",a,b);
>         }
>
> This code gives output 0, 45
> While if we uncomment the line in main function and don't use swap
> function, we get correct value. Explain why the same line when used in
> swap function gives such output.

-- 
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] swapping values in C

2011-07-12 Thread tendua
# include 

void swap(int *a, int *b)
{
*a ^= *b ^= *a ^= *b;
}

int main()
{
int a=45, b= 56;
//  a ^= b ^= a ^= b;
swap(&a,&b);
printf("%d %d",a,b);
}

This code gives output 0, 45
While if we uncomment the line in main function and don't use swap
function, we get correct value. Explain why the same line when used in
swap function gives such output.

-- 
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: Image based Problem (Google)

2011-07-12 Thread DK
@Santosh: It depends on the type of the image. An image cannot be 
represented in a (lossy) compressed format using fourier or wavelet 
coefficients if we are to detect modifications that are at the pixel level.

For example: No compression technique will be able to compress an image with 
pixels sampled from a perfectly random source. Hence, in the worst case - we 
will have to store each and every pixel of the image. Improvements are only 
possible if we are given that such images are rare or that the data in the 
images is compressible or that we are allowed a certain degree of pixel 
error tolerance.

--
DK

http://twitter.com/divyekapoor
http://www.divye.in

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/LeY_7ttPal0J.
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] Re: questions related to C

2011-07-12 Thread tendua
regarding question to the generic macro to swap int, float, double

# define swap(a,b) ((a)^=(b)^=(a)^=(b))



On Jul 12, 10:08 pm, Aniket Dutta  wrote:
> c=a+b
> then find b=c-a;
> if this b equals previous one then ok else overflow
>
> On 7/9/11, John Hayes  wrote:
>
> > regarding question related to overflow
>
> > int ovr_sum(int *sum,int a,int b)
> > {
> >  *sum=a+b
> >  if(*sum<0)
> >           return -1; //overflow
> > else
> >           return 0; //no problem with the sum (overflow don't occur)
> > }
> > On Sat, Jul 9, 2011 at 2:05 PM, John Hayes  wrote:
>
> >> generic swap can be written as -> #define Swap(T, a, b) {T temp = a; a=b;
> >> b=temp;}
>
> >> this is working fine in gcc
>
> >> On Sat, Jul 9, 2011 at 1:45 PM, saurabh singh  wrote:
>
> >>> #include
> >>> #include
> >>> #include
> >>> #include
> >>> void swap(void *p1,void *p2,const unsigned size)
> >>> {
> >>>  char *buff=(char*) malloc(size*sizeof(char));
> >>> if(!buff)
> >>> {
> >>>  perror("malloc");
> >>> exit(11);
> >>> }
> >>>  memcpy(buff,p1,size);
> >>> memcpy(p1,p2,size);
> >>> memcpy(p2,buff,size);
> >>>  free(buff);
> >>> return;
> >>> }
> >>> int main()
> >>> {
> >>> int a=12,b=24;
> >>> char c='a',d='b';
> >>>  float e=1.1f,f=2.3f;
> >>> char wrd1[]="Hello";
> >>> char wrd2[]="Bye";
> >>>  char *p=wrd1;
> >>> char *q=wrd2;
> >>> swap(&a,&b,sizeof(int));
> >>>  swap(&c,&d,sizeof(char));
> >>> swap(&e,&f,sizeof(float));
> >>> swap(&p,&q,sizeof(p));
> >>>  printf("%d\t%d\n",a,b);
> >>> printf("%c\t%c\n",c,d);
> >>> printf("%f\t%f\n",e,f);
> >>>  printf("%s\t%s\n",p,q);
> >>> return 0;
> >>> }
> >>>  Its a generic function not a macro, I know but the idea would be same.
>
> >>> --
> >>> Saurabh Singh
> >>> B.Tech (Computer Science)
> >>> MNNIT 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.

-- 
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] output

2011-07-12 Thread segfault
#include
using namespace std;
class base
{
 public:
 virtual void fun() { cout <<"base"; }  //this is
virtual function
 void run() { fun();}
};
class der:public base // base class is
inherited
{
 public:
 void fun()
{ cout <<"derived"; }
};
int main()
{
der d;
d.run();
return 0;
}

output : derived

but when we remove virtual keyword it gives "base".
why?

i think virtual mechanism is done through only POINTER.   Is this
write?

what mechanism is happening
any link about this

-- 
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] Max Arithmetic Subsequence

2011-07-12 Thread sunny agrawal
Algorithm in the paper says works only on sorted arrays
it is mentioned in the paper itself

On Tue, Jul 12, 2011 at 11:21 PM, Navneet Gupta wrote:

> I wrote the code as someone gave the reference of the paper where algo
> to get max arithmetic subsequence was given.
>
> For an input of {2,9,4,1,6,7,8,3,10}, i am getting an output of 3,
> while it should be 5 for {2,4,6,8,10}
>
> Below is the implementation, can someone help me understand where am i
> going wrong?
>
> int LongestArithmeticSubsequence(int *a, int len)
> {
>int maxLen = 2;int i,k;
>int **L = (int **)new int[len];
>for(int m = 0; m L[m] = new int[len];
>for(int j = len - 1; j>=1;j--)
>{
>i = j-1;
>k = j+1;
>while(i>=1&&k<=len-1)
>{
>if(a[i]+a[k]<2*a[j])
>k++;
>else if(a[i]+a[k]>2*a[j])
>{
>L[i][j] = 2;
>i = i-1;
>}
>else
>{
>L[i][j] = L[j][k] + 1;
>maxLen = getMax(maxLen, L[i][j]);
>i = i-1; k = k+1;
>}
>}
>while(i>=1)
>{
>L[i][j] = 2;
>i=i-1;
>}
>}
>return maxLen;
> }
>
> --
> Regards,
> Navneet
>
> --
> 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.
>
>


-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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] output

2011-07-12 Thread segfault
#include
using namespace std;
class x{
  int p;
 public:
 x(){cout<<"constructor\n";}
 x(const x &y)
 {
  cout<<"copy constructor\n";
 }
 ~x()
 {
  cout<<" destructor\n";
 }
 void print()
 {
  cout<<"print statement\n";
 }
};
x g()
{
  x b;
  b.print();
  return b;
}
int main()
{
 x b;
 x t=g();
}



#include
using namespace std;
class x{
  int p;
 public:
 x(){cout<<"constructor\n";}
 x(const x &y)
 {
  cout<<"copy constructor\n";
 }
 ~x()
 {
  cout<<" destructor\n";
 }
 void print()
 {
  cout<<"print statement\n";
 }
};
x g(x b)
{

  b.print();
  return b;
}
int main()
{
 x b;
 x t=g(b);
}


why first one is not calling copy constructor in function g() while
returning from it
but second one is  calling copy constructor in function g() while
returning from it?

in both program inside g() b is local but why giving different result.

bruce ackel page number:467



please explain it.

-- 
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] Reversing the order of words in String

2011-07-12 Thread keyan karthi
if u do not want to update the change, a print statement below the recursive
call that prints "pos" positioned word would do.. (words can be split
searching for white spaces) this is in linear pass.. but internal
representation is push and pop only

On Tue, Jul 12, 2011 at 11:01 PM, Navneet Gupta wrote:

> My bad in not being clear. I only meant it is possible to know the
> size of strings without traversing them as compiler does that but I am
> not sure if is it possible for APIs to do the same. Compiler writes
> that size in some memory location and use it during delete []str
>
> On Tue, Jul 12, 2011 at 10:54 PM, saurabh singh 
> wrote:
> > can strlen do the same job?
> > I doubt...?
> >
> > On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta 
> > wrote:
> >>
> >> @Saurabh, just to let you know, compiler actually does that. Without
> >> traversing the array (read specifying the array size), you are able to
> >> free up all the memory being consumed by simply writing delete []a.
> >>
> >>
> >> On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh 
> >> wrote:
> >> > and how would strlen compute the length without traversing through the
> >> > array?
> >> >
> >> > On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek 
> >> > wrote:
> >> >>
> >> >> One solution can be in one traversal :-
> >> >>
> >> >> take an example:- char str[]="hello my friends"; int
> i=strlen(str),j=i;
> >> >> char *srt1=malloc(sizeof(char)*i);
> >> >> 1. start from end of string (while i>=0,i--)
> >> >> 2. whenever u find any space do
> >> >>a. strcat(srt1,&srt[i]);
> >> >>b. srt[i]='\0';
> >> >>d. srt[j-i]=''; //replacing nulls by space, can be done
> using
> >> >> strlen(srt1) also
> >> >>
> >> >> Note:- I have not executed the code so modifications may be needed.
> :)
> >> >>
> >> >> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor 
> >> >> wrote:
> >> >>>
> >> >>> char a[20];
> >> >>> int l,i,j,k;
> >> >>> int main()
> >> >>> {
> >> >>> char str[100];
> >> >>> gets(str);
> >> >>> l=strlen(str);
> >> >>> for(i=l-1;i>=0;){
> >> >>> k=19;
> >> >>> a[k]='\0';
> >> >>> while(i>=0 && str[i]!=' '){
> >> >>> a[--k]=str[i--];
> >> >>> }
> >> >>> printf("%s",a+k);
> >> >>> while(i>=0 && str[i]==' ') i--;
> >> >>> printf(" ");
> >> >>> }
> >> >>> }
> >> >>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor  >
> >> >>> wrote:
> >> 
> >>  Pls Ignore my above post..
> >> 
> >>  On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor <
> pkjee2...@gmail.com>
> >>  wrote:
> >> >
> >> > char a[20];
> >> > int l;
> >> > int main()
> >> > {
> >> >  char str[100];
> >> >  scanf("%s",str);
> >> >  l=strlen(str);
> >> >
> >> > }
> >> > --
> >> > Regards,
> >> > Piyush Kapoor,
> >> > CSE-IT-BHU
> >> 
> >> 
> >> 
> >>  --
> >>  Regards,
> >>  Piyush Kapoor,
> >>  CSE-IT-BHU
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> Regards,
> >> >>> Piyush Kapoor,
> >> >>> CSE-IT-BHU
> >> >>>
> >> >>> --
> >> >>> 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
> >> >>
> >> >> --
> >> >> 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.
> >> >
> >> >
> >> >
> >> > --
> >> > Saurabh Singh
> >> > B.Tech (Computer Science)
> >> > MNNIT 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.
> >> >
> >>
> >>
> >>
> >> --
> >> Regards,
> >> Navneet
> >>
> >> --
> >> 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] Max Arithmetic Subsequence

2011-07-12 Thread Navneet Gupta
I wrote the code as someone gave the reference of the paper where algo
to get max arithmetic subsequence was given.

For an input of {2,9,4,1,6,7,8,3,10}, i am getting an output of 3,
while it should be 5 for {2,4,6,8,10}

Below is the implementation, can someone help me understand where am i
going wrong?

int LongestArithmeticSubsequence(int *a, int len)
{
int maxLen = 2;int i,k;
int **L = (int **)new int[len];
for(int m = 0; m =1;j--)
{
i = j-1;
k = j+1;
while(i>=1&&k<=len-1)
{
if(a[i]+a[k]<2*a[j])
k++;
else if(a[i]+a[k]>2*a[j])
{
L[i][j] = 2;
i = i-1;
}
else
{
L[i][j] = L[j][k] + 1;
maxLen = getMax(maxLen, L[i][j]);
i = i-1; k = k+1;
}
}
while(i>=1)
{
L[i][j] = 2;
i=i-1;
}
}
return maxLen;
}

-- 
Regards,
Navneet

-- 
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: output

2011-07-12 Thread rahul
x const a1;
x a2;

try this.

On Tue, Jul 12, 2011 at 11:11 PM, shiv narayan wrote:

> cant i invoke both simultaneously??
> if i try to make two objects like
> x const a;
> x a;
> then it gives error..can u explain plz.
>
> On Jul 12, 9:55 pm, Sandeep Jain  wrote:
> > *const* in C++ is not exactly same as *final* in java. SO unlike java
> adding
> > the keyword const to a function does not affect overriding.
> > Infact, adding in C++ const functions ==> that they will not modify any
> > member of the class.
> > non-const functions cannot be invoked by const objects.
> >
> > Try making object 'a' as const i.e.
> > const x a;
> > and then invoke f(), it should invoke the correct version.
> >
> > Note that C++ allows function overloading based on const-ness.
> > Refer (Const function section)
> http://www.cprogramming.com/tutorial/const_correctness.html
> > Also, subscript operators generally come in pairs, Referhttp://
> www.parashift.com/c++-faq-lite/operator-overloading.html#faq-1...http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.12
> >
> > Regards,
> > Sandeep Jain
> >
> > On Tue, Jul 12, 2011 at 10:09 PM, dheeraj tyagi  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > const means that it cannot be overloaded..i think due to that this is
> > > happening.
> >
> > > On Tue, Jul 12, 2011 at 9:26 PM, segfault  >wrote:
> >
> > >> #include
> > >> using namespace std;
> > >> class x{
> > >> public:
> > >> x() {}
> >
> > >> int  func() const{
> > >> cout<<"it is const function\n";
> > >> }
> >
> > >> int func() {
> > >> cout<<"it is simple functin\n";
> > >> }
> >
> > >> };
> > >> int main()
> > >> {
> > >> x a;
> > >> a.func();
> > >> return 0;
> > >> }
> >
> > >> why cann't it take const function?
> > >> explain it
> >
> > >> --
> > >> 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
> > > Dheeraj Tyagi
> > > 8197218001
> >
> > >  --
> > > 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] Re: output

2011-07-12 Thread shiv narayan
cant i invoke both simultaneously??
if i try to make two objects like
x const a;
x a;
then it gives error..can u explain plz.

On Jul 12, 9:55 pm, Sandeep Jain  wrote:
> *const* in C++ is not exactly same as *final* in java. SO unlike java adding
> the keyword const to a function does not affect overriding.
> Infact, adding in C++ const functions ==> that they will not modify any
> member of the class.
> non-const functions cannot be invoked by const objects.
>
> Try making object 'a' as const i.e.
> const x a;
> and then invoke f(), it should invoke the correct version.
>
> Note that C++ allows function overloading based on const-ness.
> Refer (Const function 
> section)http://www.cprogramming.com/tutorial/const_correctness.html
> Also, subscript operators generally come in pairs, 
> Referhttp://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-1...http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.12
>
> Regards,
> Sandeep Jain
>
> On Tue, Jul 12, 2011 at 10:09 PM, dheeraj tyagi wrote:
>
>
>
>
>
>
>
> > const means that it cannot be overloaded..i think due to that this is
> > happening.
>
> > On Tue, Jul 12, 2011 at 9:26 PM, segfault wrote:
>
> >> #include
> >> using namespace std;
> >> class x{
> >> public:
> >> x() {}
>
> >> int  func() const{
> >> cout<<"it is const function\n";
> >> }
>
> >> int func() {
> >> cout<<"it is simple functin\n";
> >> }
>
> >> };
> >> int main()
> >> {
> >> x a;
> >> a.func();
> >> return 0;
> >> }
>
> >> why cann't it take const function?
> >> explain it
>
> >> --
> >> 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
> > Dheeraj Tyagi
> > 8197218001
>
> >  --
> > 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] output

2011-07-12 Thread rahul
@dheeraj: const member function can be called by non-constant obj.just
remove the non-constant member function...try urself.

On Tue, Jul 12, 2011 at 10:59 PM, dheeraj tyagi wrote:

> const methods can only be called by constant objects. since in this case
> the object is not constant it will call the normal method.
>
>
> On Tue, Jul 12, 2011 at 10:24 PM, Aniket Dutta wrote:
>
>> @dheeraj: but the prototypes are same. how u are calling it
>> overloading plz explain
>>
>> On 7/12/11, dheeraj tyagi  wrote:
>> > const means that it cannot be overloaded..i think due to that this is
>> > happening.
>> >
>> > On Tue, Jul 12, 2011 at 9:26 PM, segfault 
>> wrote:
>> >
>> >> #include
>> >> using namespace std;
>> >> class x{
>> >> public:
>> >> x() {}
>> >>
>> >> int  func() const{
>> >> cout<<"it is const function\n";
>> >> }
>> >>
>> >> int func() {
>> >> cout<<"it is simple functin\n";
>> >> }
>> >>
>> >>
>> >> };
>> >> int main()
>> >> {
>> >> x a;
>> >> a.func();
>> >> return 0;
>> >> }
>> >>
>> >> why cann't it take const function?
>> >> explain it
>> >>
>> >> --
>> >> 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
>> > Dheeraj Tyagi
>> > 8197218001
>> >
>> > --
>> > 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
> Dheeraj Tyagi
> 8197218001
>
>  --
> 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] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
My bad in not being clear. I only meant it is possible to know the
size of strings without traversing them as compiler does that but I am
not sure if is it possible for APIs to do the same. Compiler writes
that size in some memory location and use it during delete []str

On Tue, Jul 12, 2011 at 10:54 PM, saurabh singh  wrote:
> can strlen do the same job?
> I doubt...?
>
> On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta 
> wrote:
>>
>> @Saurabh, just to let you know, compiler actually does that. Without
>> traversing the array (read specifying the array size), you are able to
>> free up all the memory being consumed by simply writing delete []a.
>>
>>
>> On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh 
>> wrote:
>> > and how would strlen compute the length without traversing through the
>> > array?
>> >
>> > On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek 
>> > wrote:
>> >>
>> >> One solution can be in one traversal :-
>> >>
>> >> take an example:- char str[]="hello my friends"; int i=strlen(str),j=i;
>> >> char *srt1=malloc(sizeof(char)*i);
>> >> 1. start from end of string (while i>=0,i--)
>> >> 2. whenever u find any space do
>> >>    a. strcat(srt1,&srt[i]);
>> >>    b. srt[i]='\0';
>> >>    d. srt[j-i]=''; //replacing nulls by space, can be done using
>> >> strlen(srt1) also
>> >>
>> >> Note:- I have not executed the code so modifications may be needed. :)
>> >>
>> >> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor 
>> >> wrote:
>> >>>
>> >>> char a[20];
>> >>> int l,i,j,k;
>> >>> int main()
>> >>> {
>> >>>     char str[100];
>> >>>     gets(str);
>> >>>     l=strlen(str);
>> >>>     for(i=l-1;i>=0;){
>> >>>     k=19;
>> >>>     a[k]='\0';
>> >>>     while(i>=0 && str[i]!=' '){
>> >>>         a[--k]=str[i--];
>> >>>     }
>> >>>     printf("%s",a+k);
>> >>>     while(i>=0 && str[i]==' ') i--;
>> >>>     printf(" ");
>> >>>     }
>> >>> }
>> >>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor 
>> >>> wrote:
>> 
>>  Pls Ignore my above post..
>> 
>>  On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor 
>>  wrote:
>> >
>> > char a[20];
>> > int l;
>> > int main()
>> > {
>> >      char str[100];
>> >      scanf("%s",str);
>> >      l=strlen(str);
>> >
>> > }
>> > --
>> > Regards,
>> > Piyush Kapoor,
>> > CSE-IT-BHU
>> 
>> 
>> 
>>  --
>>  Regards,
>>  Piyush Kapoor,
>>  CSE-IT-BHU
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Regards,
>> >>> Piyush Kapoor,
>> >>> CSE-IT-BHU
>> >>>
>> >>> --
>> >>> 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
>> >>
>> >> --
>> >> 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.
>> >
>> >
>> >
>> > --
>> > Saurabh Singh
>> > B.Tech (Computer Science)
>> > MNNIT 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.
>> >
>>
>>
>>
>> --
>> Regards,
>> Navneet
>>
>> --
>> 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.
>>
>
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT 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.
>



-- 
Regards,
Navneet

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

Re: [algogeeks] output

2011-07-12 Thread dheeraj tyagi
const methods can only be called by constant objects. since in this case the
object is not constant it will call the normal method.

On Tue, Jul 12, 2011 at 10:24 PM, Aniket Dutta wrote:

> @dheeraj: but the prototypes are same. how u are calling it
> overloading plz explain
>
> On 7/12/11, dheeraj tyagi  wrote:
> > const means that it cannot be overloaded..i think due to that this is
> > happening.
> >
> > On Tue, Jul 12, 2011 at 9:26 PM, segfault 
> wrote:
> >
> >> #include
> >> using namespace std;
> >> class x{
> >> public:
> >> x() {}
> >>
> >> int  func() const{
> >> cout<<"it is const function\n";
> >> }
> >>
> >> int func() {
> >> cout<<"it is simple functin\n";
> >> }
> >>
> >>
> >> };
> >> int main()
> >> {
> >> x a;
> >> a.func();
> >> return 0;
> >> }
> >>
> >> why cann't it take const function?
> >> explain it
> >>
> >> --
> >> 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
> > Dheeraj Tyagi
> > 8197218001
> >
> > --
> > 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
Dheeraj Tyagi
8197218001

-- 
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] Reversing the order of words in String

2011-07-12 Thread saurabh singh
can strlen do the same job?
I doubt...?

On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta wrote:

> @Saurabh, just to let you know, compiler actually does that. Without
> traversing the array (read specifying the array size), you are able to
> free up all the memory being consumed by simply writing delete []a.
>
>
> On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh 
> wrote:
> > and how would strlen compute the length without traversing through the
> > array?
> >
> > On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek 
> wrote:
> >>
> >> One solution can be in one traversal :-
> >>
> >> take an example:- char str[]="hello my friends"; int i=strlen(str),j=i;
> >> char *srt1=malloc(sizeof(char)*i);
> >> 1. start from end of string (while i>=0,i--)
> >> 2. whenever u find any space do
> >>a. strcat(srt1,&srt[i]);
> >>b. srt[i]='\0';
> >>d. srt[j-i]=''; //replacing nulls by space, can be done using
> >> strlen(srt1) also
> >>
> >> Note:- I have not executed the code so modifications may be needed. :)
> >>
> >> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor 
> >> wrote:
> >>>
> >>> char a[20];
> >>> int l,i,j,k;
> >>> int main()
> >>> {
> >>> char str[100];
> >>> gets(str);
> >>> l=strlen(str);
> >>> for(i=l-1;i>=0;){
> >>> k=19;
> >>> a[k]='\0';
> >>> while(i>=0 && str[i]!=' '){
> >>> a[--k]=str[i--];
> >>> }
> >>> printf("%s",a+k);
> >>> while(i>=0 && str[i]==' ') i--;
> >>> printf(" ");
> >>> }
> >>> }
> >>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor 
> >>> wrote:
> 
>  Pls Ignore my above post..
> 
>  On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor 
>  wrote:
> >
> > char a[20];
> > int l;
> > int main()
> > {
> >  char str[100];
> >  scanf("%s",str);
> >  l=strlen(str);
> >
> > }
> > --
> > Regards,
> > Piyush Kapoor,
> > CSE-IT-BHU
> 
> 
> 
>  --
>  Regards,
>  Piyush Kapoor,
>  CSE-IT-BHU
> >>>
> >>>
> >>>
> >>> --
> >>> Regards,
> >>> Piyush Kapoor,
> >>> CSE-IT-BHU
> >>>
> >>> --
> >>> 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
> >>
> >> --
> >> 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.
> >
> >
> >
> > --
> > Saurabh Singh
> > B.Tech (Computer Science)
> > MNNIT 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.
> >
>
>
>
> --
> Regards,
> Navneet
>
> --
> 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.
>
>


-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
@Saurabh, just to let you know, compiler actually does that. Without
traversing the array (read specifying the array size), you are able to
free up all the memory being consumed by simply writing delete []a.


On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh  wrote:
> and how would strlen compute the length without traversing through the
> array?
>
> On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek  wrote:
>>
>> One solution can be in one traversal :-
>>
>> take an example:- char str[]="hello my friends"; int i=strlen(str),j=i;
>> char *srt1=malloc(sizeof(char)*i);
>> 1. start from end of string (while i>=0,i--)
>> 2. whenever u find any space do
>>    a. strcat(srt1,&srt[i]);
>>    b. srt[i]='\0';
>>    d. srt[j-i]=''; //replacing nulls by space, can be done using
>> strlen(srt1) also
>>
>> Note:- I have not executed the code so modifications may be needed. :)
>>
>> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor 
>> wrote:
>>>
>>> char a[20];
>>> int l,i,j,k;
>>> int main()
>>> {
>>>     char str[100];
>>>     gets(str);
>>>     l=strlen(str);
>>>     for(i=l-1;i>=0;){
>>>     k=19;
>>>     a[k]='\0';
>>>     while(i>=0 && str[i]!=' '){
>>>         a[--k]=str[i--];
>>>     }
>>>     printf("%s",a+k);
>>>     while(i>=0 && str[i]==' ') i--;
>>>     printf(" ");
>>>     }
>>> }
>>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor 
>>> wrote:

 Pls Ignore my above post..

 On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor 
 wrote:
>
> char a[20];
> int l;
> int main()
> {
>      char str[100];
>      scanf("%s",str);
>      l=strlen(str);
>
> }
> --
> Regards,
> Piyush Kapoor,
> CSE-IT-BHU



 --
 Regards,
 Piyush Kapoor,
 CSE-IT-BHU
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Piyush Kapoor,
>>> CSE-IT-BHU
>>>
>>> --
>>> 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
>>
>> --
>> 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.
>
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT 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.
>



-- 
Regards,
Navneet

-- 
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] questions related to C

2011-07-12 Thread Aniket Dutta
c=a+b
then find b=c-a;
if this b equals previous one then ok else overflow

On 7/9/11, John Hayes  wrote:
> regarding question related to overflow
>
> int ovr_sum(int *sum,int a,int b)
> {
>  *sum=a+b
>  if(*sum<0)
>   return -1; //overflow
> else
>   return 0; //no problem with the sum (overflow don't occur)
> }
> On Sat, Jul 9, 2011 at 2:05 PM, John Hayes  wrote:
>
>> generic swap can be written as -> #define Swap(T, a, b) {T temp = a; a=b;
>> b=temp;}
>>
>> this is working fine in gcc
>>
>> On Sat, Jul 9, 2011 at 1:45 PM, saurabh singh  wrote:
>>
>>> #include
>>> #include
>>> #include
>>> #include
>>> void swap(void *p1,void *p2,const unsigned size)
>>> {
>>>  char *buff=(char*) malloc(size*sizeof(char));
>>> if(!buff)
>>> {
>>>  perror("malloc");
>>> exit(11);
>>> }
>>>  memcpy(buff,p1,size);
>>> memcpy(p1,p2,size);
>>> memcpy(p2,buff,size);
>>>  free(buff);
>>> return;
>>> }
>>> int main()
>>> {
>>> int a=12,b=24;
>>> char c='a',d='b';
>>>  float e=1.1f,f=2.3f;
>>> char wrd1[]="Hello";
>>> char wrd2[]="Bye";
>>>  char *p=wrd1;
>>> char *q=wrd2;
>>> swap(&a,&b,sizeof(int));
>>>  swap(&c,&d,sizeof(char));
>>> swap(&e,&f,sizeof(float));
>>> swap(&p,&q,sizeof(p));
>>>  printf("%d\t%d\n",a,b);
>>> printf("%c\t%c\n",c,d);
>>> printf("%f\t%f\n",e,f);
>>>  printf("%s\t%s\n",p,q);
>>> return 0;
>>> }
>>>  Its a generic function not a macro, I know but the idea would be same.
>>>
>>>
>>>
>>> --
>>> Saurabh Singh
>>> B.Tech (Computer Science)
>>> MNNIT 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.
>
>

-- 
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: sbtration

2011-07-12 Thread Anika Jain
awesum :) thanx all

On Tue, Jul 12, 2011 at 8:27 PM, bittu  wrote:

> Lets Try For Decimal Integer Number how we add them
>
> 1 Add 759 + 674, but “forget” to carry I then get 323
> 2 Add 759 + 674 but only do the carrying, rather than the addition of
> each digit I then
>  get 1110
> 3 Add the result of the first two operations (recursively, using the
> same process de-
> scribed in step 1 and 2): 1110 + 323 = 1433
>
> we have done for decimal numbers
>
> Now, how would we do this in binary?
>
> 1 If I add two binary numbers together but forget to carry, bit[i]
> will be 0 if bit[i] in a and
> b are both 0 or both 1 This is an XOR
> 2 If I add two numbers together but only carry, I will have a 1 in
> bit[i] if bit[i-1] in a and b
> are both 1’s This is an AND, shifted
>
> 3 Now, recurse until there’s nothing to carry
>
> int add_no_arithm(int a, int b)
> {
> if (b == 0) return a;
> int sum = a ^ b; // add without carrying
> int carry = (a & b) << 1; // carry, but don’t add return
> add_no_arithm(sum, carry); // recurse
> }
>
> Subtraction uses add function internally as well as we have adder !!!
>
> int sub(int x, int y)
> {
>   return(add(x,add(~y,1));
>
> }
>
> Thanks
> Shashank Mani
> Computer Science
> Birla Institute of Technology Mesra
>
> --
> 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] output

2011-07-12 Thread Aniket Dutta
@sandeep sir: thanx sir for clearing doubt

On 7/12/11, Sandeep Jain  wrote:
> *const* in C++ is not exactly same as *final* in java. SO unlike java adding
> the keyword const to a function does not affect overriding.
> Infact, adding in C++ const functions ==> that they will not modify any
> member of the class.
> non-const functions cannot be invoked by const objects.
>
> Try making object 'a' as const i.e.
> const x a;
> and then invoke f(), it should invoke the correct version.
>
> Note that C++ allows function overloading based on const-ness.
> Refer (Const function section)
> http://www.cprogramming.com/tutorial/const_correctness.html
> Also, subscript operators generally come in pairs, Refer
> http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
> http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.12
>
>
> Regards,
> Sandeep Jain
>
>
>
> On Tue, Jul 12, 2011 at 10:09 PM, dheeraj tyagi
> wrote:
>
>> const means that it cannot be overloaded..i think due to that this is
>> happening.
>>
>>
>> On Tue, Jul 12, 2011 at 9:26 PM, segfault wrote:
>>
>>> #include
>>> using namespace std;
>>> class x{
>>> public:
>>> x() {}
>>>
>>> int  func() const{
>>> cout<<"it is const function\n";
>>> }
>>>
>>> int func() {
>>> cout<<"it is simple functin\n";
>>> }
>>>
>>>
>>> };
>>> int main()
>>> {
>>> x a;
>>> a.func();
>>> return 0;
>>> }
>>>
>>> why cann't it take const function?
>>> explain it
>>>
>>> --
>>> 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
>> Dheeraj Tyagi
>> 8197218001
>>
>>
>>  --
>> 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] output

2011-07-12 Thread Sandeep Jain
*const* in C++ is not exactly same as *final* in java. SO unlike java adding
the keyword const to a function does not affect overriding.
Infact, adding in C++ const functions ==> that they will not modify any
member of the class.
non-const functions cannot be invoked by const objects.

Try making object 'a' as const i.e.
const x a;
and then invoke f(), it should invoke the correct version.

Note that C++ allows function overloading based on const-ness.
Refer (Const function section)
http://www.cprogramming.com/tutorial/const_correctness.html
Also, subscript operators generally come in pairs, Refer
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.12


Regards,
Sandeep Jain



On Tue, Jul 12, 2011 at 10:09 PM, dheeraj tyagi wrote:

> const means that it cannot be overloaded..i think due to that this is
> happening.
>
>
> On Tue, Jul 12, 2011 at 9:26 PM, segfault wrote:
>
>> #include
>> using namespace std;
>> class x{
>> public:
>> x() {}
>>
>> int  func() const{
>> cout<<"it is const function\n";
>> }
>>
>> int func() {
>> cout<<"it is simple functin\n";
>> }
>>
>>
>> };
>> int main()
>> {
>> x a;
>> a.func();
>> return 0;
>> }
>>
>> why cann't it take const function?
>> explain it
>>
>> --
>> 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
> Dheeraj Tyagi
> 8197218001
>
>
>  --
> 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] output

2011-07-12 Thread Aniket Dutta
@dheeraj: but the prototypes are same. how u are calling it
overloading plz explain

On 7/12/11, dheeraj tyagi  wrote:
> const means that it cannot be overloaded..i think due to that this is
> happening.
>
> On Tue, Jul 12, 2011 at 9:26 PM, segfault  wrote:
>
>> #include
>> using namespace std;
>> class x{
>> public:
>> x() {}
>>
>> int  func() const{
>> cout<<"it is const function\n";
>> }
>>
>> int func() {
>> cout<<"it is simple functin\n";
>> }
>>
>>
>> };
>> int main()
>> {
>> x a;
>> a.func();
>> return 0;
>> }
>>
>> why cann't it take const function?
>> explain it
>>
>> --
>> 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
> Dheeraj Tyagi
> 8197218001
>
> --
> 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] Re: Search node in a binary tree

2011-07-12 Thread Don
// Similar to other suggestions, but without tail recursion.

ptr search(ptr root, int value)
{
ptr result = 0;
while(root && !result)
{
result = (root->tag == value) ? root : search(root->left,
value);
root = root->right;
}
return result;
}

On Jul 12, 8:28 am, anonymous procrastination 
wrote:
> Hello,
>
> Suppose you have to search a particular node in a binary tree.
> The code is quite simple. Pick up any traversal and see if any node
> matches the value.
> Doubt I have is that how to pull out of the recursive function at the
> instant node is found.
> In iterative algos we use a break.
> Here I can use a global flag variable. But any other bettr way of
> doing this?

-- 
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] Reversing the order of words in String

2011-07-12 Thread saurabh singh
and how would strlen compute the length without traversing through the
array?

On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek  wrote:

> One solution can be in one traversal :-
>
> take an example:- char str[]="hello my friends"; int i=strlen(str),j=i;
> char *srt1=malloc(sizeof(char)*i);
> 1. start from end of string (while i>=0,i--)
> 2. whenever u find any space do
>a. strcat(srt1,&srt[i]);
>b. srt[i]='\0';
>d. srt[j-i]=''; //replacing nulls by space, can be done using
> strlen(srt1) also
>
> Note:- I have not executed the code so modifications may be needed. :)
>
> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor wrote:
>
>> char a[20];
>> int l,i,j,k;
>> int main()
>> {
>> char str[100];
>> gets(str);
>> l=strlen(str);
>> for(i=l-1;i>=0;){
>> k=19;
>> a[k]='\0';
>> while(i>=0 && str[i]!=' '){
>>  a[--k]=str[i--];
>> }
>> printf("%s",a+k);
>> while(i>=0 && str[i]==' ') i--;
>> printf(" ");
>> }
>> }
>>
>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor wrote:
>>
>>> Pls Ignore my above post..
>>>
>>>
>>> On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor wrote:
>>>
 char a[20];
 int l;
 int main()
 {
  char str[100];
  scanf("%s",str);
  l=strlen(str);


 }
 --
  *Regards,*
 *Piyush Kapoor,*
 *CSE-IT-BHU*


>>>
>>>
>>> --
>>> *Regards,*
>>> *Piyush Kapoor,*
>>> *CSE-IT-BHU*
>>>
>>>
>>
>>
>> --
>> *Regards,*
>> *Piyush Kapoor,*
>> *CSE-IT-BHU*
>>
>>  --
>> 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
>
>  --
> 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.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT 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.



Re: [algogeeks] output

2011-07-12 Thread dheeraj tyagi
const means that it cannot be overloaded..i think due to that this is
happening.

On Tue, Jul 12, 2011 at 9:26 PM, segfault  wrote:

> #include
> using namespace std;
> class x{
> public:
> x() {}
>
> int  func() const{
> cout<<"it is const function\n";
> }
>
> int func() {
> cout<<"it is simple functin\n";
> }
>
>
> };
> int main()
> {
> x a;
> a.func();
> return 0;
> }
>
> why cann't it take const function?
> explain it
>
> --
> 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
Dheeraj Tyagi
8197218001

-- 
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] output

2011-07-12 Thread segfault
#include
using namespace std;
class x{
public:
x() {}

int  func() const{
cout<<"it is const function\n";
}

int func() {
cout<<"it is simple functin\n";
}


};
int main()
{
x a;
a.func();
return 0;
}

why cann't it take const function?
explain it

-- 
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: linked list doubt

2011-07-12 Thread Aniket Dutta
@anika: according to satistics we need both n/2 and n/2+1 to find the
median from an even set
((n/2)+(n/2+1))/2.
but here you cannot do this. so i guess n/2+1 or n/2 both are correct
because both contribute equally to calculate median.

On 7/12/11, bittu  wrote:
> now try how u will remove the loop from linked list
>
>
> Shashank
> CSE BIT Mesra
>
> --
> 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] Re: O(n) Time is the problem. ..

2011-07-12 Thread Dave
@Anonymous: There are 6 numbers in the list. The low order bit of
1^2^3^4^5^6 is 1. The low order bits of the input are 0,1,0,1,1,0. As
you read them, make a list pointers to the numbers that have low order
bit 0 and another list of pointers that have low order bit 1, and also
take their exclusive or: 0^1^0^1^1^0 = 1. This equals the xor of the
low order bit, so the low order bit of the result is 0.

Now, consider only the numbers in the "0 as a low-order bit" list: 0,
2, 6. There are 3 numbers in the list, and 1^2^3 = 0. Their second
bits are 0,1,1, and the xor is 0. As you read the numbers, make
sublists of the 0s and the 1s. Since the two xors are equal, the
second bit of the result is 0.

Now, consider only the numbers in the "0 in the second bit" list: 0.
There is 1 number in the list so the xor of the number of numbers is
1. The xor of the third bit of the data is 0. Since these numbers
disagree, the result is that the third bit is 1.

Thus, the missing number has binary representation 100, which is 4.

Hope this helps.

Dave

On Jul 12, 6:39 am, anonymous procrastination 
wrote:
> @Dave
> Can you please explain through example.
> Suppose the set is {0,1,2,3,5,6}
> Then how this solution proceeds.
> I am partially getting the logic you explained but need to see an
> example.
>
> Thanks!!

-- 
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] Re: How to store largest N values efficiently

2011-07-12 Thread bittu
John You Can Use MinHeap

here is the algo

1) Build a Min Heap MH of the first k elements (arr[0] to arr[k-1]) of
the given array. O(k)
2) For each element, after the kth element (arr[k] to arr[n-1]),
compare it with root of MH.
a) If the element is greater than the root then make it root and call
heapify for MH
b) Else ignore it.
O((n-k)*logk)
3) Finally, MH has k largest elements and root of the MH is the kth
largest element.

Time Complexity: O(k + (n-k)Logk) without sorted output. If sorted
output is needed then O(k + (n-k)Logk + kLogk)


Thanks
Shashank
Computer Science
Birla Institute of Technology Mesra

-- 
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] Re: linked list doubt

2011-07-12 Thread bittu
now try how u will remove the loop from linked list


Shashank
CSE BIT Mesra

-- 
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] Re: remove duplicate chars in a string without using extra memory

2011-07-12 Thread bittu
whats the problem ?

if no extra memory allowed then can't be done in better then
O(nlogn)sorting time & O(1) space
else it will take O(N) time & O(N) Space

sorting will change the order but using bitmap or bitarray order will
be preserved


Thanks
Shashank
CSE,BIT Mesra

-- 
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] Re: remove duplicate chars in a string without using extra memory

2011-07-12 Thread bittu
whats the probelm

if no extra memory allowed then can't be done in better then
O(nlogn)sorting time & O(1) space
else it will take O(N) time & O(N) Space

sorting will change the order but using bitmap or bitarray order will
be preserved


Thanks
Shashank
CSE,BIT Mesra

-- 
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: Image based Problem (Google)

2011-07-12 Thread santosh mahto
refer Fourier transform and wavelet transform of image

On Tue, Jul 12, 2011 at 7:38 PM, bittu  wrote:

> too store this whole image we need 2^70==10^21 bytes size of disk.
> assuming each pixel take 1 byte . always go metadata for large
> entities .here metadata includes type(e.g jpeg,bmp,gif
> etc),size,name,pointer to log file entry etc.
>
> Shashank
> CSE,BIT Mesra
>
> --
> 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] NVIDIA

2011-07-12 Thread santosh mahto
@aanchal

correction:
 deletion is also O(1);

On Tue, Jul 12, 2011 at 8:31 PM, santosh mahto wrote:

> @aanchal
>
> u are correct in first case.
>
> deletion is also  not O(1). because while freeing we pass the address. so
> with that address it can directly reach the node
> which is to be freed.
>
> Thanks
> Santosh
>
>   On Tue, Jul 12, 2011 at 7:32 PM, ankit sambyal 
> wrote:
>
>> I think the allocation of address in case of circular linked list is
>> very fast   O(1),  whereas it takes O(log n) in case of balanced
>> tree.
>>
>> And yes, to find address for deletion in case of circular linked list
>> is expensive...  O(n) in worst case.
>>
>>
>>
>> On Tue, Jul 12, 2011 at 6:19 AM, aanchal goyal 
>> wrote:
>> > why does space allocator malloc()/free() interface use circular link
>> list to
>> > store allocated/freed addresses in sorted order in a link list form and
>> not
>> > tree(balanced)? To find some address for deletion it needs list
>> traversal
>> > which costs O(n) whereas a balanved tree (at cost of extra pointer space
>> )
>> > can reduce this cost to O(log n)? There are lots of other issues with
>> list
>> > usage here for which i think tree would be better .
>> >
>> > --
>> > Regards,
>> > Aanchal Goyal.
>> >
>> > --
>> > 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] NVIDIA

2011-07-12 Thread santosh mahto
@aanchal

u are correct in first case.

deletion is also  not O(1). because while freeing we pass the address. so
with that address it can directly reach the node
which is to be freed.

Thanks
Santosh

On Tue, Jul 12, 2011 at 7:32 PM, ankit sambyal wrote:

> I think the allocation of address in case of circular linked list is
> very fast   O(1),  whereas it takes O(log n) in case of balanced
> tree.
>
> And yes, to find address for deletion in case of circular linked list
> is expensive...  O(n) in worst case.
>
>
>
> On Tue, Jul 12, 2011 at 6:19 AM, aanchal goyal 
> wrote:
> > why does space allocator malloc()/free() interface use circular link list
> to
> > store allocated/freed addresses in sorted order in a link list form and
> not
> > tree(balanced)? To find some address for deletion it needs list traversal
> > which costs O(n) whereas a balanved tree (at cost of extra pointer space
> )
> > can reduce this cost to O(log n)? There are lots of other issues with
> list
> > usage here for which i think tree would be better .
> >
> > --
> > Regards,
> > Aanchal Goyal.
> >
> > --
> > 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] Re: sbtration

2011-07-12 Thread bittu
Lets Try For Decimal Integer Number how we add them

1 Add 759 + 674, but “forget” to carry I then get 323
2 Add 759 + 674 but only do the carrying, rather than the addition of
each digit I then
  get 1110
3 Add the result of the first two operations (recursively, using the
same process de-
scribed in step 1 and 2): 1110 + 323 = 1433

we have done for decimal numbers

Now, how would we do this in binary?

1 If I add two binary numbers together but forget to carry, bit[i]
will be 0 if bit[i] in a and
b are both 0 or both 1 This is an XOR
2 If I add two numbers together but only carry, I will have a 1 in
bit[i] if bit[i-1] in a and b
are both 1’s This is an AND, shifted

3 Now, recurse until there’s nothing to carry

int add_no_arithm(int a, int b)
{
if (b == 0) return a;
int sum = a ^ b; // add without carrying
int carry = (a & b) << 1; // carry, but don’t add return
add_no_arithm(sum, carry); // recurse
}

Subtraction uses add function internally as well as we have adder !!!

int sub(int x, int y)
{
   return(add(x,add(~y,1));

}

Thanks
Shashank Mani
Computer Science
Birla Institute of Technology Mesra

-- 
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: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
sorry @ankit

On Tue, Jul 12, 2011 at 8:10 PM, Aniket Dutta wrote:

> @bittu
>
>
> On Tue, Jul 12, 2011 at 8:09 PM, Aniket Dutta wrote:
>
>> @yeah right
>>
>>
>> On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal wrote:
>>
>>> @Aniket: Just add a condition at the begining:
>>>
>>> if(root == NULL)
>>> return 0;
>>>
>>> --
>>> 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: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@bittu

On Tue, Jul 12, 2011 at 8:09 PM, Aniket Dutta wrote:

> @yeah right
>
>
> On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal wrote:
>
>> @Aniket: Just add a condition at the begining:
>>
>> if(root == NULL)
>> return 0;
>>
>> --
>> 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: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@yeah right

On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal wrote:

> @Aniket: Just add a condition at the begining:
>
> if(root == NULL)
> return 0;
>
> --
> 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: sbtration

2011-07-12 Thread chandy jose paul
correction:
if(a/b<=1){
return a%b;
}
else
(a/b)*b + a%b;

assumption that difference is positive everytime

On Tue, Jul 12, 2011 at 10:29 AM, Dave  wrote:

> @Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2
> = 5. Check?
>
> Dave
>
> On Jul 11, 11:38 pm, chandy jose paul  wrote:
> > Y are u guys complicating things.Its as simple as this
> >
> >  x=a-b = (a/b)*b + a%b
> >
> >
> >
> > On Tue, Jul 12, 2011 at 1:18 AM, Dave  wrote:
> > > @Aditya: Since 124 is a 3-digit number, I think it would make more
> > > sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
> > > 954 = 1078. Since we are working in 3-digit numbers, the 1 represents
> > > an overflow, which you ignore. Thus, the answer is 78.
> >
> > > Dave
> >
> > > On Jul 11, 2:42 pm, aditya pratap  wrote:
> > > > suppose u want to do 124 - 46
> >
> > > > step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
> > > > step2: add 124 + 54 = 178
> > > > step3: neglect 1 from 178 and answer will be 78.
> >
> > > > correct me if i am wrong.
> >
> > > > On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain  >
> > > wrote:
> > > > > how to do subtraction of two integers widout using subtractn??
> >
> > > > > --
> > > > > 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
> > > > Aditya Pratap
> > > > MCA II
> >
> > > --
> > > 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.- 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 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] Re: Image based Problem (Google)

2011-07-12 Thread bittu
too store this whole image we need 2^70==10^21 bytes size of disk.
assuming each pixel take 1 byte . always go metadata for large
entities .here metadata includes type(e.g jpeg,bmp,gif
etc),size,name,pointer to log file entry etc.

Shashank
CSE,BIT Mesra

-- 
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: Search node in a binary tree

2011-07-12 Thread ankit sambyal
@Aniket: Just add a condition at the begining:

if(root == NULL)
 return 0;

-- 
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: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
what will happen if node is not found?.
you are not checking it

On 7/12/11, bittu  wrote:
> whats the problem with this
>
> bool search(root,node)
> {
> if(root==node)
>   return 1;
> else
>  return search(root->left,node)||search(root->right,node);
>
> }
>
> TC O(N)
>
> notify me via mail if anything wrong.?
>
> Thanks
> Shashank
> CSE,BIT Mesra
>
> --
> 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: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@bittu


On 7/12/11, Aniket Dutta  wrote:
> what will happen if node is not found?.
> you are not checking it
>
> On 7/12/11, bittu  wrote:
>> whats the problem with this
>>
>> bool search(root,node)
>> {
>> if(root==node)
>>   return 1;
>> else
>>  return search(root->left,node)||search(root->right,node);
>>
>> }
>>
>> TC O(N)
>>
>> notify me via mail if anything wrong.?
>>
>> Thanks
>> Shashank
>> CSE,BIT Mesra
>>
>> --
>> 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] NVIDIA

2011-07-12 Thread ankit sambyal
I think the allocation of address in case of circular linked list is
very fast   O(1),  whereas it takes O(log n) in case of balanced
tree.

And yes, to find address for deletion in case of circular linked list
is expensive...  O(n) in worst case.



On Tue, Jul 12, 2011 at 6:19 AM, aanchal goyal  wrote:
> why does space allocator malloc()/free() interface use circular link list to
> store allocated/freed addresses in sorted order in a link list form and not
> tree(balanced)? To find some address for deletion it needs list traversal
> which costs O(n) whereas a balanved tree (at cost of extra pointer space )
> can reduce this cost to O(log n)? There are lots of other issues with list
> usage here for which i think tree would be better .
>
> --
> Regards,
> Aanchal Goyal.
>
> --
> 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] Re: Search node in a binary tree

2011-07-12 Thread bittu
whats the problem with this

bool search(root,node)
{
if(root==node)
  return 1;
else
 return search(root->left,node)||search(root->right,node);

}

TC O(N)

notify me via mail if anything wrong.?

Thanks
Shashank
CSE,BIT Mesra

-- 
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] Re: Search node in a binary tree

2011-07-12 Thread Don
There is no reason to use recursion to search a binary tree.
Don

On Jul 12, 8:28 am, anonymous procrastination 
wrote:
> Hello,
>
> Suppose you have to search a particular node in a binary tree.
> The code is quite simple. Pick up any traversal and see if any node
> matches the value.
> Doubt I have is that how to pull out of the recursive function at the
> instant node is found.
> In iterative algos we use a break.
> Here I can use a global flag variable. But any other bettr way of
> doing this?

-- 
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] Overview of the New C++ (C++0x) by Scott Meyers

2011-07-12 Thread yash
Hi,

Pls let me know if any one  have below ebooks  :
1)Overview of the New C++ (C++0x) by Scott Meyers
2)Programming Pearls (2nd edition) by Jon Bentley.

Thanks
Yash

-- 
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] Search node in a binary tree

2011-07-12 Thread sunny agrawal
i think Return statement will do the job :)

On Tue, Jul 12, 2011 at 6:58 PM, anonymous procrastination <
opamp1...@gmail.com> wrote:

> Hello,
>
> Suppose you have to search a particular node in a binary tree.
> The code is quite simple. Pick up any traversal and see if any node
> matches the value.
> Doubt I have is that how to pull out of the recursive function at the
> instant node is found.
> In iterative algos we use a break.
> Here I can use a global flag variable. But any other bettr way of
> doing this?
>
> --
> 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.
>
>


-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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] Search node in a binary tree

2011-07-12 Thread anonymous procrastination
Hello,

Suppose you have to search a particular node in a binary tree.
The code is quite simple. Pick up any traversal and see if any node
matches the value.
Doubt I have is that how to pull out of the recursive function at the
instant node is found.
In iterative algos we use a break.
Here I can use a global flag variable. But any other bettr way of
doing this?

-- 
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] microsoft ques

2011-07-12 Thread shilpa gupta
@sunny k i have seen...

On Tue, Jul 12, 2011 at 6:48 PM, sunny agrawal wrote:

> @shilpa
>
> see some post is hidden
> click on hide quoted text to see the complete post 
>
>
> On Tue, Jul 12, 2011 at 6:46 PM, shilpa gupta wrote:
>
>> @sunny well this case is not possible i think in any code a braces that
>> are opened should be closed...also
>>
>>
>> On Tue, Jul 12, 2011 at 6:43 PM, sunny agrawal 
>> wrote:
>>
>>> @Nitish
>>> as complete file will be scanned, program is taking care of functions
>>> already
>>>
>>> @shilpa
>>> u r wrong !!
>>> that part of code is very important
>>>
>>> else what will be the answer for the following
>>> {
>>>  {
>>>
>>>  }
>>>
>>>  {
>>>
>>>  }
>>>
>>>  {
>>>   {
>>>
>>>
>>>   }
>>>  }
>>> }
>>>
>>> On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta 
>>> wrote:
>>>
 i think there is no need of this part

 else if(c== '}' )
  {
depth-=1;
  }
 than there is no need to find out max also
 depth will give max itself i think...


 On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal >>> > wrote:

> 1. what if braces occur in comments
>
> and also i think final answer should be 1 less than(dropping { for
> main()) the final count because there is no meaning of scope depth for a
> global variable
>
>
> On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:
>
>> igonre the previous code, here is fully working code..previous one
>> doesn't include check for having { within quotes which should not be 
>> counted
>> for scope depth
>>
>> #include
>>
>> int main()
>> {
>> int depth=0,max=0;
>>  char c,temp;
>> while((c=getchar())!=EOF)
>> {
>>  if(c== '{' )
>>  {
>>depth+=1;
>>if(depth>max)
>>max=depth;
>>  }
>>  else if(c== '}' )
>>  {
>>depth-=1;
>>  }
>>  else if(c=='\"'||c==39)
>>  {
>>  temp=c;
>>  while((c=getchar())!=temp);  //skipping all the
>> characters till next quote occurs
>>  }
>>  }
>>  printf("%d\n",max);
>>  }
>>
>> 39 is ASCII code for '
>> it was giving error when i tried to write it like '''.so i
>> replaced it with its ASCII to save timesomeone please suggest the 
>> proper
>> way to writing it...
>>
>> the code is working fine for this code as input output is 3..if
>> any constraints are left then please suggest !!
>>
>> On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:
>>
>>> my bad...that should be understood..
>>>
>>>
>>> On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani <
>>> vandana@gmail.com> wrote:
>>>
 You have the right braces missing, it would result in a 0 depth for
 all cases. (Precedence of != is greater than =)

 On Tue, Jul 12, 2011 at 5:41 PM, nicks 
 wrote:

> i thought of this code..i think it should work.correct me
> if i am wrong
>
>
> depth=0;max=0;
> while(*(*c=getchar()*)*!=EOF)
> {
>  if(c== '{' )
>  {
>   depth+=1
>   if(depth>max)
>max=depth;
>  }
> else if(c== '}' )
> {
>   depth-=1;
> }
> }
>
>
> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain <
> sandeep6...@gmail.com> wrote:
>
>> If we just have to give the depth as in count then, I believe we
>> can use stack to push/pop curly braces. While maintaining the 
>> maximum depth
>> observed
>> And if we have to display/print line numbers or code itself, then
>> converting the code in a tree structure should help.
>> Each node can contain the line/col position of starting/closing
>> braces. Each node will have its nested braces as child nodes.
>>
>> PS: In either case make sure you ignore comments and strings
>> literals
>>
>>
>> Regards,
>> Sandeep Jain
>>
>>
>>
>>
>> On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
>> shilpagupta...@gmail.com> wrote:
>>
>>> Write down the c code for finding out the maximum scope depth in
>>> a c
>>> code. A scope
>>> depth is increased by one with every '{' and decreases by one
>>> with
>>> every '}'
>>>
>>> --
>>> 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] NVIDIA

2011-07-12 Thread aanchal goyal
why does space allocator malloc()/free() interface use circular link list to
store allocated/freed addresses in sorted order in a link list form and not
tree(balanced)? To find some address for deletion it needs list traversal
which costs O(n) whereas a balanved tree (at cost of extra pointer space )
can reduce this cost to O(log n)? There are lots of other issues with list
usage here for which i think tree would be better .

-- 
Regards,*
Aanchal Goyal*.

-- 
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] microsoft ques

2011-07-12 Thread sunny agrawal
@shilpa

see some post is hidden
click on hide quoted text to see the complete post 

On Tue, Jul 12, 2011 at 6:46 PM, shilpa gupta wrote:

> @sunny well this case is not possible i think in any code a braces that are
> opened should be closed...also
>
>
> On Tue, Jul 12, 2011 at 6:43 PM, sunny agrawal wrote:
>
>> @Nitish
>> as complete file will be scanned, program is taking care of functions
>> already
>>
>> @shilpa
>> u r wrong !!
>> that part of code is very important
>>
>> else what will be the answer for the following
>> {
>>  {
>>
>>  }
>>
>>  {
>>
>>  }
>>
>>  {
>>   {
>>
>>
>>   }
>>  }
>> }
>>
>> On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta 
>> wrote:
>>
>>> i think there is no need of this part
>>>
>>> else if(c== '}' )
>>>  {
>>>depth-=1;
>>>  }
>>> than there is no need to find out max also
>>> depth will give max itself i think...
>>>
>>>
>>> On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal 
>>> wrote:
>>>
 1. what if braces occur in comments

 and also i think final answer should be 1 less than(dropping { for
 main()) the final count because there is no meaning of scope depth for a
 global variable


 On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:

> igonre the previous code, here is fully working code..previous one
> doesn't include check for having { within quotes which should not be 
> counted
> for scope depth
>
> #include
>
> int main()
> {
> int depth=0,max=0;
>  char c,temp;
> while((c=getchar())!=EOF)
> {
>  if(c== '{' )
>  {
>depth+=1;
>if(depth>max)
>max=depth;
>  }
>  else if(c== '}' )
>  {
>depth-=1;
>  }
>  else if(c=='\"'||c==39)
>  {
>  temp=c;
>  while((c=getchar())!=temp);  //skipping all the
> characters till next quote occurs
>  }
>  }
>  printf("%d\n",max);
>  }
>
> 39 is ASCII code for '
> it was giving error when i tried to write it like '''.so i replaced
> it with its ASCII to save timesomeone please suggest the proper way to
> writing it...
>
> the code is working fine for this code as input output is 3..if
> any constraints are left then please suggest !!
>
> On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:
>
>> my bad...that should be understood..
>>
>>
>> On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani <
>> vandana@gmail.com> wrote:
>>
>>> You have the right braces missing, it would result in a 0 depth for
>>> all cases. (Precedence of != is greater than =)
>>>
>>> On Tue, Jul 12, 2011 at 5:41 PM, nicks 
>>> wrote:
>>>
 i thought of this code..i think it should work.correct me if
 i am wrong


 depth=0;max=0;
 while(*(*c=getchar()*)*!=EOF)
 {
  if(c== '{' )
  {
   depth+=1
   if(depth>max)
max=depth;
  }
 else if(c== '}' )
 {
   depth-=1;
 }
 }


 On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain <
 sandeep6...@gmail.com> wrote:

> If we just have to give the depth as in count then, I believe we
> can use stack to push/pop curly braces. While maintaining the maximum 
> depth
> observed
> And if we have to display/print line numbers or code itself, then
> converting the code in a tree structure should help.
> Each node can contain the line/col position of starting/closing
> braces. Each node will have its nested braces as child nodes.
>
> PS: In either case make sure you ignore comments and strings
> literals
>
>
> Regards,
> Sandeep Jain
>
>
>
>
> On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
> shilpagupta...@gmail.com> wrote:
>
>> Write down the c code for finding out the maximum scope depth in a
>> c
>> code. A scope
>> depth is increased by one with every '{' and decreases by one with
>> every '}'
>>
>> --
>> 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 "Al

Re: [algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
@sunny well this case is not possible i think in any code a braces that are
opened should be closed...also

On Tue, Jul 12, 2011 at 6:43 PM, sunny agrawal wrote:

> @Nitish
> as complete file will be scanned, program is taking care of functions
> already
>
> @shilpa
> u r wrong !!
> that part of code is very important
>
> else what will be the answer for the following
> {
>  {
>
>  }
>
>  {
>
>  }
>
>  {
>   {
>
>
>   }
>  }
> }
>
> On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta wrote:
>
>> i think there is no need of this part
>>
>> else if(c== '}' )
>>  {
>>depth-=1;
>>  }
>> than there is no need to find out max also
>> depth will give max itself i think...
>>
>>
>> On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal 
>> wrote:
>>
>>> 1. what if braces occur in comments
>>>
>>> and also i think final answer should be 1 less than(dropping { for
>>> main()) the final count because there is no meaning of scope depth for a
>>> global variable
>>>
>>>
>>> On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:
>>>
 igonre the previous code, here is fully working code..previous one
 doesn't include check for having { within quotes which should not be 
 counted
 for scope depth

 #include

 int main()
 {
 int depth=0,max=0;
  char c,temp;
 while((c=getchar())!=EOF)
 {
  if(c== '{' )
  {
depth+=1;
if(depth>max)
max=depth;
  }
  else if(c== '}' )
  {
depth-=1;
  }
  else if(c=='\"'||c==39)
  {
  temp=c;
  while((c=getchar())!=temp);  //skipping all the
 characters till next quote occurs
  }
  }
  printf("%d\n",max);
  }

 39 is ASCII code for '
 it was giving error when i tried to write it like '''.so i replaced
 it with its ASCII to save timesomeone please suggest the proper way to
 writing it...

 the code is working fine for this code as input output is 3..if
 any constraints are left then please suggest !!

 On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:

> my bad...that should be understood..
>
>
> On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani <
> vandana@gmail.com> wrote:
>
>> You have the right braces missing, it would result in a 0 depth for
>> all cases. (Precedence of != is greater than =)
>>
>> On Tue, Jul 12, 2011 at 5:41 PM, nicks wrote:
>>
>>> i thought of this code..i think it should work.correct me if
>>> i am wrong
>>>
>>>
>>> depth=0;max=0;
>>> while(*(*c=getchar()*)*!=EOF)
>>> {
>>>  if(c== '{' )
>>>  {
>>>   depth+=1
>>>   if(depth>max)
>>>max=depth;
>>>  }
>>> else if(c== '}' )
>>> {
>>>   depth-=1;
>>> }
>>> }
>>>
>>>
>>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain >> > wrote:
>>>
 If we just have to give the depth as in count then, I believe we can
 use stack to push/pop curly braces. While maintaining the maximum depth
 observed
 And if we have to display/print line numbers or code itself, then
 converting the code in a tree structure should help.
 Each node can contain the line/col position of starting/closing
 braces. Each node will have its nested braces as child nodes.

 PS: In either case make sure you ignore comments and strings
 literals


 Regards,
 Sandeep Jain




 On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
 shilpagupta...@gmail.com> wrote:

> Write down the c code for finding out the maximum scope depth in a
> c
> code. A scope
> depth is increased by one with every '{' and decreases by one with
> every '}'
>
> --
> 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.

>>>
>>>
>>> On Tue, Jul 12, 2011 at 4:55 PM,

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
i think adding this would take care of { in comment also

else if(c=='\"'||c==39||c=='*")
 {
 temp=c;
 while((c=getchar())!=temp);  //skipping all the characters
till next quote or end of comment occurs
 }

On Tue, Jul 12, 2011 at 6:43 PM, sunny agrawal wrote:

> @Nitish
> as complete file will be scanned, program is taking care of functions
> already
>
> @shilpa
> u r wrong !!
> that part of code is very important
>
> else what will be the answer for the following
> {
>  {
>
>  }
>
>  {
>
>  }
>
>  {
>   {
>
>
>   }
>  }
> }
>
> On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta wrote:
>
>> i think there is no need of this part
>>
>> else if(c== '}' )
>>  {
>>depth-=1;
>>  }
>> than there is no need to find out max also
>> depth will give max itself i think...
>>
>>
>> On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal 
>> wrote:
>>
>>> 1. what if braces occur in comments
>>>
>>> and also i think final answer should be 1 less than(dropping { for
>>> main()) the final count because there is no meaning of scope depth for a
>>> global variable
>>>
>>>
>>> On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:
>>>
 igonre the previous code, here is fully working code..previous one
 doesn't include check for having { within quotes which should not be 
 counted
 for scope depth

 #include

 int main()
 {
 int depth=0,max=0;
  char c,temp;
 while((c=getchar())!=EOF)
 {
  if(c== '{' )
  {
depth+=1;
if(depth>max)
max=depth;
  }
  else if(c== '}' )
  {
depth-=1;
  }
  else if(c=='\"'||c==39)
  {
  temp=c;
  while((c=getchar())!=temp);  //skipping all the
 characters till next quote occurs
  }
  }
  printf("%d\n",max);
  }

 39 is ASCII code for '
 it was giving error when i tried to write it like '''.so i replaced
 it with its ASCII to save timesomeone please suggest the proper way to
 writing it...

 the code is working fine for this code as input output is 3..if
 any constraints are left then please suggest !!

 On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:

> my bad...that should be understood..
>
>
> On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani <
> vandana@gmail.com> wrote:
>
>> You have the right braces missing, it would result in a 0 depth for
>> all cases. (Precedence of != is greater than =)
>>
>> On Tue, Jul 12, 2011 at 5:41 PM, nicks wrote:
>>
>>> i thought of this code..i think it should work.correct me if
>>> i am wrong
>>>
>>>
>>> depth=0;max=0;
>>> while(*(*c=getchar()*)*!=EOF)
>>> {
>>>  if(c== '{' )
>>>  {
>>>   depth+=1
>>>   if(depth>max)
>>>max=depth;
>>>  }
>>> else if(c== '}' )
>>> {
>>>   depth-=1;
>>> }
>>> }
>>>
>>>
>>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain >> > wrote:
>>>
 If we just have to give the depth as in count then, I believe we can
 use stack to push/pop curly braces. While maintaining the maximum depth
 observed
 And if we have to display/print line numbers or code itself, then
 converting the code in a tree structure should help.
 Each node can contain the line/col position of starting/closing
 braces. Each node will have its nested braces as child nodes.

 PS: In either case make sure you ignore comments and strings
 literals


 Regards,
 Sandeep Jain




 On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
 shilpagupta...@gmail.com> wrote:

> Write down the c code for finding out the maximum scope depth in a
> c
> code. A scope
> depth is increased by one with every '{' and decreases by one with
> every '}'
>
> --
> 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 grou

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
@shilpa...absolutely wrong
{
}
{
}

depth acc. to you is 2...incorrectit is 1

On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta wrote:

> i think there is no need of this part
>
> else if(c== '}' )
>  {
>depth-=1;
>  }
> than there is no need to find out max also
> depth will give max itself i think...
>
>
> On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal wrote:
>
>> 1. what if braces occur in comments
>>
>> and also i think final answer should be 1 less than(dropping { for main())
>> the final count because there is no meaning of scope depth for a global
>> variable
>>
>>
>> On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:
>>
>>> igonre the previous code, here is fully working code..previous one
>>> doesn't include check for having { within quotes which should not be counted
>>> for scope depth
>>>
>>> #include
>>>
>>> int main()
>>> {
>>> int depth=0,max=0;
>>>  char c,temp;
>>> while((c=getchar())!=EOF)
>>> {
>>>  if(c== '{' )
>>>  {
>>>depth+=1;
>>>if(depth>max)
>>>max=depth;
>>>  }
>>>  else if(c== '}' )
>>>  {
>>>depth-=1;
>>>  }
>>>  else if(c=='\"'||c==39)
>>>  {
>>>  temp=c;
>>>  while((c=getchar())!=temp);  //skipping all the
>>> characters till next quote occurs
>>>  }
>>>  }
>>>  printf("%d\n",max);
>>>  }
>>>
>>> 39 is ASCII code for '
>>> it was giving error when i tried to write it like '''.so i replaced
>>> it with its ASCII to save timesomeone please suggest the proper way to
>>> writing it...
>>>
>>> the code is working fine for this code as input output is 3..if
>>> any constraints are left then please suggest !!
>>>
>>> On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:
>>>
 my bad...that should be understood..


 On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani >>> > wrote:

> You have the right braces missing, it would result in a 0 depth for all
> cases. (Precedence of != is greater than =)
>
> On Tue, Jul 12, 2011 at 5:41 PM, nicks wrote:
>
>> i thought of this code..i think it should work.correct me if i
>> am wrong
>>
>>
>> depth=0;max=0;
>> while(*(*c=getchar()*)*!=EOF)
>> {
>>  if(c== '{' )
>>  {
>>   depth+=1
>>   if(depth>max)
>>max=depth;
>>  }
>> else if(c== '}' )
>> {
>>   depth-=1;
>> }
>> }
>>
>>
>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain 
>> wrote:
>>
>>> If we just have to give the depth as in count then, I believe we can
>>> use stack to push/pop curly braces. While maintaining the maximum depth
>>> observed
>>> And if we have to display/print line numbers or code itself, then
>>> converting the code in a tree structure should help.
>>> Each node can contain the line/col position of starting/closing
>>> braces. Each node will have its nested braces as child nodes.
>>>
>>> PS: In either case make sure you ignore comments and strings literals
>>>
>>>
>>> Regards,
>>> Sandeep Jain
>>>
>>>
>>>
>>>
>>> On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
>>> shilpagupta...@gmail.com> wrote:
>>>
 Write down the c code for finding out the maximum scope depth in a c
 code. A scope
 depth is increased by one with every '{' and decreases by one with
 every '}'

 --
 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.
>>>
>>
>>
>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain 
>> wrote:
>>
>>> If we just have to give the depth as in count then, I believe we can
>>> use stack to push/pop curly braces. While maintaining the maximum depth
>>> observed
>>> And if we have to display/print line numbers or code itself, then
>>> converting the code in a tree structure should help.
>>> Each node can contain the line/col position of starting/closing
>>> braces. Each node will have its nested braces as child nodes.
>>>
>>> PS: In either case make sure you ignore comments and strings literals
>>>
>>>
>>>

Re: [algogeeks] microsoft ques

2011-07-12 Thread sunny agrawal
@Nitish
as complete file will be scanned, program is taking care of functions
already

@shilpa
u r wrong !!
that part of code is very important

else what will be the answer for the following
{
 {

 }

 {

 }

 {
  {

  }
 }
}

On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta wrote:

> i think there is no need of this part
>
> else if(c== '}' )
>  {
>depth-=1;
>  }
> than there is no need to find out max also
> depth will give max itself i think...
>
>
> On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal wrote:
>
>> 1. what if braces occur in comments
>>
>> and also i think final answer should be 1 less than(dropping { for main())
>> the final count because there is no meaning of scope depth for a global
>> variable
>>
>>
>> On Tue, Jul 12, 2011 at 6:22 PM, nicks wrote:
>>
>>> igonre the previous code, here is fully working code..previous one
>>> doesn't include check for having { within quotes which should not be counted
>>> for scope depth
>>>
>>> #include
>>>
>>> int main()
>>> {
>>> int depth=0,max=0;
>>>  char c,temp;
>>> while((c=getchar())!=EOF)
>>> {
>>>  if(c== '{' )
>>>  {
>>>depth+=1;
>>>if(depth>max)
>>>max=depth;
>>>  }
>>>  else if(c== '}' )
>>>  {
>>>depth-=1;
>>>  }
>>>  else if(c=='\"'||c==39)
>>>  {
>>>  temp=c;
>>>  while((c=getchar())!=temp);  //skipping all the
>>> characters till next quote occurs
>>>  }
>>>  }
>>>  printf("%d\n",max);
>>>  }
>>>
>>> 39 is ASCII code for '
>>> it was giving error when i tried to write it like '''.so i replaced
>>> it with its ASCII to save timesomeone please suggest the proper way to
>>> writing it...
>>>
>>> the code is working fine for this code as input output is 3..if
>>> any constraints are left then please suggest !!
>>>
>>> On Tue, Jul 12, 2011 at 5:50 PM, nicks wrote:
>>>
 my bad...that should be understood..


 On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani >>> > wrote:

> You have the right braces missing, it would result in a 0 depth for all
> cases. (Precedence of != is greater than =)
>
> On Tue, Jul 12, 2011 at 5:41 PM, nicks wrote:
>
>> i thought of this code..i think it should work.correct me if i
>> am wrong
>>
>>
>> depth=0;max=0;
>> while(*(*c=getchar()*)*!=EOF)
>> {
>>  if(c== '{' )
>>  {
>>   depth+=1
>>   if(depth>max)
>>max=depth;
>>  }
>> else if(c== '}' )
>> {
>>   depth-=1;
>> }
>> }
>>
>>
>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain 
>> wrote:
>>
>>> If we just have to give the depth as in count then, I believe we can
>>> use stack to push/pop curly braces. While maintaining the maximum depth
>>> observed
>>> And if we have to display/print line numbers or code itself, then
>>> converting the code in a tree structure should help.
>>> Each node can contain the line/col position of starting/closing
>>> braces. Each node will have its nested braces as child nodes.
>>>
>>> PS: In either case make sure you ignore comments and strings literals
>>>
>>>
>>> Regards,
>>> Sandeep Jain
>>>
>>>
>>>
>>>
>>> On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <
>>> shilpagupta...@gmail.com> wrote:
>>>
 Write down the c code for finding out the maximum scope depth in a c
 code. A scope
 depth is increased by one with every '{' and decreases by one with
 every '}'

 --
 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.
>>>
>>
>>
>> On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain 
>> wrote:
>>
>>> If we just have to give the depth as in count then, I believe we can
>>> use stack to push/pop curly braces. While maintaining the maximum depth
>>> observed
>>> And if we have to display/print line numbers or code itself, then
>>> converting the code in a tree structure should help.
>>> Each node can contain the line/col position of startin

[algogeeks] Image based Problem (Google)

2011-07-12 Thread Navneet Gupta
Given 1000 million x 1000 million image, What information of
this image to be stored such that you can  find the locations
when the given image has modi cations

-- 
Regards,
Navneet

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



  1   2   >