[algogeeks] Re: SPOJ Problem DP

2011-07-03 Thread shady
any spojjer in the group ? if you want i can post my solution with
djikstra's :P ?

Shady

On Sat, Jul 2, 2011 at 10:31 AM, shady sinv...@gmail.com wrote:

 Hi,
 I am solving this http://www.spoj.pl/problems/DP/ problem using Djikstra's
 algorithm. What is the dynamic programming solution to this ?

 PS : Don't post the code, but the states of dp.

 Thanks.

 Shady


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] [Brain Teaser]Popular Puzzle of the week

2011-07-03 Thread Birender rawat
 *Hi,*
*
*
*Based on most comments, The popular puzzle of the last week is*
*
*
*
*
*
http://dailybrainteaser.blogspot.com/2011/06/find-next-number.html?biren=biren
*
*
*
**
*
*
*http://dailybrainteaser.blogspot.com/2011/06/equation-puzzle.html?**
biren=biren*
*
*
*
*
*You Can Also follow us on Facebook by liking this page*
*http://www.facebook.com/pages/Brain-Teasers/215057538517190*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Interview Question

2011-07-03 Thread Sandeep Jain
I was thinking the same, BUT here the question is that we have two *SETS*
and that's the catch.
So, XORing all elements of SET A with SET B should result in ZERO only when
both the set have same elements.


Regards,
Sandeep Jain




On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal meetpranav...@gmail.comwrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.comwrote:

 @aditya. xor all elements mean that. take xor of each element of 1st array
 store in a variable that take xor of variable and each element of the second
 array if all elements are common then the variable will be 0 some where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont think
 dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.comwrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element in an
 array using minimum no of comparisons?Any thing better than O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if in
 both the array set of integers are same but they arnt corresponding to 
 each
 other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays have the
 same
  set of ntegers ? Suggest an algo which can run faster than NlogN
 without
  extra space?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Mohit Mittal
 4th year , Computer Engineering
 Student-Coordinator , DTU WebTeam
 Delhi Technological University

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 ,08011820777
 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.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 

Re: [algogeeks] [Brain Teaser]Popular Puzzle of the week

2011-07-03 Thread shady
banned :)

On Sun, Jul 3, 2011 at 12:31 PM, Birender rawat birender.ra...@gmail.comwrote:

 *Hi,*
 *
 *
 *Based on most comments, The popular puzzle of the last week is*
 *
 *
 *
 *
 *
 http://dailybrainteaser.blogspot.com/2011/06/find-next-number.html?biren=biren
 *
 *
 *
 **
 *
 *
 *http://dailybrainteaser.blogspot.com/2011/06/equation-puzzle.html?**
 biren=biren*
 *
 *
 *
 *
 *You Can Also follow us on Facebook by liking this page*
 *http://www.facebook.com/pages/Brain-Teasers/215057538517190*

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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: Interview Question

2011-07-03 Thread sunny agrawal
@sandeep
SET A - {0,3,4,7}
SET B - {1,2,5,6}

xor of all elements is zero
sum of both the sets is same
no of elements in both are same

overall result : all Algorithm posted above Fails

On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.com wrote:

 I was thinking the same, BUT here the question is that we have two *SETS*
 and that's the catch.
 So, XORing all elements of SET A with SET B should result in ZERO only when
 both the set have same elements.


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal 
 meetpranav...@gmail.comwrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.comwrote:

 @aditya. xor all elements mean that. take xor of each element of 1st
 array store in a variable that take xor of variable and each element of the
 second array if all elements are common then the variable will be 0 some
 where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont
 think dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.comwrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element in
 an array using minimum no of comparisons?Any thing better than O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if in
 both the array set of integers are same but they arnt corresponding to 
 each
 other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays have
 the same
  set of ntegers ? Suggest an algo which can run faster than NlogN
 without
  extra space?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Mohit Mittal
 4th year , Computer Engineering
 Student-Coordinator , DTU WebTeam
 Delhi Technological University

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 ,08011820777
 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.


  --
 You received this message because you are 

[algogeeks] Optimisation to reduce time...

2011-07-03 Thread rajeevrvis
Hi Here is the code  . I want to optimize it to run faster .
Can Anyone help me???

#includestdio.h
void main()
{
 int n,q,a[10]={0},b[10],c[10],d[10],i,count,j;
 scanf(%d%d,n,q);
 for(i=0;iq;i++) scanf(%d%d%d,b[i],c[i],d[i]);
 for(i=0;iq;i++)
   if(b[i]==0)
   {
for(j=c[i];j=d[i];j++)
 a[j]=a[j]+1;
   }
else
{
 count =0;
 for(j=c[i];j=d[i];j++)
  if(a[j]%3==0)
   count++;
 printf(%d\n,count);
 }
}

 Regards

rajeevrvis

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Interview Question

2011-07-03 Thread Sandeep Jain
Agreed, BUT if you don't add a stipulation. You won't be able to reduce the
complexity.
For a 100% general solution, I don't think you can reduce the complexity
more than O(nLgn.)
There are variations of this question:
-- All numbers are non-zero and distinct.
-- All numbers belong to given range
-- You can also have character's in place of numbers
In all the above cases, you will have time complexity O(n)

PS: I'm definitely looking forward to learn a solution, better than O(nLgn)



Regards,
Sandeep Jain




On Sun, Jul 3, 2011 at 1:09 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @sandeep
 SET A - {0,3,4,7}
 SET B - {1,2,5,6}

 xor of all elements is zero
 sum of both the sets is same
 no of elements in both are same

 overall result : all Algorithm posted above Fails

 On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 I was thinking the same, BUT here the question is that we have two *SETS*
 and that's the catch.
 So, XORing all elements of SET A with SET B should result in ZERO only
 when both the set have same elements.


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal 
 meetpranav...@gmail.comwrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.comwrote:

 @aditya. xor all elements mean that. take xor of each element of 1st
 array store in a variable that take xor of variable and each element of the
 second array if all elements are common then the variable will be 0 some
 where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont
 think dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.comwrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element in
 an array using minimum no of comparisons?Any thing better than O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if in
 both the array set of integers are same but they arnt corresponding to 
 each
 other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.com wrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays have
 the same
  set of ntegers ? Suggest an algo which can run faster than NlogN
 without
  extra space?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Mohit Mittal
 4th year , Computer Engineering
 Student-Coordinator , DTU WebTeam
 Delhi Technological University

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 ,08011820777
 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 

Re: [algogeeks] Optimisation to reduce time...

2011-07-03 Thread Sandeep Jain
Can you give an insight to what exactly this code does? That may help quiet
a lot.



Regards,
Sandeep Jain




On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote:

 Hi Here is the code  . I want to optimize it to run faster .
 Can Anyone help me???

 #includestdio.h
 void main()
 {
  int n,q,a[10]={0},b[10],c[10],d[10],i,count,j;
  scanf(%d%d,n,q);
  for(i=0;iq;i++) scanf(%d%d%d,b[i],c[i],d[i]);
  for(i=0;iq;i++)
   if(b[i]==0)
   {
for(j=c[i];j=d[i];j++)
 a[j]=a[j]+1;
   }
else
{
 count =0;
 for(j=c[i];j=d[i];j++)
  if(a[j]%3==0)
   count++;
 printf(%d\n,count);
 }
}

  Regards

 rajeevrvis

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Optimisation to reduce time...

2011-07-03 Thread sunny agrawal
You should have posted the problem link
i think u are trying this one. http://www.codechef.com/problems/MULTQ3/

 http://www.codechef.com/problems/MULTQ3/use RMQ or Binary Indexed Trees.
Brute Force won't work

On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote:

 Hi Here is the code  . I want to optimize it to run faster .
 Can Anyone help me???

 #includestdio.h
 void main()
 {
  int n,q,a[10]={0},b[10],c[10],d[10],i,count,j;
  scanf(%d%d,n,q);
  for(i=0;iq;i++) scanf(%d%d%d,b[i],c[i],d[i]);
  for(i=0;iq;i++)
   if(b[i]==0)
   {
for(j=c[i];j=d[i];j++)
 a[j]=a[j]+1;
   }
else
{
 count =0;
 for(j=c[i];j=d[i];j++)
  if(a[j]%3==0)
   count++;
 printf(%d\n,count);
 }
}

  Regards

 rajeevrvis

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Re: Interview Question

2011-07-03 Thread sunny agrawal
But i don't think xor method will work at all for all of the cases above you
mentioned.
setA = {4,7}
setB = {5,6}

- all numbers in both set are nonzero and distinct
- all numbers are in some range :D
and for character parts it will similarly failby taking character set of
ascii values 4,5,6,7

and about general solution i dont know how to do it in O(n)
one thing i was thinking of goes this way, taking arrays A and B instead of
sets.
if we can prove these polynomial to be same in O(n) time.
(x-a[0])*(x-a[1])*.*(x-a[n-1]) ==
(x-b[0])*(x-b[1])*.(x-b[n-1])
dont know if it can be done efficienty

On Sun, Jul 3, 2011 at 1:25 PM, Sandeep Jain sandeep6...@gmail.com wrote:

 Agreed, BUT if you don't add a stipulation. You won't be able to reduce the
 complexity.
 For a 100% general solution, I don't think you can reduce the complexity
 more than O(nLgn.)
 There are variations of this question:
 -- All numbers are non-zero and distinct.
 -- All numbers belong to given range
 -- You can also have character's in place of numbers
 In all the above cases, you will have time complexity O(n)

 PS: I'm definitely looking forward to learn a solution, better than O(nLgn)



 Regards,
 Sandeep Jain




 On Sun, Jul 3, 2011 at 1:09 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @sandeep
 SET A - {0,3,4,7}
 SET B - {1,2,5,6}

 xor of all elements is zero
 sum of both the sets is same
 no of elements in both are same

 overall result : all Algorithm posted above Fails

 On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 I was thinking the same, BUT here the question is that we have two *SETS*
 and that's the catch.
 So, XORing all elements of SET A with SET B should result in ZERO only
 when both the set have same elements.


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal meetpranav...@gmail.com
  wrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa 
 varunpahwa2...@gmail.comwrote:

 @aditya. xor all elements mean that. take xor of each element of 1st
 array store in a variable that take xor of variable and each element of 
 the
 second array if all elements are common then the variable will be 0 some
 where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont
 think dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal 
 mohitm.1...@gmail.comwrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element in
 an array using minimum no of comparisons?Any thing better than O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if in
 both the array set of integers are same but they arnt corresponding to 
 each
 other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.comwrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays have
 the same
  set of ntegers ? Suggest an algo which can run faster than NlogN
 without
  extra space?

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Mohit Mittal
 4th year , Computer Engineering
 Student-Coordinator , DTU WebTeam
 Delhi Technological University

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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 

[algogeeks] Re: Optimisation to reduce time...

2011-07-03 Thread rajeevrvis
@sunny Ok , Thanks

On Jul 3, 12:58 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 You should have posted the problem link
 i think u are trying this one. http://www.codechef.com/problems/MULTQ3/

  http://www.codechef.com/problems/MULTQ3/use RMQ or Binary Indexed Trees.
 Brute Force won't work

 On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote:









  Hi Here is the code  . I want to optimize it to run faster .
  Can Anyone help me???

  #includestdio.h
  void main()
  {
   int n,q,a[10]={0},b[10],c[10],d[10],i,count,j;
   scanf(%d%d,n,q);
   for(i=0;iq;i++) scanf(%d%d%d,b[i],c[i],d[i]);
   for(i=0;iq;i++)
    if(b[i]==0)
    {
     for(j=c[i];j=d[i];j++)
      a[j]=a[j]+1;
    }
     else
     {
      count =0;
      for(j=c[i];j=d[i];j++)
       if(a[j]%3==0)
        count++;
      printf(%d\n,count);
      }
     }

   Regards

  rajeevrvis

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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] Re: Number of Comparisons!

2011-07-03 Thread udit sharma
Its Ceiling of (n/2) In both cases atmost comparisons will be 3
*  Ceiling of (n/2)...

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread Nitish Garg
Which chapter of Sartaj Sahni are you referring to?

-- 
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/-/rWAgp3fzkrcJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
class Base
{
  public:
int a;
};

class X:  public Base
{
  public:
int x;
};

class Y:  public Base
{
  public:
int y;
};

class Z:public X,public Y
{
};

int main()
{coutsizeof(Base)endl;
cout  sizeof(X) endl;
cout  sizeof(Y) endl;
cout  sizeof(Z) endl;
}
o/p is 4
8
8
16...
which is absolutely fine.

but the problem arises here
class Base
{
  public:
int a;
};

class X:virtual public Base
{
  public:
int x;
};

class Y:virtual public Base
{
  public:
int y;
};

class Z:public X,public Y
{
};

int main()
{coutsizeof(Base)endl;
cout  sizeof(X) endl;
cout  sizeof(Y) endl;
cout  sizeof(Z) endl;
}

o/p is 4
12
12
20
why the size is 12 and 20 for x and Zdoes this is because that
some sort of VPTR IS maintained in the classif yes then then what
does that points to

PS:HERE.i am talking about virtual inheritanceNOT ABOUT
VIRTUAL FUNCTIONS...

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread sunny agrawal
refer CLRS topic 9.1 Maximum and Minimum page no 184 :)

On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.comwrote:

 Which chapter of Sartaj Sahni are you referring to?

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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] VIRTUAL INHERITANCE

2011-07-03 Thread abc abc
In the second case , the size of vptr will be added to each and every object
.
1st class = one int :4
2nd class = one int +one int from base + vptr =12
3rd class = one int + one int from base + vptr =12
4th class =one int from each base class + one int from each of the grand
parent +one vptr =20

On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal himanshukansal...@gmail.com
 wrote:

 class Base
 {
  public:
int a;
 };

 class X:  public Base
 {
  public:
int x;
 };

 class Y:  public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }
 o/p is 4
 8
 8
 16...
 which is absolutely fine.

 but the problem arises here
 class Base
 {
  public:
int a;
 };

 class X:virtual public Base
 {
  public:
int x;
 };

 class Y:virtual public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }

 o/p is 4
 12
 12
 20
 why the size is 12 and 20 for x and Zdoes this is because that
 some sort of VPTR IS maintained in the classif yes then then what
 does that points to

 PS:HERE.i am talking about virtual inheritanceNOT ABOUT
 VIRTUAL FUNCTIONS...

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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: VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
1 MORE QUESHOW IS DELEGATED TO SISTER CLASS IMPLEMENTED...MEANS HOW
CAN ONE CLASS CALL ANOTHER CLASS'S FUNCTION WITHOUT KNOWING ANYTHING ABOUT
IT
On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal himanshukansal...@gmail.com
 wrote:

 class Base
 {
  public:
int a;
 };

 class X:  public Base
 {
  public:
int x;
 };

 class Y:  public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }
 o/p is 4
 8
 8
 16...
 which is absolutely fine.

 but the problem arises here
 class Base
 {
  public:
int a;
 };

 class X:virtual public Base
 {
  public:
int x;
 };

 class Y:virtual public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }

 o/p is 4
 12
 12
 20
 why the size is 12 and 20 for x and Zdoes this is because that
 some sort of VPTR IS maintained in the classif yes then then what
 does that points to

 PS:HERE.i am talking about virtual inheritanceNOT ABOUT
 VIRTUAL FUNCTIONS...




-- 

  Regards
Himanshu Kansal
  Msc Comp. sc.
(University of Delhi)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
shouldnt it be 16cz only one instance of base class gets included when
we use virtual keyword..

On Sun, Jul 3, 2011 at 2:54 PM, abc abc may.i.answ...@gmail.com wrote:

 In the second case , the size of vptr will be added to each and every
 object .
 1st class = one int :4
 2nd class = one int +one int from base + vptr =12
 3rd class = one int + one int from base + vptr =12
 4th class =one int from each base class + one int from each of the grand
 parent +one vptr =20

 On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal 
 himanshukansal...@gmail.com wrote:

 class Base
 {
  public:
int a;
 };

 class X:  public Base
 {
  public:
int x;
 };

 class Y:  public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }
 o/p is 4
 8
 8
 16...
 which is absolutely fine.

 but the problem arises here
 class Base
 {
  public:
int a;
 };

 class X:virtual public Base
 {
  public:
int x;
 };

 class Y:virtual public Base
 {
  public:
int y;
 };

 class Z:public X,public Y
 {
 };

 int main()
 {coutsizeof(Base)endl;
 cout  sizeof(X) endl;
 cout  sizeof(Y) endl;
 cout  sizeof(Z) endl;
 }

 o/p is 4
 12
 12
 20
 why the size is 12 and 20 for x and Zdoes this is because that
 some sort of VPTR IS maintained in the classif yes then then what
 does that points to

 PS:HERE.i am talking about virtual inheritanceNOT ABOUT
 VIRTUAL FUNCTIONS...

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 

  Regards
Himanshu Kansal
  Msc Comp. sc.
(University of Delhi)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread Nitish Garg
Thanks got it.

On 7/3/11, sunny agrawal sunny816.i...@gmail.com wrote:
 refer CLRS topic 9.1 Maximum and Minimum page no 184 :)

 On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.comwrote:

 Which chapter of Sartaj Sahni are you referring to?

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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.



-- 
Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: help..

2011-07-03 Thread cegprakash
@sameer: thank you

On Jul 2, 3:47 pm, sameer.mut...@gmail.com sameer.mut...@gmail.com
wrote:
 nn-1  is the expression to find out if n is a power of 2...If nn-1 returns
 0 its a power of 2 else its not.
 And what sunny said is also ryt

 On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal sunny816.i...@gmail.comwrote:







  @cegprakash
  Expression resets the least significant set bit

  On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:

  May be this can work.give any counter example...
  int count;
  main()
  {
        int l,rope,cuts;
        scanf(%d%d,l,rope);
        count =0;

         find_cuts(l,rope);
         printf(cuts needed is %d,count);
         getch();
         return 0;
         }

   int find_cuts(int l,int rope)

   {

      if(l==rope)
      return count;
       count++;
       printf(%d,count);
       l=l/2;
       if(l==rope)
       return count;
       if(ropel)
       rope =rope-l;

       find_cuts(l,rope);

   }

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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] Re: Number of Comparisons!

2011-07-03 Thread vaibhav shukla
refer cormen.. chapter 9 ;)

On Sun, Jul 3, 2011 at 3:19 PM, Nitish Garg nitishgarg1...@gmail.comwrote:

 Thanks got it.

 On 7/3/11, sunny agrawal sunny816.i...@gmail.com wrote:
  refer CLRS topic 9.1 Maximum and Minimum page no 184 :)
 
  On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.com
 wrote:
 
  Which chapter of Sartaj Sahni are you referring to?
 
  --
  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/-/rWAgp3fzkrcJ.
 
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.
 
 

 --
 Sent from my mobile device

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.



[algogeeks] Re: help..

2011-07-03 Thread cegprakash
@mohit: nice soln :)

On Jul 2, 2:50 pm, mohit goel mohitgoel291...@gmail.com wrote:
 May be this can work.give any counter example...
 int count;
 main()
 {
       int l,rope,cuts;
       scanf(%d%d,l,rope);
       count =0;

        find_cuts(l,rope);
        printf(cuts needed is %d,count);
        getch();
        return 0;
      }

  int find_cuts(int l,int rope)

  {

     if(l==rope)
     return count;
      count++;
      printf(%d,count);
      l=l/2;
      if(l==rope)
      return count;
      if(ropel)
      rope =rope-l;

      find_cuts(l,rope);

  }

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: help..

2011-07-03 Thread cegprakash
@mohit: a little change in your function to make it work..
  int find_cuts(int l,int rope)

  int find_cuts(int l,int rope)

 {

if(l==rope)
return count;
 count++;
   // printf(%d,count);
 l=l/2;
 if(l==rope)
 return count;
 if(ropel)
 rope =rope-l;

 return find_cuts(l,rope);

 }

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: help..

2011-07-03 Thread cegprakash
@avi dullu: explanation of your code plz..

On Jul 3, 3:57 am, Avi Dullu avi.du...@gmail.com wrote:
 Another alternative soln.

 int rec_cut(int l, int k) {
   if (l == k) return 0;
   int tmp = k - (l1);
   return 1 + rec_cut(l1, tmp = 0 ? k : tmp);

 }

 int main() {
   int l, k;
   scanf(%d%d, l, k);
   printf(%d\n, rec_cut(l, k));
   return 0;

 }

 Veni Vedi Slumber !

 On Sat, Jul 2, 2011 at 9:47 PM, varun pahwa varunpahwa2...@gmail.comwrote:





  @sunny thnx for the correction.

  On Sat, Jul 2, 2011 at 9:16 AM, varun pahwa varunpahwa2...@gmail.comwrote:

  @sunny ya  i wanted to write the while(k % m == 0)

  On Sat, Jul 2, 2011 at 3:47 AM, sameer.mut...@gmail.com 
  sameer.mut...@gmail.com wrote:

  nn-1  is the expression to find out if n is a power of 2...If nn-1
  returns 0 its a power of 2 else its not.
  And what sunny said is also ryt

  On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal 
  sunny816.i...@gmail.comwrote:

  @cegprakash
  Expression resets the least significant set bit

   On Sat, Jul 2, 2011 at 3:20 PM, mohit goel 
  mohitgoel291...@gmail.comwrote:

  May be this can work.give any counter example...
  int count;
  main()
  {
        int l,rope,cuts;
        scanf(%d%d,l,rope);
        count =0;

         find_cuts(l,rope);
         printf(cuts needed is %d,count);
         getch();
         return 0;
         }

   int find_cuts(int l,int rope)

   {

      if(l==rope)
      return count;
       count++;
       printf(%d,count);
       l=l/2;
       if(l==rope)
       return count;
       if(ropel)
       rope =rope-l;

       find_cuts(l,rope);

   }

  --
  You received this message because you are subscribed to the Google
  Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.

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

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

  --
  Varun Pahwa
  B.Tech (IT)
  7th Sem.
  Indian Institute of Information Technology Allahabad.
  Ph : 09793899112 ,08011820777
  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] Re: help..

2011-07-03 Thread cegprakash
i was actually trying this problem..

www.spoj.pl/problems/LQDCANDY

I'm getting WA still..


#includemath.h
#includestdio.h
int cnt;
inline int find_cuts(int l,int rope)
{
if(l==rope)
return cnt;
cnt++;
 l=l/2;
 if(l==rope)
return cnt;
 if(ropel)
rope-=l;

 return find_cuts(l,rope);
}

int main(){
  int t;
  scanf(%d,t);
  while(t--){
 int n,needed;
 scanf(%d,n);
 int x=log2(n);
 int p=(int)pow(2,x);
 if(n!=p)
needed=(int)pow(2,x+1);
 else{
 printf(%d 0\n,n);
 continue;
 }
 if(n%2==1)
printf(%d %d\n,needed,(int)log2(needed));
 else{
   cnt=0;
   printf(%d %d\n,needed,find_cuts(needed,n));

 }
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: help..

2011-07-03 Thread saurabh singh
I think its problem of overflow?
the input data is 10^18.Otherwise the problem is trivial

On Sun, Jul 3, 2011 at 7:02 PM, cegprakash cegprak...@gmail.com wrote:

 i was actually trying this problem..

 www.spoj.pl/problems/LQDCANDY

 I'm getting WA still..


 #includemath.h
 #includestdio.h
 int cnt;
 inline int find_cuts(int l,int rope)
 {
if(l==rope)
return cnt;
cnt++;
  l=l/2;
 if(l==rope)
 return cnt;
 if(ropel)
 rope-=l;

 return find_cuts(l,rope);
 }

 int main(){
  int t;
  scanf(%d,t);
  while(t--){
 int n,needed;
 scanf(%d,n);
 int x=log2(n);
 int p=(int)pow(2,x);
 if(n!=p)
needed=(int)pow(2,x+1);
 else{
 printf(%d 0\n,n);
 continue;
 }
 if(n%2==1)
printf(%d %d\n,needed,(int)log2(needed));
 else{
   cnt=0;
   printf(%d %d\n,needed,find_cuts(needed,n));

 }
  }
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Fwd: anu_test Segmentation fault

2011-07-03 Thread HARSH PAHUJA
-- Forwarded message --
From: HARSH PAHUJA hpahuja.mn...@gmail.com
Date: Sun, Jul 3, 2011 at 8:37 AM
Subject: anu_test Segmentation fault
To: anutest...@googlegroups.com


http://www.ideone.com/QuMcn

plzz help.

y the above program is giving seg fault


#includestdio.h
#includestring.h
#define MAX 2000
//using namespace std;

int minimum(int a,int b,int c)
{
if(ab  ac) return a;
if(bc) return b;
return c;
}

int LevenshteinDistance(char a[], char b[])
{
int d[2000][2000]={0};
int m=0,n=0,i,j;
char s[MAX]=0;
char t[MAX]=0;
strcat(s,a);
strcat(t,b);
m=strlen(s);
n=strlen(t);
printf(%s%s,s,t);
 for(i=0;i=m;i++) d[i][0]=i ;
for(j=0;j=n;j++) d[0][j]=j;

for(j=1;j=n;j++)
{
 for(i=1;i=m;i++)
{
if (s[i] == t[j])
 d[i][j]=d[i-1][j-1];
else
d[i][j]=minimum(d[i-1][j] + (s[i]==t[i]?0:1),d[i][j-1] + 1,d[i-1][j-1] + 1
);
 }

}

return d[m][n];
}


int main()
{
int t,ed;
char s1[MAX],t1[MAX];
scanf(%d,t);
while( t--)
{
scanf(%s%s,s1,t1);
//couts1t1endl;
ed=LevenshteinDistance(s1,t1);
printf(%d\n,ed);
}

return 0;
}

-- 
You received this message because you are subscribed to the Google Groups
anu testing group.
To post to this group, send email to anutest...@googlegroups.com.
To unsubscribe from this group, send email to
anutesting+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/anutesting?hl=en.



-- 
HARSHIT PAHUJA
M.N.N.I.T.
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] Fwd: anu_test Segmentation fault

2011-07-03 Thread Vishal Thanki
Don't allocate too much static memory in stack, it will cause
troubles. You are doing int[2000][2000], i.e. 2000*2000*4 bytes of
memory in stack. Use dynamic memory allocation for such large chunk. I
modified your code as below and it doesn't give seg fault.
#includestdio.h
#include malloc.h
#includestring.h
#define MAX 2000
using namespace std;

int minimum(int a,int b,int c)
{
if(ab  ac) return a;
if(bc) return b;
return c;
}

int LevenshteinDistance(char *a, char *b)
{
int **d;
int m=0,n=0,i,j;
char s[MAX]=0;
char t[MAX]=0;
d = (int **)malloc(MAX*sizeof(int));
for (i=0;iMAX;i++)
d[i] = (int *)malloc(MAX*sizeof(int));
strcat(s,a);
strcat(t,b);
m=strlen(s);
n=strlen(t);
printf(%s%s,s,t);
for(i=0;i=m;i++) d[i][0]=i ;
for(j=0;j=n;j++) d[0][j]=j;

for(j=1;j=n;j++)
{
for(i=1;i=m;i++)
{
if (s[i] == t[j])
d[i][j]=d[i-1][j-1];
else
d[i][j]=minimum(d[i-1][j] + 
(s[i]==t[i]?0:1),d[i][j-1] +
1,d[i-1][j-1] + 1 );
}

}
//TODO: Free d
return d[m][n];
}


int main()
{
int t,ed;
char s1[MAX],t1[MAX];
scanf(%d,t);
while( t--)
{
scanf(%s%s,s1,t1);
//couts1t1endl;
ed=LevenshteinDistance(s1,t1);
printf(%d\n,ed);
}

return 0;
}


On Sun, Jul 3, 2011 at 9:08 PM, HARSH PAHUJA hpahuja.mn...@gmail.com wrote:


 -- Forwarded message --
 From: HARSH PAHUJA hpahuja.mn...@gmail.com
 Date: Sun, Jul 3, 2011 at 8:37 AM
 Subject: anu_test Segmentation fault
 To: anutest...@googlegroups.com


 http://www.ideone.com/QuMcn
 plzz help.
 y the above program is giving seg fault

 #includestdio.h
 #includestring.h
 #define MAX 2000
 //using namespace std;
 int minimum(int a,int b,int c)
 {
 if(ab  ac) return a;
 if(bc) return b;
 return c;
 }
 int LevenshteinDistance(char a[], char b[])
 {
 int d[2000][2000]={0};
 int m=0,n=0,i,j;
 char s[MAX]=0;
 char t[MAX]=0;
 strcat(s,a);
 strcat(t,b);
 m=strlen(s);
 n=strlen(t);
 printf(%s%s,s,t);
 for(i=0;i=m;i++) d[i][0]=i ;
 for(j=0;j=n;j++) d[0][j]=j;
 for(j=1;j=n;j++)
 {
 for(i=1;i=m;i++)
 {
 if (s[i] == t[j])
 d[i][j]=d[i-1][j-1];
 else
 d[i][j]=minimum(d[i-1][j] + (s[i]==t[i]?0:1),d[i][j-1] + 1,d[i-1][j-1] + 1
 );
 }
 }
 return d[m][n];
 }

 int main()
 {
 int t,ed;
 char s1[MAX],t1[MAX];
 scanf(%d,t);
 while( t--)
 {
 scanf(%s%s,s1,t1);
 //couts1t1endl;
 ed=LevenshteinDistance(s1,t1);
 printf(%d\n,ed);
 }
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 anu testing group.
 To post to this group, send email to anutest...@googlegroups.com.
 To unsubscribe from this group, send email to
 anutesting+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/anutesting?hl=en.



 --
 HARSHIT PAHUJA
 M.N.N.I.T.
 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] Fwd: anu_test Segmentation fault

2011-07-03 Thread Shachin Sharma
You might want to try the following:

limit

This will show you the stacksize limit (I believe 1024 KB?)

Execute the following command

unlimit stacksize

This should increase the stacksize and make the program work. The second
thing is I agree with the fact the such huge static allocation shouldnt be
done and it would be better to allocate this chunk dynamically.

Regards,
Shachin

On Sun, Jul 3, 2011 at 9:26 PM, Vishal Thanki vishaltha...@gmail.comwrote:

 Don't allocate too much static memory in stack, it will cause
 troubles. You are doing int[2000][2000], i.e. 2000*2000*4 bytes of
 memory in stack. Use dynamic memory allocation for such large chunk. I
 modified your code as below and it doesn't give seg fault.
 #includestdio.h
 #include malloc.h
 #includestring.h
 #define MAX 2000
 using namespace std;

 int minimum(int a,int b,int c)
 {
if(ab  ac) return a;
if(bc) return b;
return c;
 }

 int LevenshteinDistance(char *a, char *b)
 {
 int **d;
 int m=0,n=0,i,j;
char s[MAX]=0;
char t[MAX]=0;
 d = (int **)malloc(MAX*sizeof(int));
for (i=0;iMAX;i++)
d[i] = (int *)malloc(MAX*sizeof(int));
 strcat(s,a);
strcat(t,b);
m=strlen(s);
n=strlen(t);
printf(%s%s,s,t);
for(i=0;i=m;i++) d[i][0]=i ;
for(j=0;j=n;j++) d[0][j]=j;

for(j=1;j=n;j++)
{
for(i=1;i=m;i++)
{
if (s[i] == t[j])
d[i][j]=d[i-1][j-1];
else
d[i][j]=minimum(d[i-1][j] +
 (s[i]==t[i]?0:1),d[i][j-1] +
 1,d[i-1][j-1] + 1 );
}

}
 //TODO: Free d
 return d[m][n];
 }


 int main()
 {
int t,ed;
char s1[MAX],t1[MAX];
scanf(%d,t);
while( t--)
{
scanf(%s%s,s1,t1);
//couts1t1endl;
ed=LevenshteinDistance(s1,t1);
printf(%d\n,ed);
}

return 0;
 }


 On Sun, Jul 3, 2011 at 9:08 PM, HARSH PAHUJA hpahuja.mn...@gmail.com
 wrote:
 
 
  -- Forwarded message --
  From: HARSH PAHUJA hpahuja.mn...@gmail.com
  Date: Sun, Jul 3, 2011 at 8:37 AM
  Subject: anu_test Segmentation fault
  To: anutest...@googlegroups.com
 
 
  http://www.ideone.com/QuMcn
  plzz help.
  y the above program is giving seg fault
 
  #includestdio.h
  #includestring.h
  #define MAX 2000
  //using namespace std;
  int minimum(int a,int b,int c)
  {
  if(ab  ac) return a;
  if(bc) return b;
  return c;
  }
  int LevenshteinDistance(char a[], char b[])
  {
  int d[2000][2000]={0};
  int m=0,n=0,i,j;
  char s[MAX]=0;
  char t[MAX]=0;
  strcat(s,a);
  strcat(t,b);
  m=strlen(s);
  n=strlen(t);
  printf(%s%s,s,t);
  for(i=0;i=m;i++) d[i][0]=i ;
  for(j=0;j=n;j++) d[0][j]=j;
  for(j=1;j=n;j++)
  {
  for(i=1;i=m;i++)
  {
  if (s[i] == t[j])
  d[i][j]=d[i-1][j-1];
  else
  d[i][j]=minimum(d[i-1][j] + (s[i]==t[i]?0:1),d[i][j-1] + 1,d[i-1][j-1] +
 1
  );
  }
  }
  return d[m][n];
  }
 
  int main()
  {
  int t,ed;
  char s1[MAX],t1[MAX];
  scanf(%d,t);
  while( t--)
  {
  scanf(%s%s,s1,t1);
  //couts1t1endl;
  ed=LevenshteinDistance(s1,t1);
  printf(%d\n,ed);
  }
  return 0;
  }
 
  --
  You received this message because you are subscribed to the Google Groups
  anu testing group.
  To post to this group, send email to anutest...@googlegroups.com.
  To unsubscribe from this group, send email to
  anutesting+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/anutesting?hl=en.
 
 
 
  --
  HARSHIT PAHUJA
  M.N.N.I.T.
  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: Interview Question

2011-07-03 Thread Deoki Nandan
there is no possible solution for this question in less than O(nlgn) time.
As  by theorem given in cormen and solution is possible using xor

On Sun, Jul 3, 2011 at 2:27 PM, Sandeep Jain sandeep6...@gmail.com wrote:

 For case1) yes XOR works,
 for Well, for the other two cases hash-maps may come in handy. :)


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 1:48 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 But i don't think xor method will work at all for all of the cases above
 you mentioned.
 setA = {4,7}
 setB = {5,6}

 - all numbers in both set are nonzero and distinct
 - all numbers are in some range :D
 and for character parts it will similarly failby taking character set
 of ascii values 4,5,6,7

 and about general solution i dont know how to do it in O(n)
 one thing i was thinking of goes this way, taking arrays A and B instead
 of sets.
 if we can prove these polynomial to be same in O(n) time.
 (x-a[0])*(x-a[1])*.*(x-a[n-1]) ==
 (x-b[0])*(x-b[1])*.(x-b[n-1])
 dont know if it can be done efficienty


 On Sun, Jul 3, 2011 at 1:25 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 Agreed, BUT if you don't add a stipulation. You won't be able to reduce
 the complexity.
 For a 100% general solution, I don't think you can reduce the complexity
 more than O(nLgn.)
 There are variations of this question:
 -- All numbers are non-zero and distinct.
 -- All numbers belong to given range
 -- You can also have character's in place of numbers
 In all the above cases, you will have time complexity O(n)

 PS: I'm definitely looking forward to learn a solution, better than
 O(nLgn)



 Regards,
 Sandeep Jain




 On Sun, Jul 3, 2011 at 1:09 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 @sandeep
 SET A - {0,3,4,7}
 SET B - {1,2,5,6}

 xor of all elements is zero
 sum of both the sets is same
 no of elements in both are same

 overall result : all Algorithm posted above Fails

 On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 I was thinking the same, BUT here the question is that we have two
 *SETS* and that's the catch.
 So, XORing all elements of SET A with SET B should result in ZERO only
 when both the set have same elements.


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal 
 meetpranav...@gmail.com wrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.com
  wrote:

 @aditya. xor all elements mean that. take xor of each element of 1st
 array store in a variable that take xor of variable and each element of 
 the
 second array if all elements are common then the variable will be 0 some
 where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont
 think dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal mohitm.1...@gmail.com
  wrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element
 in an array using minimum no of comparisons?Any thing better than 
 O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if
 in both the array set of integers are same but they arnt 
 corresponding to
 each other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.comwrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays
 have the same
  set of ntegers ? Suggest an algo which can run faster than
 NlogN without
  extra space?

 --
 You received this message because you are subscribed to the
 Google Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Mohit Mittal
 4th year , Computer Engineering
 

[algogeeks] Re: Interview Question

2011-07-03 Thread XYZ

Either you will have to use hashmaps which means extra storage or compromise 
on time complexity as nlogn
I dont think there is any other possible workaround!

-- 
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/-/21xV7cUULxcJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] find output

2011-07-03 Thread amit the cool
int main()
{
int a[]={5,10,15,8};
int *x=a;
int y;
y=*x++;
printf(%d,y);
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] find output

2011-07-03 Thread Apoorve Mohan
5

On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.comwrote:

 int main()
 {
int a[]={5,10,15,8};
int *x=a;
int y;
y=*x++;
printf(%d,y);
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
regards

Apoorve Mohan

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Interview Question

2011-07-03 Thread Arpit Sood
Hey,
what is the solution with XOR, methods mentioned above seem to
fail there any reference ?

On Sun, Jul 3, 2011 at 10:39 PM, Deoki Nandan deok...@gmail.com wrote:

 there is no possible solution for this question in less than O(nlgn) time.
 As  by theorem given in cormen and solution is possible using xor


 On Sun, Jul 3, 2011 at 2:27 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 For case1) yes XOR works,
 for Well, for the other two cases hash-maps may come in handy. :)


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 1:48 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 But i don't think xor method will work at all for all of the cases above
 you mentioned.
 setA = {4,7}
 setB = {5,6}

 - all numbers in both set are nonzero and distinct
 - all numbers are in some range :D
 and for character parts it will similarly failby taking character set
 of ascii values 4,5,6,7

 and about general solution i dont know how to do it in O(n)
 one thing i was thinking of goes this way, taking arrays A and B instead
 of sets.
 if we can prove these polynomial to be same in O(n) time.
 (x-a[0])*(x-a[1])*.*(x-a[n-1]) ==
 (x-b[0])*(x-b[1])*.(x-b[n-1])
 dont know if it can be done efficienty


 On Sun, Jul 3, 2011 at 1:25 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 Agreed, BUT if you don't add a stipulation. You won't be able to reduce
 the complexity.
 For a 100% general solution, I don't think you can reduce the complexity
 more than O(nLgn.)
 There are variations of this question:
 -- All numbers are non-zero and distinct.
 -- All numbers belong to given range
 -- You can also have character's in place of numbers
 In all the above cases, you will have time complexity O(n)

 PS: I'm definitely looking forward to learn a solution, better than
 O(nLgn)



 Regards,
 Sandeep Jain




 On Sun, Jul 3, 2011 at 1:09 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 @sandeep
 SET A - {0,3,4,7}
 SET B - {1,2,5,6}

 xor of all elements is zero
 sum of both the sets is same
 no of elements in both are same

 overall result : all Algorithm posted above Fails

 On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain 
 sandeep6...@gmail.comwrote:

 I was thinking the same, BUT here the question is that we have two
 *SETS* and that's the catch.
 So, XORing all elements of SET A with SET B should result in ZERO only
 when both the set have same elements.


 Regards,
 Sandeep Jain





 On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal 
 meetpranav...@gmail.com wrote:

 I think that the above algo will fail for the following two arrays:
 a={2,2,3,3}
 b={4,4,1,1}

 sum(a)=sum(b);
 a^b=0;
 len(a)=len(b);

 Correct me if i am wrong!

 Pranav


 On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa 
 varunpahwa2...@gmail.com wrote:

 @aditya. xor all elements mean that. take xor of each element of 1st
 array store in a variable that take xor of variable and each element 
 of the
 second array if all elements are common then the variable will be 0 
 some
 where.
 var = a[0];
 for(i = 1; i  sizeof(a)/sizeof(a[0]); i++)
 var = var ^ a[i];
 for(i = 0; i  sizeof(b)/sizeof(b[0]); i++)
 var = var ^ b[i];



 On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont
 think dat you can find second largest in less than O(n).


 On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal 
 mohitm.1...@gmail.com wrote:

 Dont think that the corresponding elements should be same.
 XOR Should do it anyway.

 Btw other question How would you find the second largest element
 in an array using minimum no of comparisons?Any thing better than 
 O(n).?


 On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 xor will only result if corresponding elements are same . what if
 in both the array set of integers are same but they arnt 
 corresponding to
 each other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu duman...@gmail.comwrote:

 xor all the elements of both arrays ==0
 sum of 1st array == sum of 2nd array
 no. of elements in 1st == no. of elements in 2nd
 if the above conditions are met, they have the same set.
 m i missin sth?
 On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote:
  Given two arrays of numbers, find if each of the two arrays
 have the same
  set of ntegers ? Suggest an algo which can run faster than
 NlogN without
  extra space?

 --
 You received this message because you are subscribed to the
 Google Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com
 .
 To unsubscribe from 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] array size problem

2011-07-03 Thread Deoki Nandan
WHY?
In C++, you can do something like

const int ArraySize = 100;
int Array[ArraySize];

while in ANSI C, this would be flagged as an error.

-- 
**With Regards
Deoki Nandan Vishwakarma

*
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: array size problem

2011-07-03 Thread Gene
Why do bicycles have 2 wheels and tricycles 3?  The designers made
them that way.

So you're probably asking why they were designed that way.

C++ came after C.  In general C++ seeks to de-emphasize use of the pre-
processor because macro substitution is generally considered to make
maintenance more difficult.

Consequently, in C you would say
#define ArraySize 100
and this will work in C++, too.  But C++ gives you the addtional
preferred way.



On Jul 3, 4:17 pm, Deoki Nandan deok...@gmail.com wrote:
 WHY?
 In C++, you can do something like

 const int ArraySize = 100;
 int Array[ArraySize];

 while in ANSI C, this would be flagged as an error.

 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: VIRTUAL INHERITANCE

2011-07-03 Thread T3rminal
@abc abc
4th class= two ints from X and Y classes + one int from base class( as
this class is shared ) + 2 virtual pointers of X and Y classes.

On Jul 3, 2:24 pm, abc abc may.i.answ...@gmail.com wrote:
 In the second case , the size of vptr will be added to each and every object
 .
 1st class = one int :4
 2nd class = one int +one int from base + vptr =12
 3rd class = one int + one int from base + vptr =12
 4th class =one int from each base class + one int from each of the grand
 parent +one vptr =20

 On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal himanshukansal...@gmail.com







  wrote:
  class Base
  {
       public:
             int a;
  };

  class X:  public Base
  {
       public:
             int x;
  };

  class Y:  public Base
  {
       public:
             int y;
  };

  class Z:public X,public Y
  {
  };

  int main()
  {coutsizeof(Base)endl;
  cout  sizeof(X) endl;
  cout  sizeof(Y) endl;
  cout  sizeof(Z) endl;
  }
  o/p is 4
  8
  8
  16...
  which is absolutely fine.

  but the problem arises here
  class Base
  {
       public:
             int a;
  };

  class X:virtual public Base
  {
       public:
             int x;
  };

  class Y:virtual public Base
  {
       public:
             int y;
  };

  class Z:public X,public Y
  {
  };

  int main()
  {coutsizeof(Base)endl;
  cout  sizeof(X) endl;
  cout  sizeof(Y) endl;
  cout  sizeof(Z) endl;
  }

  o/p is 4
  12
  12
  20
  why the size is 12 and 20 for x and Zdoes this is because that
  some sort of VPTR IS maintained in the classif yes then then what
  does that points to

  PS:HERE.i am talking about virtual inheritanceNOT ABOUT
  VIRTUAL FUNCTIONS...

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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: array size problem

2011-07-03 Thread Navneet Gupta
If you can, refer to Constants chapter in Bruce Eckel. He he smartly
explained how const are different for C  C++.

The e-book is free to download from net.

On Mon, Jul 4, 2011 at 2:50 AM, Gene gene.ress...@gmail.com wrote:
 Why do bicycles have 2 wheels and tricycles 3?  The designers made
 them that way.

 So you're probably asking why they were designed that way.

 C++ came after C.  In general C++ seeks to de-emphasize use of the pre-
 processor because macro substitution is generally considered to make
 maintenance more difficult.

 Consequently, in C you would say
 #define ArraySize 100
 and this will work in C++, too.  But C++ gives you the addtional
 preferred way.



 On Jul 3, 4:17 pm, Deoki Nandan deok...@gmail.com wrote:
 WHY?
 In C++, you can do something like

 const int ArraySize = 100;
 int Array[ArraySize];

 while in ANSI C, this would be flagged as an error.

 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/algogeeks?hl=en.





-- 
--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] Delete a node in a BST!!

2011-07-03 Thread Navneet Gupta
It is a simple algorithm
1) If node has no child, simply delete
2) If node has one child, replace node's data with child's data and
make the subtree child of node, delete child.
3) if node has two child, find the node with min key in right subtree
(or max in left subtree), call it x, replace node's data with x's and
recursively call deleteNode on x.


Since there have been a couple of DS book recos, i would like to add
one which I used and found extremely good. Data Structures in C++ by
Mark Allen Weiss. All frequently used/asked DS algos are present in
that book and more!

Thanks,
Navneet

On Mon, Jul 4, 2011 at 4:58 AM, amit kumar amitthecoo...@gmail.com wrote:
 use cormen

 On Sat, Jul 2, 2011 at 9:14 AM, shady sinv...@gmail.com wrote:

 http://webdocs.cs.ualberta.ca/~holte/T26/del-from-bst.html
 google it there are lot of resources
 On Sat, Jul 2, 2011 at 8:59 AM, sameer.mut...@gmail.com
 sameer.mut...@gmail.com wrote:

 how to Delete a node in a BST. Handle All Test cases.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




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

2011-07-03 Thread Sandeep Jain
Apoorve, please explain the reason for this output as well


Regards,
Sandeep Jain




On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan apoorvemo...@gmail.comwrote:

 5


 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.comwrote:

 int main()
 {
int a[]={5,10,15,8};
int *x=a;
int y;
y=*x++;
printf(%d,y);
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 regards

 Apoorve Mohan


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] find output

2011-07-03 Thread amit kumar
i think d answer sud be 10.
but it comes out to be 5.
xplain plz

On Mon, Jul 4, 2011 at 10:30 AM, Sandeep Jain sandeep6...@gmail.com wrote:

 Apoorve, please explain the reason for this output as well


 Regards,
 Sandeep Jain





 On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan apoorvemo...@gmail.comwrote:

 5


 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.comwrote:

 int main()
 {
int a[]={5,10,15,8};
int *x=a;
int y;
y=*x++;
printf(%d,y);
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 regards

 Apoorve Mohan


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Reverse

2011-07-03 Thread sagar pareek
OK

On Thu, Jun 30, 2011 at 3:14 PM, Anders Ma xuejiao...@gmail.com wrote:

 On Tue, Jun 28, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com
 wrote:
  I have 1 more solution :-
 
  #includestdio.h
  #includestring.h
 
  main()
  {
   int i,j,l;
   char arr[100];
   printf(Enter the string\n);
   fgets(arr,100,stdin);
 
   for(i=0,l=strlen(arr),j=l;i=l/2;i++)
   {
arr[j--]=arr[i];
arr[i]=arr[j];
   }
 
   for(i--;il;i++)
   arr[i]=arr[i+1];
 
   arr[i]='\0';
 
   printf(%s\n,arr);
  }
 
  I hope it will work perfect :)

 it works, but it does need extra space to swap variables, it uses '\0'
 space.
 personally speaking, I prefer to use XOR, it is so cool.  :-)
 --
 Regards
 Anders

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.



Re: [algogeeks] linked list

2011-07-03 Thread sagar pareek
@Anantha Krishnan
Well be specific
just read the question again. it has only to reorder numbers...
what problem will occur if it has more than one data fields
we can traverse with help of digits and then swap all the data fields

On Thu, Jun 30, 2011 at 5:03 PM, Anantha Krishnan 
ananthakrishnan@gmail.com wrote:

 @sagar pareek
 If there are more fields in the node like:

 struct node{
  int data;
  float mark;
  char ch;
  struct node *link;
 };
 Here swapping *data* alone will corrupt the list right!!


 On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.comwrote:

 Here is one approach which works :)

 Traverse the list from a pointer name ptr
 when encounter odd then start traversing from a tmp pointer (start point
 is ptr-next) to find even no. when find it swap the numbers.
 then again start forwarding ptr. If during traversing  ptr==tmp make
 flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
 then tmp=ptr-next else tmp=tmp-next
 do it until tmp or ptr becomes null. :)
 I hope no questions :) :)


 On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000

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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.



Re: [algogeeks] find output

2011-07-03 Thread Anantha Krishnan
y=*x++;
this line executes like this:

y=*x;
x=x+1; // post increment

Regards
Anantha Krishnan

On Mon, Jul 4, 2011 at 10:36 AM, amit kumar amitthecoo...@gmail.com wrote:

 i think d answer sud be 10.
 but it comes out to be 5.
 xplain plz


 On Mon, Jul 4, 2011 at 10:30 AM, Sandeep Jain sandeep6...@gmail.comwrote:

 Apoorve, please explain the reason for this output as well


 Regards,
 Sandeep Jain





 On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan apoorvemo...@gmail.comwrote:

 5


 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool 
 amitthecoo...@gmail.comwrote:

 int main()
 {
int a[]={5,10,15,8};
int *x=a;
int y;
y=*x++;
printf(%d,y);
 }

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 regards

 Apoorve Mohan


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] find output

2011-07-03 Thread Navneet Gupta
I think one rule of thumb for reading pre and post increment operators is

1) For Pre - Increment the value and use it (++x)
2) For Post - Use the value and increment it (x++)

Similar is for pre and post decrement.

I am not very good at commenting the generality of above but in simple
usages like below, the above work well for me.

On Mon, Jul 4, 2011 at 11:21 AM, Anantha Krishnan
ananthakrishnan@gmail.com wrote:
 y=*x++;
 this line executes like this:

 y=*x;
 x=x+1; // post increment
 Regards
 Anantha Krishnan
 On Mon, Jul 4, 2011 at 10:36 AM, amit kumar amitthecoo...@gmail.com wrote:

 i think d answer sud be 10.
 but it comes out to be 5.
 xplain plz

 On Mon, Jul 4, 2011 at 10:30 AM, Sandeep Jain sandeep6...@gmail.com
 wrote:

 Apoorve, please explain the reason for this output as well


 Regards,
 Sandeep Jain




 On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan apoorvemo...@gmail.com
 wrote:

 5

 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.com
 wrote:

 int main()
 {
        int a[]={5,10,15,8};
        int *x=a;
        int y;
        y=*x++;
        printf(%d,y);
 }

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 regards

 Apoorve Mohan

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




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