Re: [algogeeks] Re: Yahoo Question

2011-07-11 Thread sachin sharma
@vaibhav

Overflow problem in case of big number in option b.
the best and simple one is option a.

Best Wishes
Sachin Sharma | Software Trainee | Information Mosaic
New York | Dublin | London | Luxembourg | New Delhi | Singapore | Melbourne
|
e-mail: sachinku...@informationmosaic.com
Web:www.informationmosaic.comhttp://www.informationmosaic.com/ |  t:
www.twitter.com/infomosaic
Winner 2009 Banking Technology Readers' Choice Award for Best Corporate
Actions Automation Solution

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

2011-07-11 Thread Sandeep Jain
Option A: Works on all data types
Option B: Works on numerical data, (best on integral data) but leads to
overflow problem
Option C: XOR would solve the problem of overflow, but afaik bitwise
operators work on integral data


Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 12:03 PM, sachin sharma sachin.bles...@gmail.comwrote:


 @vaibhav

 Overflow problem in case of big number in option b.
 the best and simple one is option a.

 Best Wishes
 Sachin Sharma | Software Trainee | Information Mosaic
 New York | Dublin | London | Luxembourg | New Delhi | Singapore | Melbourne
 |
 e-mail: sachinku...@informationmosaic.com
 Web:www.informationmosaic.comhttp://www.informationmosaic.com/ |  t:
 www.twitter.com/infomosaic
 Winner 2009 Banking Technology Readers' Choice Award for Best Corporate
 Actions Automation Solution

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

2011-07-11 Thread aditya pratap
only first is conditionally independent and other options are used with some
conditions thats why always first one is preferable.

On Mon, Jul 11, 2011 at 12:03 PM, sachin sharma sachin.bles...@gmail.comwrote:


 @vaibhav

 Overflow problem in case of big number in option b.
 the best and simple one is option a.

 Best Wishes
 Sachin Sharma | Software Trainee | Information Mosaic
 New York | Dublin | London | Luxembourg | New Delhi | Singapore | Melbourne
 |
 e-mail: sachinku...@informationmosaic.com
 Web:www.informationmosaic.comhttp://www.informationmosaic.com/ |  t:
 www.twitter.com/infomosaic
 Winner 2009 Banking Technology Readers' Choice Award for Best Corporate
 Actions Automation Solution

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




-- 
Regards
Aditya Pratap
MCA II

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



Re: [algogeeks] Re: Yahoo Question

2011-07-11 Thread aditya pratap
thanks sandeep sir

On Mon, Jul 11, 2011 at 12:16 PM, aditya pratap contacttoadity...@gmail.com
 wrote:

 only first is conditionally independent and other options are used with
 some conditions thats why always first one is preferable.

 On Mon, Jul 11, 2011 at 12:03 PM, sachin sharma 
 sachin.bles...@gmail.comwrote:


 @vaibhav

 Overflow problem in case of big number in option b.
 the best and simple one is option a.

 Best Wishes
 Sachin Sharma | Software Trainee | Information Mosaic
 New York | Dublin | London | Luxembourg | New Delhi | Singapore |
 Melbourne |
 e-mail: sachinku...@informationmosaic.com
 Web:www.informationmosaic.comhttp://www.informationmosaic.com/ |  t:
 www.twitter.com/infomosaic
 Winner 2009 Banking Technology Readers' Choice Award for Best Corporate
 Actions Automation Solution

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




 --
 Regards
 Aditya Pratap
 MCA II




-- 
Regards
Aditya Pratap
MCA II

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



Re: [algogeeks] Re: GOOGLE Q

2011-07-11 Thread surender sanke
Hi, here i maintained two pair of indexes with respect to a and b, reply if
u found any test case which fails..

int npairs()
{
 int a[] = {0,1,4,5,9,11,20};
 int b[] = {0,2,3,6,8,11,15};
 int c[20];
 int len = sizeof(a)/sizeof(a[0]);
 int i1,j1,i2,j2;
 i1=len-1;
 j1=len-2;
 i2=len-2;
 j2=len-1;

 int count = 0;
c[count++] = a[len-1]+b[len-1]; //obvious
 while(count=len)
 {
  if( (a[i1-1]+a[j2-1]  a[i1]+b[j1])   (a[i1-1]+a[j2-1]  a[i1]+b[j1]) )
  {
   c[count++] = a[i1-1]+b[j2-1];  //highest  sum with higher numbers
have exhausted
   i1 = i1-1,j2=j2-1,j1=j2-1,i2=i1-1;
   continue;
  }
  if(a[i1]+b[j1] = a[i2]+b[j2] )
  {
   c[count++] = a[i1]+b[j1];
   j1--;
  }
  else
  {
   c[count++] = a[i2]+b[j2];
   i2--;
  }
 }

 for(int i =0;ilen;i++)
  printf(%d ,c[i]);
 return 0;
}

surender
On Mon, Jul 11, 2011 at 10:46 AM, sunny agrawal sunny816.i...@gmail.comwrote:

 A = 0, 1, 4, 5, 9, 11, 20
 B = 0, 2, 3, 6, 8, 13, 15

 (20, 15)  (20, 15) - (20,15)
 (20,13)   (11,15)  - (20,13)
 (20,8) (11,15)  - (20,8)
 (20,6) (11,15)  - assume (20,6)
 (20,3) (11,15)  - (11,15)
 (20,3) (9,15)- (9,15)
 (20,3) (5,15)- (20,3)  .problem (11,13) has higher value but

 did i missed something ??


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



[algogeeks] c doubt

2011-07-11 Thread geek forgeek
#includestdio.h
main(){int a=10,b;
a=5?b=10:b=20;printf
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}

y this is asking for lvalue
while this(below) not?


#includestdio.h
main(){int a=10,b;
a=5?b=10:(b=20);printf
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}

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



Re: [algogeeks] c doubt

2011-07-11 Thread aditya pratap
this is something like this thats why it is giving lvalue required.
u r going to store the the value over value which is not a variable at left
hand side.

main(){int a=10,b;
(a=5?b=10:b)=20;printf
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}


On Mon, Jul 11, 2011 at 12:47 PM, geek forgeek geekhori...@gmail.comwrote:

 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:b=20;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}

 y this is asking for lvalue
 while this(below) not?


 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:(b=20);printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}


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




-- 
Regards
Aditya Pratap
MCA II

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



Re: [algogeeks] c doubt

2011-07-11 Thread vaibhav shukla
remember in C , the false statement cannot be used for assignment, if u
write it without braces.It is allowed in C++ but not in C
In C compiler would treat it as what aditya has explained.hence the error.

On Mon, Jul 11, 2011 at 12:59 PM, aditya pratap contacttoadity...@gmail.com
 wrote:

 this is something like this thats why it is giving lvalue required.
 u r going to store the the value over value which is not a variable at left
 hand side.


 main(){int a=10,b;
 (a=5?b=10:b)=20;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}



 On Mon, Jul 11, 2011 at 12:47 PM, geek forgeek geekhori...@gmail.comwrote:

 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:b=20;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}

 y this is asking for lvalue
 while this(below) not?


 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:(b=20);printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}


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




 --
 Regards
 Aditya Pratap
 MCA II

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




-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

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



Re: [algogeeks] c doubt

2011-07-11 Thread nicks
@vaibhav.i don't think there is any rule like you mentioned.if it is
plz mention it's source

i think the explanation by aditya is correct it's just due to the precedence
order which is

=
?:
=
in descending order

hence first = is evaluated then ?: followed by =...due to which lvalue
error occurs as constant is on the left side !!
On Mon, Jul 11, 2011 at 2:08 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

 remember in C , the false statement cannot be used for assignment, if u
 write it without braces.It is allowed in C++ but not in C
 In C compiler would treat it as what aditya has explained.hence the error.

 On Mon, Jul 11, 2011 at 12:59 PM, aditya pratap 
 contacttoadity...@gmail.com wrote:

 this is something like this thats why it is giving lvalue required.
 u r going to store the the value over value which is not a variable at
 left hand side.

 main(){int a=10,b;
 (a=5?b=10:b)=20;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}




 On Mon, Jul 11, 2011 at 12:47 PM, geek forgeek geekhori...@gmail.comwrote:

 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:b=20;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}

 y this is asking for lvalue
 while this(below) not?


 #includestdio.h
 main(){int a=10,b;
 a=5?b=10:(b=20);printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(%d\n,b);}


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




 --
 Regards
 Aditya Pratap
 MCA II

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




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


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

2011-07-11 Thread shambo
Find the largest ceil(sqrt(n)) elements of A and B using a sliding window in
time O(n) and then take their cross in time sqrt(n)^2 ie O(n).

--Shambo

On Mon, Jul 11, 2011 at 12:37 PM, surender sanke surend...@gmail.comwrote:

 Hi, here i maintained two pair of indexes with respect to a and b, reply if
 u found any test case which fails..

 int npairs()
 {
  int a[] = {0,1,4,5,9,11,20};
  int b[] = {0,2,3,6,8,11,15};
  int c[20];
  int len = sizeof(a)/sizeof(a[0]);
  int i1,j1,i2,j2;
  i1=len-1;
  j1=len-2;
  i2=len-2;
  j2=len-1;

  int count = 0;
 c[count++] = a[len-1]+b[len-1]; //obvious
  while(count=len)
  {
   if( (a[i1-1]+a[j2-1]  a[i1]+b[j1])   (a[i1-1]+a[j2-1]  a[i1]+b[j1]) )
   {
c[count++] = a[i1-1]+b[j2-1];  //highest  sum with higher numbers
 have exhausted
i1 = i1-1,j2=j2-1,j1=j2-1,i2=i1-1;
continue;
   }
   if(a[i1]+b[j1] = a[i2]+b[j2] )
   {
c[count++] = a[i1]+b[j1];
j1--;
   }
   else
   {
c[count++] = a[i2]+b[j2];
i2--;
   }
  }

  for(int i =0;ilen;i++)
   printf(%d ,c[i]);
  return 0;
 }

 surender
 On Mon, Jul 11, 2011 at 10:46 AM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 A = 0, 1, 4, 5, 9, 11, 20
 B = 0, 2, 3, 6, 8, 13, 15

 (20, 15)  (20, 15) - (20,15)
 (20,13)   (11,15)  - (20,13)
 (20,8) (11,15)  - (20,8)
 (20,6) (11,15)  - assume (20,6)
 (20,3) (11,15)  - (11,15)
 (20,3) (9,15)- (9,15)
 (20,3) (5,15)- (20,3)  .problem (11,13) has higher value but

 did i missed something ??


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

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


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


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



[algogeeks] MS: BST

2011-07-11 Thread aanchal goyal
Given a BST and integer value K. Find all pairs of nodes (x,y), such that
x-data + y-data = K
Time O(n)

Can someone provide a pseudocode/code to solve this using the concept of
 inorder and reverse inorder traversal of BST?
PS: please don't post other solutions for this, I know this can be solved in
other ways too. I am not able to code this using the above concept..
-- 
Regards,*
Aanchal Goyal*.

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



Re: [algogeeks] Re: GOOGLE Q

2011-07-11 Thread DK
@Shambo: That doesn't work.
Consider:
A = 1 10 100 1000
B = 1 2 3 4

The top 4 pairs are: (1000,4), (1000,3), (1000,2) and (1000,1)

--
DK

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

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



Re: [algogeeks] MS: BST

2011-07-11 Thread Piyush Sinha
If we dont want the tree back, we can convert the BST to DLL and do the
job..
On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal goyal.aanch...@gmail.comwrote:

 Given a BST and integer value K. Find all pairs of nodes (x,y), such that
 x-data + y-data = K
 Time O(n)

 Can someone provide a pseudocode/code to solve this using the concept of
  inorder and reverse inorder traversal of BST?
 PS: please don't post other solutions for this, I know this can be solved
 in other ways too. I am not able to code this using the above concept..
 --
 Regards,*
 Aanchal Goyal*.

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




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-07-11 Thread ritu
it has O(n2) solution

take nxn matrix and for every a[j](j=1 to n)  store the d (a[j]-a[i])
value for all i  j
the trick is that d of the longest AP will occur maximum number of
times in matrix

count the maximum occuring d value and reconstruct the sequence by
going through matrix



-Ritu

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

2011-07-11 Thread DK
@Sunny: Thanks for this counterexample. The O(N) algorithm currently seems 
unfeasible to me. 
@Piyush: Are you sure an O(N) algo exists?

Here's an O(N log N) algo (without the N^2 memory requirements of Sunny's 
algo as it doesn't generate duplicates)

For arrays
A = a1 a2 ... an
B = b1 b2  bn

Maintain a max priority_queue ordered by Val(a,b). (Use a BST for this).
Insert (an, bn).

Repeat N Times {
   Pop off and output the max value from the priority queue. Let that be 
(ai, bj) // O(log N)
   if(i == j) {
  Insert (ai-1, bj), (ai, bj-1), (ai-1, bj-1) in the priority queue. // 
O(log n)
   } else if(i  j) {
  Insert (ai-1, bj) in the priority queue. // O(log n)
   } else {
  Insert (ai, bj-1) in the priority queue. // O(log n)
   }
}

Time complexity: O(N log N)
Space complexity: O(N) ??

--
DK

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

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



Re: [algogeeks] MS: BST

2011-07-11 Thread aanchal goyal
we should not deform the tree.
- converting into dll and solving.
- doing inorder and hashing
- doing inorder and saving in array
All above solutions I know, so dont post them,
i dont know how to solve this using inorder and reverse inorder approach..

On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:


 If we dont want the tree back, we can convert the BST to DLL and do the
 job..
 On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal 
 goyal.aanch...@gmail.comwrote:

 Given a BST and integer value K. Find all pairs of nodes (x,y), such that
 x-data + y-data = K
 Time O(n)

 Can someone provide a pseudocode/code to solve this using the concept of
  inorder and reverse inorder traversal of BST?
 PS: please don't post other solutions for this, I know this can be solved
 in other ways too. I am not able to code this using the above concept..
 --
 Regards,*
 Aanchal Goyal*.

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




 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

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



Re: [algogeeks] Re: GOOGLE Q

2011-07-11 Thread Piyush Sinha
@Dk..i dint frame the question buddy...:P

I found it over here
http://geeksforgeeks.org/forum/topic/google-interview-question-for-software-engineerdeveloper-about-algorithms-75

On Mon, Jul 11, 2011 at 3:14 PM, DK divyekap...@gmail.com wrote:

 @Sunny: Thanks for this counterexample. The O(N) algorithm currently seems
 unfeasible to me.
 @Piyush: Are you sure an O(N) algo exists?

 Here's an O(N log N) algo (without the N^2 memory requirements of Sunny's
 algo as it doesn't generate duplicates)

 For arrays
 A = a1 a2 ... an
 B = b1 b2  bn

 Maintain a max priority_queue ordered by Val(a,b). (Use a BST for this).
 Insert (an, bn).

 Repeat N Times {
Pop off and output the max value from the priority queue. Let that be
 (ai, bj) // O(log N)
if(i == j) {
   Insert (ai-1, bj), (ai, bj-1), (ai-1, bj-1) in the priority queue. //
 O(log n)
} else if(i  j) {
   Insert (ai-1, bj) in the priority queue. // O(log n)
} else {
   Insert (ai, bj-1) in the priority queue. // O(log n)
}
 }

 Time complexity: O(N log N)
 Space complexity: O(N) ??

 --
 DK

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

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/XCjyFaTFD-UJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-07-11 Thread deven
Thanks..This link is very useful.

On Jul 10, 11:40 pm, Sandeep Jain sandeep6...@gmail.com wrote:
 http://www.parashift.com/c++-faq-lite/virtual-functions.html
 Its one of my favorite sites... :)

 Regards,
 Sandeep Jain

 On Mon, Jul 11, 2011 at 12:02 AM, himanshu kansal 







 himanshukansal...@gmail.com wrote:
  thanku sir...sir 1 more thngcn u gv a link or some pdf for studying
  virtual inheritance elaborating the vptr mechanism more clearly...

  On Sun, Jul 10, 2011 at 11:56 PM, Sandeep Jain sandeep6...@gmail.comwrote:

  The reason is... that when u write
   a obj1=14;
  it is same as writing a obj1 = a(14);
  So first a temporary object is created using the constructor
  a(int i)
  And this temporary object is passed in the copy constructor. BUT since it
  is temp object it must be referred by a const alias.

  Regards,
  Sandeep Jain

  On Sun, Jul 10, 2011 at 11:52 PM, himanshu kansal 
  himanshukansal...@gmail.com wrote:

  a obj3(obj1);    but this statement works fine.so it means it is
  calling copy constt. perfectly...

  On Sun, Jul 10, 2011 at 11:49 PM, rahul rahulr...@gmail.com wrote:

  my badadd const in copy construcori think...that compiler
  expect...

  On Sun, Jul 10, 2011 at 11:48 PM, rahul rahulr...@gmail.com wrote:

  use a(int arg)
  {
     x = arg;
  }

  ur call will work...:)

  On Sun, Jul 10, 2011 at 11:46 PM, himanshu kansal 
  himanshukansal...@gmail.com wrote:

  class a
  {
         int x;
  public:
         a()
         {
         }
         a(int i){x=i;coutin a xendl;}
         a(a obj){coutin copy cons of aendl;}

  };

  a obj1=14;      //error no matching call to a::a(a)

  why.
  and just adding a const in the constructor  saves me from error...but
  how

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

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

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



Re: [algogeeks] MS: BST

2011-07-11 Thread saurabh singh
Ok lets see.
1-Traverse a pointer right down to the leftmost element,i.e.the
shortest,say small
2-traverse a pointer left down to the rightmost element i.e.the largest.say
large
while(small!=large)
3-Compare their sum.If sumk set large to its successor in reverse
inorder.(I am not sure if u meant the same but I am assuming rev inorder to
be right-node-left)
else set small to its inorder successor.
break when u get the desired k.
print :)
return
if u get out of the loop without getting the number
then such number does not exist.print :(


On Mon, Jul 11, 2011 at 3:16 PM, aanchal goyal goyal.aanch...@gmail.comwrote:

 we should not deform the tree.
 - converting into dll and solving.
 - doing inorder and hashing
 - doing inorder and saving in array
 All above solutions I know, so dont post them,
 i dont know how to solve this using inorder and reverse inorder approach..


 On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:


 If we dont want the tree back, we can convert the BST to DLL and do the
 job..
 On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal 
 goyal.aanch...@gmail.comwrote:

 Given a BST and integer value K. Find all pairs of nodes (x,y), such that
 x-data + y-data = K
 Time O(n)

 Can someone provide a pseudocode/code to solve this using the concept of
  inorder and reverse inorder traversal of BST?
 PS: please don't post other solutions for this, I know this can be solved
 in other ways too. I am not able to code this using the above concept..
 --
 Regards,*
 Aanchal Goyal*.

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




 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

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




-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

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



Re: [algogeeks] MS: BST

2011-07-11 Thread TIRU REDDY
We need all pairs.

Best Regards,
T V Thirumala Reddy




On Mon, Jul 11, 2011 at 3:56 PM, saurabh singh saurab...@gmail.com wrote:

 Ok lets see.
 1-Traverse a pointer right down to the leftmost element,i.e.the
 shortest,say small
 2-traverse a pointer left down to the rightmost element i.e.the
 largest.say large
 while(small!=large)
 3-Compare their sum.If sumk set large to its successor in reverse
 inorder.(I am not sure if u meant the same but I am assuming rev inorder to
 be right-node-left)
 else set small to its inorder successor.
 break when u get the desired k.
 print :)
 return
 if u get out of the loop without getting the number
 then such number does not exist.print :(


 On Mon, Jul 11, 2011 at 3:16 PM, aanchal goyal 
 goyal.aanch...@gmail.comwrote:

 we should not deform the tree.
 - converting into dll and solving.
 - doing inorder and hashing
 - doing inorder and saving in array
 All above solutions I know, so dont post them,
 i dont know how to solve this using inorder and reverse inorder approach..


 On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:


 If we dont want the tree back, we can convert the BST to DLL and do the
 job..
 On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal goyal.aanch...@gmail.com
  wrote:

 Given a BST and integer value K. Find all pairs of nodes (x,y), such
 that x-data + y-data = K
 Time O(n)

 Can someone provide a pseudocode/code to solve this using the concept of
  inorder and reverse inorder traversal of BST?
 PS: please don't post other solutions for this, I know this can be
 solved in other ways too. I am not able to code this using the above
 concept..
 --
 Regards,*
 Aanchal Goyal*.

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




 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD


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


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



Re: [algogeeks] MS: BST

2011-07-11 Thread TIRU REDDY
what is the complexity of your alg?
Best Regards,
T V Thirumala Reddy




On Mon, Jul 11, 2011 at 4:02 PM, TIRU REDDY tiru...@gmail.com wrote:

 We need all pairs.

 Best Regards,
 T V Thirumala Reddy




 On Mon, Jul 11, 2011 at 3:56 PM, saurabh singh saurab...@gmail.comwrote:

 Ok lets see.
 1-Traverse a pointer right down to the leftmost element,i.e.the
 shortest,say small
 2-traverse a pointer left down to the rightmost element i.e.the
 largest.say large
 while(small!=large)
 3-Compare their sum.If sumk set large to its successor in reverse
 inorder.(I am not sure if u meant the same but I am assuming rev inorder to
 be right-node-left)
 else set small to its inorder successor.
 break when u get the desired k.
 print :)
 return
 if u get out of the loop without getting the number
 then such number does not exist.print :(


 On Mon, Jul 11, 2011 at 3:16 PM, aanchal goyal 
 goyal.aanch...@gmail.comwrote:

 we should not deform the tree.
 - converting into dll and solving.
 - doing inorder and hashing
 - doing inorder and saving in array
 All above solutions I know, so dont post them,
 i dont know how to solve this using inorder and reverse inorder
 approach..


 On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:


 If we dont want the tree back, we can convert the BST to DLL and do the
 job..
 On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal 
 goyal.aanch...@gmail.com wrote:

 Given a BST and integer value K. Find all pairs of nodes (x,y), such
 that x-data + y-data = K
 Time O(n)

 Can someone provide a pseudocode/code to solve this using the concept
 of  inorder and reverse inorder traversal of BST?
 PS: please don't post other solutions for this, I know this can be
 solved in other ways too. I am not able to code this using the above
 concept..
 --
 Regards,*
 Aanchal Goyal*.

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




 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD


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




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



Re: [algogeeks] MS: BST

2011-07-11 Thread saurabh singh
Finding the smallest node-o(logn)
Finding the largest node-o(logn)
Finding the Successor.(o(1) (depends if u have the parent pointer in the
tree implementation))
worst case traversal-o(n)
COmplexity o(logn)+o(logn)+o(n*1)=o(n)
correct me if I am wrong.I was never good with calculating complexity,

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

2011-07-11 Thread surender sanke
small mistake change a to b
if( (a[i1-1]+b[j2-1]  a[i1]+b[j1])   (a[i1-1]+a[j2-1]  a[i1]+b[j1]) )

surender
On Mon, Jul 11, 2011 at 3:54 PM, DK divyekap...@gmail.com wrote:

 @surender: Your algo fails. See the counterexample posted by Sunny.

 --
 DK

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

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/ITTX48LIzcUJ.

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

2011-07-11 Thread DK
@Ritu: Your solution is incorrect.

Consider

1 3 41 43 47 49 90 100 110

Maximum repeated 'd' value:
'2' for the pairs (1,3), (41,43), (47,49) = 3 repeats. However, the 
sequences themselves are not part of an AP.
The longest AP is of size 3 - (90, 100, 110) with a d of 10.


--
DK

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

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/FnebaYc_FbIJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] How to store largest N values efficiently

2011-07-11 Thread John Reid
I have a procedure that generates N x M values sequentially. I want to 
store the N largest ones and discard the others. Obviously I can store 
all the values in a vector, sort it when it is full and then choose the 
top N values. Is there a more efficient way using a data structure that 
just stores the top N values as the procedure goes along? Typically M is 
1,000 and N is anywhere from 1,000 to 50,000. I have no prior 
expectation on how the N largest values are distributed amongst the N x 
M values.


I'm working in C++ with the STL and boost libraries.

Thanks for reading this,
John.

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

2011-07-11 Thread abhijith reddy
Wouldn't a heap be ideal for this ?

On Mon, Jul 11, 2011 at 3:35 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote:

 I have a procedure that generates N x M values sequentially. I want to
 store the N largest ones and discard the others. Obviously I can store all
 the values in a vector, sort it when it is full and then choose the top N
 values. Is there a more efficient way using a data structure that just
 stores the top N values as the procedure goes along? Typically M is 1,000
 and N is anywhere from 1,000 to 50,000. I have no prior expectation on how
 the N largest values are distributed amongst the N x M values.

 I'm working in C++ with the STL and boost libraries.

 Thanks for reading this,
 John.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en 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] plz tell how many times loop will execute and why?

2011-07-11 Thread Deoki Nandan
#includeunistd.h
#includestdio.h
#includestdlib.h

int main()
{
int i=0;
pid_t pid;
for( ;i10;i++)
{
pid=fork();
i++;
printf(%d ,pid);
}
}


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



Re: [algogeeks] How to store largest N values efficiently

2011-07-11 Thread saurabh singh
Similar to selection searching problem.

On Mon, Jul 11, 2011 at 4:37 PM, abhijith reddy abhijith200...@gmail.comwrote:

 Wouldn't a heap be ideal for this ?


 On Mon, Jul 11, 2011 at 3:35 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote:

 I have a procedure that generates N x M values sequentially. I want to
 store the N largest ones and discard the others. Obviously I can store all
 the values in a vector, sort it when it is full and then choose the top N
 values. Is there a more efficient way using a data structure that just
 stores the top N values as the procedure goes along? Typically M is 1,000
 and N is anywhere from 1,000 to 50,000. I have no prior expectation on how
 the N largest values are distributed amongst the N x M values.

 I'm working in C++ with the STL and boost libraries.

 Thanks for reading this,
 John.

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


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




-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

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



[algogeeks] Re: How to store largest N values efficiently

2011-07-11 Thread John Reid



On 11/07/11 12:07, abhijith reddy wrote:

Wouldn't a heap be ideal for this ?


I thought it might. Do I just need to limit the heap to size 2 * N to 
avoid storing values I'll never need?


Thanks,
John.




On Mon, Jul 11, 2011 at 3:35 PM, John Reid
j.r...@mail.cryst.bbk.ac.uk
mailto:j.r...@mail.cryst.bbk.ac.uk wrote:

I have a procedure that generates N x M values sequentially. I want
to store the N largest ones and discard the others. Obviously I can
store all the values in a vector, sort it when it is full and then
choose the top N values. Is there a more efficient way using a data
structure that just stores the top N values as the procedure goes
along? Typically M is 1,000 and N is anywhere from 1,000 to 50,000.
I have no prior expectation on how the N largest values are
distributed amongst the N x M values.

I'm working in C++ with the STL and boost libraries.

Thanks for reading this,
John.

--
You received this message because you are subscribed to the Google
Groups Algorithm Geeks group.
To post to this group, send email to
algogeeks@googlegroups.com
mailto:algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscribe@__googlegroups.com
mailto:algogeeks%2bunsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/__group/algogeeks?hl=en
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: How to store largest N values efficiently

2011-07-11 Thread abhijith reddy
You can use priority_queue in STL. The size needs to be limited to N
elements. At any point the the N elements in the heap will give the largest
N
elements processed so far.

On Mon, Jul 11, 2011 at 4:41 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote:



 On 11/07/11 12:07, abhijith reddy wrote:

 Wouldn't a heap be ideal for this ?


 I thought it might. Do I just need to limit the heap to size 2 * N to avoid
 storing values I'll never need?

 Thanks,
 John.



 On Mon, Jul 11, 2011 at 3:35 PM, John Reid
 j.r...@mail.cryst.bbk.ac.uk
 mailto:j.r...@mail.cryst.bbk.**ac.uk j.r...@mail.cryst.bbk.ac.uk
 wrote:

I have a procedure that generates N x M values sequentially. I want
to store the N largest ones and discard the others. Obviously I can
store all the values in a vector, sort it when it is full and then
choose the top N values. Is there a more efficient way using a data
structure that just stores the top N values as the procedure goes
along? Typically M is 1,000 and N is anywhere from 1,000 to 50,000.
I have no prior expectation on how the N largest values are
distributed amongst the N x M values.

I'm working in C++ with the STL and boost libraries.

Thanks for reading this,
John.

--
You received this message because you are subscribed to the Google
Groups Algorithm Geeks group.
To post to this group, send email to
algogeeks@googlegroups.com
mailto:algogeeks@**googlegroups.com algogeeks@googlegroups.com.

To unsubscribe from this group, send email to
algogeeks+unsubscribe@__google**groups.com http://googlegroups.com

 mailto:algogeeks%**2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 **.

For more options, visit this group at

 http://groups.google.com/__**group/algogeeks?hl=enhttp://groups.google.com/__group/algogeeks?hl=en

 http://groups.google.com/**group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/**group/algogeeks?hl=enhttp://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+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Anika Jain
A c code for this is:

int main()
{
int a[2] = {0};
char str[50];
int i,ind=0;
scanf (%s, str);
for(i=0;istrlen(str);i++)
{
if(str[i]='a'  str[i]='z')
{
if(!(a[0]  1str[i]-'a'))
{
a[0] = a[0] | 1str[i]-'a';
str[ind]=str[i];
ind++;
}
}
else if(str[i]='A'  str[i]='Z')
{
if(!(a[1]  1str[i]-'a'))
{
a[1] = a[1] | 1str[i]-'a';
str[ind]=str[i];
ind++;
}
}
}
str[ind]='\0';
printf(%s\n,str);
return 0;
}


is it fine 2 use 2 integers for this? or not allowed??


On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

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

2011-07-11 Thread Anika Jain
*if i have to write a code for finding middle element in a linked list..
then for even length linked which will be the middle element both n/2-1 and
n/2+1 or just n/2+1???

if its both then how can i make my function two elements??
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread saurabh singh
A similar solution has been proposed above if I am not misinterpreting the
code,You are creating a bitmap from the 2 variables.?

On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.com wrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

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



Re: [algogeeks] Re: GOOGLE Q1

2011-07-11 Thread sunny agrawal
@Divye sir
yeah that will work fine if D is in reasonable limits ..

On Mon, Jul 11, 2011 at 4:26 PM, DK divyekap...@gmail.com wrote:

 @Ritu: Your solution is incorrect.

 Consider

 1 3 41 43 47 49 90 100 110

 Maximum repeated 'd' value:
 '2' for the pairs (1,3), (41,43), (47,49) = 3 repeats. However, the
 sequences themselves are not part of an AP.
 The longest AP is of size 3 - (90, 100, 110) with a d of 10.


 --
 DK

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

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/FnebaYc_FbIJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Anika Jain
YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?

On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.com wrote:

 A similar solution has been proposed above if I am not misinterpreting the
 code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Sandeep Jain
Anika, look closely.
Your code takes O(N^2) instead of O(N)


Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 5:15 PM, Anika Jain anika.jai...@gmail.com wrote:

 YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?


 On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.comwrote:

 A similar solution has been proposed above if I am not misinterpreting the
 code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread saurabh singh
The guy who asked the question said one or two variables are fine.So i guess
its fine.

On Mon, Jul 11, 2011 at 5:15 PM, Anika Jain anika.jai...@gmail.com wrote:

 YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?


 On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.comwrote:

 A similar solution has been proposed above if I am not misinterpreting the
 code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


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




-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

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



Re: [algogeeks] c doubt

2011-07-11 Thread Piyush Kapoor
Can anybody give a full explanation


On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 try to find out the binary representation of float value 5.2


 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.com wrote:

 int main(){
 int i;
 float a=5.2;
 char *ptr;
 ptr=(char *)a;
 for(i=0;i=3;i++)
 printf(%d ,*ptr++);
 }

 output:
  102 102 -90 64.explain?

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




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

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



Re: [algogeeks] c doubt

2011-07-11 Thread Sandeep Jain
Sunny is right.
Try to observe the binary representation, and you shall get your answers.


Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.com wrote:

 Can anybody give a full explanation


 On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 try to find out the binary representation of float value 5.2


 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.comwrote:

 int main(){
 int i;
 float a=5.2;
 char *ptr;
 ptr=(char *)a;
 for(i=0;i=3;i++)
 printf(%d ,*ptr++);
 }

 output:
  102 102 -90 64.explain?

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




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

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


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



Re: [algogeeks] MS: BST

2011-07-11 Thread Puneet Ginoria
@saurabh:

finding succesor may not be O(1)... it can be O(logn)

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

2011-07-11 Thread vaibhav shukla
 i have considered it  (n/2+1)th
and didn't bothered much :P


On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.com wrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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




-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

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



Re: [algogeeks] linked list doubt

2011-07-11 Thread chandy jose paul
dnt worry about that write a code in which initialy 2 ptrs .move 1 ptr 2
nodes at a time and other ptr 1 time.when the first ptr reaches end then
seconf ptr will be at middle

On Mon, Jul 11, 2011 at 6:15 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

  i have considered it  (n/2+1)th
 and didn't bothered much :P



 On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.comwrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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


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

2011-07-11 Thread chandy jose paul
use a heap u ill be using a min heap ie the Nth element will be the root.So
when u find a element compare with the root if its greater then replace the
root with this new number and call heapify function

On Mon, Jul 11, 2011 at 4:43 PM, abhijith reddy abhijith200...@gmail.comwrote:

 You can use priority_queue in STL. The size needs to be limited to N
 elements. At any point the the N elements in the heap will give the largest
 N
 elements processed so far.


 On Mon, Jul 11, 2011 at 4:41 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote:



 On 11/07/11 12:07, abhijith reddy wrote:

 Wouldn't a heap be ideal for this ?


 I thought it might. Do I just need to limit the heap to size 2 * N to
 avoid storing values I'll never need?

 Thanks,
 John.



 On Mon, Jul 11, 2011 at 3:35 PM, John Reid
 j.r...@mail.cryst.bbk.ac.uk
 mailto:j.r...@mail.cryst.bbk.**ac.uk j.r...@mail.cryst.bbk.ac.uk
 wrote:

I have a procedure that generates N x M values sequentially. I want
to store the N largest ones and discard the others. Obviously I can
store all the values in a vector, sort it when it is full and then
choose the top N values. Is there a more efficient way using a data
structure that just stores the top N values as the procedure goes
along? Typically M is 1,000 and N is anywhere from 1,000 to 50,000.
I have no prior expectation on how the N largest values are
distributed amongst the N x M values.

I'm working in C++ with the STL and boost libraries.

Thanks for reading this,
John.

--
You received this message because you are subscribed to the Google
Groups Algorithm Geeks group.
To post to this group, send email to
algogeeks@googlegroups.com
mailto:algogeeks@**googlegroups.com algogeeks@googlegroups.com.

To unsubscribe from this group, send email to
algogeeks+unsubscribe@__google**groups.com http://googlegroups.com

 mailto:algogeeks%**2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 **.

For more options, visit this group at

 http://groups.google.com/__**group/algogeeks?hl=enhttp://groups.google.com/__group/algogeeks?hl=en

 http://groups.google.com/**group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/**group/algogeeks?hl=enhttp://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+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en 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] linked list doubt

2011-07-11 Thread vaibhav shukla
moreover n/2-1 will never be the middle element. in case of even no. of
nodes ,middle shall be n/2 and n/2+1

On Mon, Jul 11, 2011 at 6:19 PM, chandy jose paul jpchaa...@gmail.comwrote:

 dnt worry about that write a code in which initialy 2 ptrs .move 1 ptr 2
 nodes at a time and other ptr 1 time.when the first ptr reaches end then
 seconf ptr will be at middle

 On Mon, Jul 11, 2011 at 6:15 PM, vaibhav shukla 
 vaibhav200...@gmail.comwrote:

  i have considered it  (n/2+1)th
 and didn't bothered much :P



 On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.comwrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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


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

2011-07-11 Thread Dave
@John: It seems that a heap size of N would do the trick.

Dave

On Jul 11, 6:11 am, John Reid j.r...@mail.cryst.bbk.ac.uk wrote:
 On 11/07/11 12:07, abhijith reddy wrote:

  Wouldn't a heap be ideal for this ?

 I thought it might. Do I just need to limit the heap to size 2 * N to
 avoid storing values I'll never need?

 Thanks,
 John.





  On Mon, Jul 11, 2011 at 3:35 PM, John Reid
  j.r...@mail.cryst.bbk.ac.uk
  mailto:j.r...@mail.cryst.bbk.ac.uk wrote:

      I have a procedure that generates N x M values sequentially. I want
      to store the N largest ones and discard the others. Obviously I can
      store all the values in a vector, sort it when it is full and then
      choose the top N values. Is there a more efficient way using a data
      structure that just stores the top N values as the procedure goes
      along? Typically M is 1,000 and N is anywhere from 1,000 to 50,000.
      I have no prior expectation on how the N largest values are
      distributed amongst the N x M values.

      I'm working in C++ with the STL and boost libraries.

      Thanks for reading this,
      John.

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

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

 - Show quoted text -

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



Re: [algogeeks] plz tell how many times loop will execute and why?

2011-07-11 Thread vaibhav shukla
try this :

#includeunistd.h
 #includestdio.h
 #includestdlib.h

 int main()
 {
 int i=0,count=0;
 pid_t pid;
 for( ;i10;i++,count++)
 {
 pid=fork();
 i++;
 //printf(%d ,pid);
 }

   printf(count is=%d,count);

 }

 as loop works only five times but each time fork is being invoked,hence
 creating a child process.

so count will be printed 32 times (2^(no. of fork invoked)).
i hope this helps.

 *
 *

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




-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

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



Re: [algogeeks] MS: BST

2011-07-11 Thread Piyush Sinha
@AanchalI think my following algo will work..its a modification of
Morris traversal...check if you can find any bug in it...I have tried my
best to make it error free..For further details regarding Morris traversal,
check out http://geeksforgeeks.org/?p=6358

*void findsum(node *T,int key)
{
 int n = countnodes(T);//returns the number of nodes in the BST
 int i=0;
 int j=n-1;
 node *cur1,*cur2,*p1,*p2;
 cur1=cur2=T;
 int flag1,flag2,sum;
 flag1=flag2=1;
 while(ij)
 {
   if(cur1-left == NULL  cur2-right == NULL)
   {
   sum = checksum(cur1,cur2,key);
   if(sum==0) //if cur1-data + cur2-data ==key
   {
   i++;j--;
   flag1=flag2=1;
   cur1 = cur1-right;
   cur2 = cur2left;
   }
   if(sum0) //if cur1-data + cur2-data  key
   {
   cur2 = cur2-left;
   flag1 = 0; //do not do anything with the left
traversal
   j--;
   }
   if(sum0) //if cur1-data + cur2-data key
   {
   cur1 = cur1-right;
   flag2 = 0;//do not do anything with the right
traversal
   i++;
   }
   }
   else
   {
   if(flag1  cur1-left!=NULL)
   {
   p1 = cur1-left;
   while(p1-right!=NULL  p1-right!=cur1)
p1 = p1-right;
   if(p1-right == NULL)
   {
p1-right = cur1;
cur1 = cur1-left;
   }
   }
   if(flag2  cur2-right!=NULL)
   {
   p2 = cur2-right;
   while(p2-left!=NULL  p2-left!=cur2)
p2 = p2-left;
   if(p2-left == NULL)
   {
p2-left = cur2;
cur2 = cur2-right;
   }
   }
   if(p1-right == cur1 || p2-left == cur2)
   {
   sum = checksum(cur1,cur2,key);
   if(sum==0) //if cur1-data + cur2-data ==key
   {
  if(cur1-left == NULL)
  {
  cur1 = cur1-right;
  flag1 = 0;
  }
  else if(p1-right == cur1)
  {
   p1-right = NULL;
   cur1 = cur1-right;
   flag1 = 1;
  }

  if(cur2-right == NULL)
  {
  cur2 = cur2-left;
  flag2 = 0;
  }
  else if(p2-left == cur2)
  {
   p2-left = NULL;
   cur2 = cur2-left;
   flag2 = 1;
  }
  i++;j--;
   }
   if (sum0) //if cur1-data + cur2-data  key
   {
  if(cur1-left == NULL)
  {
  cur1 = cur1-right;
  flag1 = 0;
  }
  else if(p1-right == cur1)
  {
   p1-right = NULL;
   cur1 = cur1-right;
   flag1 = 1;
  }
  i++;
   }
   if(sum0)//if cur1-data + cur2-data  key
   {
  if(cur2-right == NULL)
  {
  cur2 = cur2-left;
  flag2 = 0;
  }
  else if(p2-left == cur2)
  {
   p2-left = NULL;
   cur2 = cur2-left;
   flag2 = 1;
  }
  j--;
   }
   }
   }
 }

 //final correction of the links can be done again
}

int checksum ( node *c1,node *c2,int key)
{
if(c1-data+c2-data == key)
 return 0;
else if(c1-data+c2-data  key)
 return 1;
else
return -1;
}*



-- 
*Piyush Sinha*
*IIIT, Allahabad*
**
*+91-7483122727*
*Never say NEVER 

Re: [algogeeks] Re: GOOGLE Q1

2011-07-11 Thread Yogesh Yadav
with matrix this problem will be in O(n^2).

We don' have to just check the max number present in matrix. We have to
check as


array a[]= 1,2,3,4,5,6,8,10,12,14

diff[][]=  1  2  3  4  5  6  8  10  12  14
2  0  1  2  3  4  6   8   10  12
3 -1  0  1  2  3  5   79   11
4 -2  -1 0  1  2  4   68   10
5 0
6 0
80
   100
   12  0
   14   0


now in this diff[][] you have to search for if the diff[2][3] =1 then there
should be diff[3][i]=1 and then diff[i][j]=1 ...and so on ...this will give
n A.P of 6 elements

but check for diff[2][4]=2 then diff[4][6]=2 and so on...this will give
an A.P of 7

and its solvable in O(n^2)

On Mon, Jul 11, 2011 at 5:01 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @Divye sir
 yeah that will work fine if D is in reasonable limits ..


 On Mon, Jul 11, 2011 at 4:26 PM, DK divyekap...@gmail.com wrote:

 @Ritu: Your solution is incorrect.

 Consider

 1 3 41 43 47 49 90 100 110

 Maximum repeated 'd' value:
 '2' for the pairs (1,3), (41,43), (47,49) = 3 repeats. However, the
 sequences themselves are not part of an AP.
 The longest AP is of size 3 - (90, 100, 110) with a d of 10.


 --
 DK

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

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/FnebaYc_FbIJ.

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

2011-07-11 Thread raj singh
@yogesh
your code is simple one and excellent to understand;

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] remove duplicate chars in a string without using extra memory

2011-07-11 Thread dinesh bansal
On Sat, May 28, 2011 at 11:32 AM, Rajeev Kumar rajeevprasa...@gmail.com wrote:
 Design an algorithm and write code to remove the duplicate characters in a
 string without using any additional buffer.
  NOTE: One or two additional variables are fine.
  An extra copy of the array is not.

 --
 Thank You
 Rajeev Kumar

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


I have a solution. Please check whether is fits the requirement:

#includeunistd.h
#includestdio.h
#includestdlib.h

int main()
{
char input[256], ele;
int i, j, size;
printf(Enter input string::);
scanf(%s,input);
size = strlen(input);
for(i = 0; i size; i++) {
if(input[i])
ele = input[i];
else
continue;
for(j=i+1; j  size; j++) {
input[j] ^= ele;
if(input[j]) {
input[j] ^= ele;
}
}
}
for(i=0; i  size;i++)
printf(%c,input[i]);
}


-- 
Dinesh Bansal
The Law of Win says, Let's not do it your way or my way; let's do it
the best way.

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



Re: [algogeeks] MS: BST

2011-07-11 Thread aanchal goyal
@Piyush..
I tried your algo on BST {5,4,6,3,2,1,8,7,10,12,9,11}.
Its only returning 1+7.
Other pairs are 5+3, 6+2.

On Mon, Jul 11, 2011 at 6:56 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 @AanchalI think my following algo will work..its a modification of
 Morris traversal...check if you can find any bug in it...I have tried my
 best to make it error free..For further details regarding Morris traversal,
 check out http://geeksforgeeks.org/?p=6358

 *void findsum(node *T,int key)
 {
  int n = countnodes(T);//returns the number of nodes in the BST
  int i=0;
  int j=n-1;
  node *cur1,*cur2,*p1,*p2;
  cur1=cur2=T;
  int flag1,flag2,sum;
  flag1=flag2=1;
  while(ij)
  {
if(cur1-left == NULL  cur2-right == NULL)
{
sum = checksum(cur1,cur2,key);
if(sum==0) //if cur1-data + cur2-data ==key
{
i++;j--;
flag1=flag2=1;
cur1 = cur1-right;
cur2 = cur2left;
}
if(sum0) //if cur1-data + cur2-data  key
{
cur2 = cur2-left;
flag1 = 0; //do not do anything with the left
 traversal
j--;
}
if(sum0) //if cur1-data + cur2-data key
{
cur1 = cur1-right;
flag2 = 0;//do not do anything with the right
 traversal
i++;
}
}
else
{
if(flag1  cur1-left!=NULL)
{
p1 = cur1-left;
while(p1-right!=NULL  p1-right!=cur1)
 p1 = p1-right;
if(p1-right == NULL)
{
 p1-right = cur1;
 cur1 = cur1-left;
}
}
if(flag2  cur2-right!=NULL)
{
p2 = cur2-right;
while(p2-left!=NULL  p2-left!=cur2)
 p2 = p2-left;
if(p2-left == NULL)
{
 p2-left = cur2;
 cur2 = cur2-right;
}
}
if(p1-right == cur1 || p2-left == cur2)
{
sum = checksum(cur1,cur2,key);
if(sum==0) //if cur1-data + cur2-data ==key
{
   if(cur1-left == NULL)
   {
   cur1 = cur1-right;
   flag1 = 0;
   }
   else if(p1-right == cur1)
   {
p1-right = NULL;
cur1 = cur1-right;
flag1 = 1;
   }

   if(cur2-right == NULL)
   {
   cur2 = cur2-left;
   flag2 = 0;
   }
   else if(p2-left == cur2)
   {
p2-left = NULL;
cur2 = cur2-left;
flag2 = 1;
   }
   i++;j--;
}
if (sum0) //if cur1-data + cur2-data  key
{
   if(cur1-left == NULL)
   {
   cur1 = cur1-right;
   flag1 = 0;
   }
   else if(p1-right == cur1)
   {
p1-right = NULL;
cur1 = cur1-right;
flag1 = 1;
   }
   i++;
}
if(sum0)//if cur1-data + cur2-data  key
{
   if(cur2-right == NULL)
   {
   cur2 = cur2-left;
   flag2 = 0;
   }
   else if(p2-left == cur2)
   {
p2-left = NULL;
cur2 = cur2-left;
flag2 = 1;
   }
   j--;
}
}
}
  }

  //final 

Re: [algogeeks] Re: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Anika Jain
@sandeep sir: i didnt get it how is it takin o(n^2) ??

On Mon, Jul 11, 2011 at 5:18 PM, Sandeep Jain sandeep6...@gmail.com wrote:

 Anika, look closely.
 Your code takes O(N^2) instead of O(N)


 Regards,
 Sandeep Jain




 On Mon, Jul 11, 2011 at 5:15 PM, Anika Jain anika.jai...@gmail.comwrote:

 YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?


 On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.comwrote:

 A similar solution has been proposed above if I am not misinterpreting
 the code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


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


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


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



[algogeeks] Re: Largest BST subtree in Binary Tree

2011-07-11 Thread vigneshr
@Harsha, Yes!, the bottom up approach is the best and avoids lot of
repeated calculations.

Cheers,
Vignesh

On Jul 11, 10:13 am, Harshal hc4...@gmail.com wrote:
 @vigneshr, no your method is not that efficient since you will be calling
 IsBST for a node many times in the process. It will be O(nlogn) assuming
 complete Binary Tree, Sunny's algorithm runs in O(n) time.









 On Sun, Jul 10, 2011 at 11:25 PM, vigneshr rvignesh1...@gmail.com wrote:
  I donno if my idea is efficient.
  I'll do a breath-first traversal and check IsBST on each node(modified
  to also get the count of nodes)
  So at each level, the largest BST is kept track of and end of the
  level, the largest subtree can be returned.
  If there is no BST at that level go down one level more.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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 Regards,
 Harshal Choudhary
 7th Semester, CSE Dept.
 NIT Surathkal, India.
 The road to knowledge runs through the land of confusion.

 Mobile: +91 9844667142
 Email : hc4...@gmail.com
 http://www.facebook.com/profile.php?id=1518764305
 https://twitter.com/#!/harshal4342
   http://www.linkedin.com/pub/harshal-choudhary/17/731/291
 http://kkoolharshal.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Sandeep Jain
Hint: What is the time complexity of strlen??


Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 8:00 PM, Anika Jain anika.jai...@gmail.com wrote:

 @sandeep sir: i didnt get it how is it takin o(n^2) ??


 On Mon, Jul 11, 2011 at 5:18 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 Anika, look closely.
 Your code takes O(N^2) instead of O(N)


 Regards,
 Sandeep Jain




 On Mon, Jul 11, 2011 at 5:15 PM, Anika Jain anika.jai...@gmail.comwrote:

 YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?


 On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.comwrote:

 A similar solution has been proposed above if I am not misinterpreting
 the code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


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

2011-07-11 Thread raj singh
1.using temporary variable method is the best as it is applicable to all
datatype.

2.using airthmatic expresion:-  problem arise if we r swap the value using
pointer and both pointer point to same location
   let  int *x and int *y both point to a=20;
   now we write a method swap
  void swap(int *x,int *y)
  {
 *x=*x+*y;  //20+20=40
 *y=*x-*y;  //40-40=0;
  *x=*x-*y;// 0-0=0
  }

In this case this method fail since x and y both point to a=20;and result
become 0;

3.same problem arise in bitwise xor opertor.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: remove duplicate chars in a string without using extra memory

2011-07-11 Thread Anika Jain
ohh ok! got it!

On Mon, Jul 11, 2011 at 8:05 PM, Sandeep Jain sandeep6...@gmail.com wrote:

 Hint: What is the time complexity of strlen??


 Regards,
 Sandeep Jain



 On Mon, Jul 11, 2011 at 8:00 PM, Anika Jain anika.jai...@gmail.comwrote:

 @sandeep sir: i didnt get it how is it takin o(n^2) ??


 On Mon, Jul 11, 2011 at 5:18 PM, Sandeep Jain sandeep6...@gmail.comwrote:

 Anika, look closely.
 Your code takes O(N^2) instead of O(N)


 Regards,
 Sandeep Jain




 On Mon, Jul 11, 2011 at 5:15 PM, Anika Jain anika.jai...@gmail.comwrote:

 YA.. N YA M USING 2 VARIABLES.. IS IT ALLOWED?


 On Mon, Jul 11, 2011 at 4:58 PM, saurabh singh saurab...@gmail.comwrote:

 A similar solution has been proposed above if I am not misinterpreting
 the code,You are creating a bitmap from the 2 variables.?


 On Mon, Jul 11, 2011 at 4:55 PM, Anika Jain anika.jai...@gmail.comwrote:


 A c code for this is:

 int main()
 {
 int a[2] = {0};
 char str[50];
 int i,ind=0;
 scanf (%s, str);
 for(i=0;istrlen(str);i++)
 {

 if(str[i]='a'  str[i]='z')
 {
 if(!(a[0]  1str[i]-'a'))
 {
 a[0] = a[0] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 else if(str[i]='A'  str[i]='Z')
 {
 if(!(a[1]  1str[i]-'a'))
 {
 a[1] = a[1] | 1str[i]-'a';
 str[ind]=str[i];
 ind++;
 }
 }
 }
 str[ind]='\0';

 printf(%s\n,str);
 return 0;
 }


 is it fine 2 use 2 integers for this? or not allowed??



 On Mon, Jul 11, 2011 at 9:35 AM, Yaw yawbrob...@gmail.com wrote:

 Quite new to java what do you think of mine?

 import java.util.*;

 public class RemoveDuplicates {


 public static void main(String[] args){
 while(true) {
 System.out.println(Enter String);
 Scanner input = new Scanner(System.in);
 String str = input.nextLine();
 System.out.println(RemoveDup(str));
 }
 }

 public static String RemoveDup(String str){
 str = str.toLowerCase();
 String temp = ;
  for (int i=0; istr.length(); i++){
  if (!temp.contains(Character.toString(str.charAt(i{
  temp+=str.charAt(i);
  }

  }
  return temp;


 }

 }




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

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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




 --
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD



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


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

[algogeeks] a general problem

2011-07-11 Thread syl
i was seeing a question on spojhttps://www.spoj.pl/problems/
SUMMUL/
regarding this question could anyone tell me how to go about this
one...
any help or hint is appreciated.

Thanks!!

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



Re: [algogeeks] MS: BST

2011-07-11 Thread Piyush Sinha
@Anchalthanks for pointing out the error...i found where the error
is...it is the else loop in this line in this checking...

if(p1-right == cur1 || p2-left == cur2)

actually before i have already assigned p1-right == cur1 (or
p2-left=cur2)..it shud have been in else loop..soryy for the
mistake..i will submit the modification asap..

On 7/11/11, aanchal goyal goyal.aanch...@gmail.com wrote:
 @Piyush..
 I tried your algo on BST {5,4,6,3,2,1,8,7,10,12,9,11}.
 Its only returning 1+7.
 Other pairs are 5+3, 6+2.

 On Mon, Jul 11, 2011 at 6:56 PM, Piyush Sinha
 ecstasy.piy...@gmail.comwrote:

 @AanchalI think my following algo will work..its a modification of
 Morris traversal...check if you can find any bug in it...I have tried my
 best to make it error free..For further details regarding Morris
 traversal,
 check out http://geeksforgeeks.org/?p=6358

 *void findsum(node *T,int key)
 {
  int n = countnodes(T);//returns the number of nodes in the BST
  int i=0;
  int j=n-1;
  node *cur1,*cur2,*p1,*p2;
  cur1=cur2=T;
  int flag1,flag2,sum;
  flag1=flag2=1;
  while(ij)
  {
if(cur1-left == NULL  cur2-right == NULL)
{
sum = checksum(cur1,cur2,key);
if(sum==0) //if cur1-data + cur2-data ==key
{
i++;j--;
flag1=flag2=1;
cur1 = cur1-right;
cur2 = cur2left;
}
if(sum0) //if cur1-data + cur2-data  key
{
cur2 = cur2-left;
flag1 = 0; //do not do anything with the left
 traversal
j--;
}
if(sum0) //if cur1-data + cur2-data key
{
cur1 = cur1-right;
flag2 = 0;//do not do anything with the right
 traversal
i++;
}
}
else
{
if(flag1  cur1-left!=NULL)
{
p1 = cur1-left;
while(p1-right!=NULL  p1-right!=cur1)
 p1 = p1-right;
if(p1-right == NULL)
{
 p1-right = cur1;
 cur1 = cur1-left;
}
}
if(flag2  cur2-right!=NULL)
{
p2 = cur2-right;
while(p2-left!=NULL  p2-left!=cur2)
 p2 = p2-left;
if(p2-left == NULL)
{
 p2-left = cur2;
 cur2 = cur2-right;
}
}
if(p1-right == cur1 || p2-left == cur2)
{
sum = checksum(cur1,cur2,key);
if(sum==0) //if cur1-data + cur2-data ==key
{
   if(cur1-left == NULL)
   {
   cur1 = cur1-right;
   flag1 = 0;
   }
   else if(p1-right == cur1)
   {
p1-right = NULL;
cur1 = cur1-right;
flag1 = 1;
   }

   if(cur2-right == NULL)
   {
   cur2 = cur2-left;
   flag2 = 0;
   }
   else if(p2-left == cur2)
   {
p2-left = NULL;
cur2 = cur2-left;
flag2 = 1;
   }
   i++;j--;
}
if (sum0) //if cur1-data + cur2-data  key
{
   if(cur1-left == NULL)
   {
   cur1 = cur1-right;
   flag1 = 0;
   }
   else if(p1-right == cur1)
   {
p1-right = NULL;
cur1 = cur1-right;
flag1 = 1;
   }
   i++;
}
if(sum0)//if cur1-data + cur2-data  key
{
   if(cur2-right == NULL)
   {
   cur2 = cur2-left;
   flag2 = 

Re: [algogeeks] MS: BST

2011-07-11 Thread Piyush Sinha
Check this one once..I hope it will work now..I hv introduced two more
variables check1 and check2
*
void findsum(node *T,int key)
{
 int n = countnodes(T);//returns the number of nodes in the BST
 int i=0;
 int j=n-1;
 node *cur1,*cur2,*p1,*p2;
 cur1=cur2=T;
 int flag1,flag2,sum;
 flag1=flag2=1;
 int check1,check2;
 check1=check2=0;
 while(ij)
 {
   if(cur1-left == NULL  cur2-right == NULL)
   {
   sum = checksum(cur1,cur2,key);
   if(sum==0) //if cur1-data + cur2-data ==key
   {
   i++;j--;
   flag1=flag2=1;
   cur1 = cur1-right;
   cur2 = cur2left;
   }
   if(sum0) //if cur1-data + cur2-data  key
   {
   cur2 = cur2-left;
   flag1 = 0; //do not do anything with the left
traversal
   j--;
   check1 = 1;
   }
   if(sum0) //if cur1-data + cur2-data key
   {
   cur1 = cur1-right;
   flag2 = 0;//do not do anything with the right
traversal
   i++;
   check2 = 1;
   }
   }
   else
   {
   if(flag1  cur1-left!=NULL)
   {
   p1 = cur1-left;
   while(p1-right!=NULL  p1-right!=cur1)
p1 = p1-right;
   if(p1-right == NULL)
   {
p1-right = cur1;
cur1 = cur1-left;
check1 = 0;
   }
   else // p1-right = cur1
   check1 = 1;
   }
   if(flag2  cur2-right!=NULL)
   {
   p2 = cur2-right;
   while(p2-left!=NULL  p2-left!=cur2)
p2 = p2-left;
   if(p2-left == NULL)
   {
p2-left = cur2;
cur2 = cur2-right;
check2 = 0;
   }
   else //p2-left = cur2
   check2 = 1;
   }
   if(check1  check2)
   {
   sum = checksum(cur1,cur2,key);
   if(sum==0) //if cur1-data + cur2-data ==key
   {
  if(cur1-left == NULL)
  {
  cur1 = cur1-right;
  flag1 = 0;
  }
  else if(p1-right == cur1)
  {
   p1-right = NULL;
   cur1 = cur1-right;
   flag1 = 1;
  }

  if(cur2-right == NULL)
  {
  cur2 = cur2-left;
  flag2 = 0;
  }
  else if(p2-left == cur2)
  {
   p2-left = NULL;
   cur2 = cur2-left;
   flag2 = 1;
  }
  i++;j--;
   }
   if (sum0) //if cur1-data + cur2-data  key
   {
  if(cur1-left == NULL)
  {
  cur1 = cur1-right;
  flag1 = 0;
  }
  else if(p1-right == cur1)
  {
   p1-right = NULL;
   cur1 = cur1-right;
   flag1 = 1;
  }
  i++;
   }
   if(sum0)//if cur1-data + cur2-data  key
   {
  if(cur2-right == NULL)
  {
  cur2 = cur2-left;
  flag2 = 0;
  }
  else if(p2-left == cur2)
  {
   p2-left = NULL;
   cur2 = cur2-left;
   flag2 = 1;
  }
  j--;
   }
   }
   }
 }

 //final correction of the links can be done again
}

int checksum ( node *c1,node *c2,int key)
{
if(c1-data+c2-data == key)
 return 0;

Re: [algogeeks] Re: GOOGLE Q1

2011-07-11 Thread DK
@Yogi: Your algo (though it seems N^2) is actually N^3.

According to your algorithm, you need to have a loop to select the starting 
value of the common difference of the AP.
As per what you've written, an implementation is:

for all distinct d values in the diff matrix { // O(N^2) loop
   Let location of d value be (i, j)
   length = 2;
repeat:
   for k in range (j...N-1) { // O(N) loop
   if(diff[j][k] == d) {
   length++;
   j = k;
   goto repeat;
   }
   }
}

The time complexity of this solution is O(number of distinct d values x 
(length of sequence - 1) x N).
For the case that all the diff values are distinct, the time complexity of 
this solution is O(N^3) (since length of sequence will be 2)
Please let me know if you have a way to implement this faster than O(N^3) or 
an alteration of the algorithm that brings down the complexity to O(N^2).
Alternatively, if you believe that this algo is O(N^2), could you please 
provide a complexity analysis supporting that?

--
DK

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

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



Re: [algogeeks] MS

2011-07-11 Thread Yogesh Yadav
largest size of square would be = H.C.F of width and height .

now with size known we have to just arrange squares

this can be done such that we can make a big square by adding them...

for ex 1st square can be made by just (1 square)
 2nd square can be made by adding 3 sqaures around it like 1
2  //suppose 2,3,4 are newly addded squares

4 3
 3rd square can be made by adding 5 sqaures around it like  1 2 5

3 4 6

9 8 7
 4th square can be made by adding 7 sqaures around it like   1 2 5
10

3 4 6 11

9 8 7 12

13141516 and so on

so we have to first check the no of squares and try to make largest possible
square... and then we can add rest around it anywhere

in this case height =3, width=2 so HCF=1

hence side of square will be 1

and n=5 given ...so largest possible square can be of 4 and rest can be
added around it...






On Sun, Jul 10, 2011 at 10:44 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

 with n=(height*width)/side^2 .. u can calculate the side if n would be
 given.


 On Sun, Jul 10, 2011 at 10:37 PM, vaibhav agarwal 
 vibhu.bitspil...@gmail.com wrote:

 @vaibhav this fails as n will be provided in the question.


 On Sun, Jul 10, 2011 at 9:56 PM, vaibhav shukla 
 vaibhav200...@gmail.comwrote:

 wastage can be minimized if side of square is maximized.
 so largest size of square would be = H.C.F of width and height .

 and also number of squares needed will be = (width*height)/side^2 .



 On Sun, Jul 10, 2011 at 9:11 PM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 Given a rectangle with known width and height, design an algorithms to
 fill the rectangle using n squares(n is integer, also given) and make sure
 in the result the wasting area is minimized. Length of square doesn't have
 to be integer.
 I.e, given width=3,height=2,n=5, one solution is that rectangle can be
 filled with five 1x1 squares and the wasting area is 1. Another solution
 could be filled with five 0.9x0.9 squares, but the wasting area is more 
 than
 first solution.

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


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


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



Re: [algogeeks] MS

2011-07-11 Thread Yogesh Yadav
largest size of square would be = H.C.F of width and height .

now with size known we have to just arrange squares

this can be done such that we can make a big square by adding them...

for ex 1st square can be made by just (1 square)
 2nd square can be made by adding 3 sqaures around it like 1
2  //suppose 2,3,4 are newly addded  squares

4 3
 3rd square can be made by adding 5 sqaures around it like  1 2 5

3 4 6

9 8 7
 4th square can be made by adding 7 sqaures around it like   1 2 5
10

3 4 6 11

9 8 7 12

13141516 and so on

so we have to first check the no of squares and try to make largest possible
square...*we have to check also that the largest possible square should not
exceed either length or breadth.*.. and then we can add rest around it
anywhere

in this case height =3, width=2 so HCF=1

hence side of square will be 1

and n=5 given ...so largest possible square can be of 4 and rest can be
added around it...


On Sun, Jul 10, 2011 at 10:44 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

 with n=(height*width)/side^2 .. u can calculate the side if n would be
 given.


 On Sun, Jul 10, 2011 at 10:37 PM, vaibhav agarwal 
 vibhu.bitspil...@gmail.com wrote:

 @vaibhav this fails as n will be provided in the question.


 On Sun, Jul 10, 2011 at 9:56 PM, vaibhav shukla 
 vaibhav200...@gmail.comwrote:

 wastage can be minimized if side of square is maximized.
 so largest size of square would be = H.C.F of width and height .

 and also number of squares needed will be = (width*height)/side^2 .



 On Sun, Jul 10, 2011 at 9:11 PM, Akshata Sharma 
 akshatasharm...@gmail.com wrote:

 Given a rectangle with known width and height, design an algorithms to
 fill the rectangle using n squares(n is integer, also given) and make sure
 in the result the wasting area is minimized. Length of square doesn't have
 to be integer.
 I.e, given width=3,height=2,n=5, one solution is that rectangle can be
 filled with five 1x1 squares and the wasting area is 1. Another solution
 could be filled with five 0.9x0.9 squares, but the wasting area is more 
 than
 first solution.

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


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


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

2011-07-11 Thread Ankur Khurana
if we are using strncpy( destination ,  source , num_of_char)

then if destination have less space allocated than num_of_char , what will
happen ?

Also , if there is no null char after string, what will happen , puts(str)
//where str is the string wihtout NULL character . I was not able to find
any reference regarding these doubts . Any suggestion or readable material ?

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

2011-07-11 Thread ●αηυяαg ∩ ℓιƒє ≈ Φ
Perform an inorder traversal store in array A={x : x is a node val in
BST }  and in array B={K-x : x is a node val in BST}.Reverse B
because it's descending.
Now merge arrays A and B to array C. Repeated elements in C notify the
pair(x,K-x) which add up to K. memory=O(n) time=O(n).

Plz comment.

On Jul 11, 8:23 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote:
 Check this one once..I hope it will work now..I hv introduced two more
 variables check1 and check2
 *
 void findsum(node *T,int key)
 {
      int n = countnodes(T);//returns the number of nodes in the BST
      int i=0;
      int j=n-1;
      node *cur1,*cur2,*p1,*p2;
      cur1=cur2=T;
      int flag1,flag2,sum;
      flag1=flag2=1;
      int check1,check2;
      check1=check2=0;
      while(ij)
      {
                if(cur1-left == NULL  cur2-right == NULL)
                {
                    sum = checksum(cur1,cur2,key);
                    if(sum==0) //if cur1-data + cur2-data ==key
                    {
                        i++;j--;
                        flag1=flag2=1;
                        cur1 = cur1-right;
                        cur2 = cur2left;
                    }
                    if(sum0) //if cur1-data + cur2-data  key
                    {
                        cur2 = cur2-left;
                        flag1 = 0; //do not do anything with the left
 traversal
                        j--;
                        check1 = 1;
                    }
                    if(sum0) //if cur1-data + cur2-data key
                    {
                        cur1 = cur1-right;
                        flag2 = 0;//do not do anything with the right
 traversal
                        i++;
                        check2 = 1;
                    }
                }
                else
                {
                    if(flag1  cur1-left!=NULL)
                    {
                        p1 = cur1-left;
                        while(p1-right!=NULL  p1-right!=cur1)
                             p1 = p1-right;
                        if(p1-right == NULL)
                        {
                             p1-right = cur1;
                             cur1 = cur1-left;
                             check1 = 0;
                        }
                        else // p1-right = cur1
                            check1 = 1;
                    }
                    if(flag2  cur2-right!=NULL)
                    {
                        p2 = cur2-right;
                        while(p2-left!=NULL  p2-left!=cur2)
                             p2 = p2-left;
                        if(p2-left == NULL)
                        {
                             p2-left = cur2;
                             cur2 = cur2-right;
                             check2 = 0;
                        }
                        else //p2-left = cur2
                            check2 = 1;
                    }
                    if(check1  check2)
                    {
                        sum = checksum(cur1,cur2,key);
                        if(sum==0) //if cur1-data + cur2-data ==key
                        {
                           if(cur1-left == NULL)
                           {
                               cur1 = cur1-right;
                               flag1 = 0;
                           }
                           else if(p1-right == cur1)
                           {
                                p1-right = NULL;
                                cur1 = cur1-right;
                                flag1 = 1;
                           }

                           if(cur2-right == NULL)
                           {
                               cur2 = cur2-left;
                               flag2 = 0;
                           }
                           else if(p2-left == cur2)
                           {
                                p2-left = NULL;
                                cur2 = cur2-left;
                                flag2 = 1;
                           }
                           i++;j--;
                        }
                        if (sum0) //if cur1-data + cur2-data  key
                        {
                           if(cur1-left == NULL)
                           {
                               cur1 = cur1-right;
                               flag1 = 0;
                           }
                           else if(p1-right == cur1)
                           {
                                p1-right = NULL;
                                cur1 = cur1-right;
                                flag1 = 1;
                           }
                           i++;
                        }
                        if(sum0)//if cur1-data + cur2-data  key
                        {
                           if(cur2-right == NULL)
                           {
                               cur2 = cur2-left;
                               flag2 = 0;
                           }
                

Re: [algogeeks] Basic String Queries

2011-07-11 Thread Kamakshii Aggarwal
puts(str) will print the string copied even if it has no null character.
also strncpy will not create any problem

On Mon, Jul 11, 2011 at 10:19 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote:

 if we are using strncpy( destination ,  source , num_of_char)

 then if destination have less space allocated than num_of_char , what will
 happen ?

 Also , if there is no null char after string, what will happen , puts(str)
 //where str is the string wihtout NULL character . I was not able to find
 any reference regarding these doubts . Any suggestion or readable material ?



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

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

2011-07-11 Thread Kamakshii Aggarwal
the output is compiler dependent..

On Mon, Jul 11, 2011 at 10:29 PM, Kamakshii Aggarwal
kamakshi...@gmail.comwrote:


 puts(str) will print the string copied even if it has no null character.
 also strncpy will not create any problem


 On Mon, Jul 11, 2011 at 10:19 PM, Ankur Khurana 
 ankur.kkhur...@gmail.comwrote:

 if we are using strncpy( destination ,  source , num_of_char)

 then if destination have less space allocated than num_of_char , what will
 happen ?

 Also , if there is no null char after string, what will happen , puts(str)
 //where str is the string wihtout NULL character . I was not able to find
 any reference regarding these doubts . Any suggestion or readable material ?



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




-- 
Regards,
Kamakshi
kamakshi...@gmail.com

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

2011-07-11 Thread rShetty
What is the most efficient algorithm to count the number of bits in an
unsigned integer ?
Explain your approach to the problem ?

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

2011-07-11 Thread Dave
Assuming that the integer is 32 bits, this is pretty good:

x = (x  0x) +  ((x  1)  0x);
x = (x  0x) +  ((x  2)  0x);
x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
x = (x  0x) +  ((x  16)  0x);

Notice that the hex constants are respectively alternate bits,
alternate pairs of bits, alternate groups of four bits, alternate
bytes, and the low-order half of the int.

The first statement determines the number of one-bits in each pair of
bits. The second statement adds adjacent pairs of bits to get the
number of bits in each group of four bits. Then these are added to get
the number of bits in each byte, short int, and finally in the whole
int.

Dave

On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:
 What is the most efficient algorithm to count the number of bits in an
 unsigned integer ?
 Explain your approach to the problem ?

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

2011-07-11 Thread rShetty
Some more Explanation of the working would be helpful

Thank You ..

On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:
 Assuming that the integer is 32 bits, this is pretty good:

 x = (x  0x) +  ((x  1)  0x);
 x = (x  0x) +  ((x  2)  0x);
 x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
 x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
 x = (x  0x) +  ((x  16)  0x);

 Notice that the hex constants are respectively alternate bits,
 alternate pairs of bits, alternate groups of four bits, alternate
 bytes, and the low-order half of the int.

 The first statement determines the number of one-bits in each pair of
 bits. The second statement adds adjacent pairs of bits to get the
 number of bits in each group of four bits. Then these are added to get
 the number of bits in each byte, short int, and finally in the whole
 int.

 Dave

 On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:







  What is the most efficient algorithm to count the number of bits in an
  unsigned integer ?
  Explain your approach to the problem ?

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

2011-07-11 Thread Anika Jain
how to do subtraction of two integers widout using subtractn??

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



[algogeeks] Re: Bit Twiddles

2011-07-11 Thread Dave
@rShetty: Ask a question. What do you need to know?

Dave

On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
 Some more Explanation of the working would be helpful

 Thank You ..

 On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:



  Assuming that the integer is 32 bits, this is pretty good:

  x = (x  0x) +  ((x  1)  0x);
  x = (x  0x) +  ((x  2)  0x);
  x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
  x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
  x = (x  0x) +  ((x  16)  0x);

  Notice that the hex constants are respectively alternate bits,
  alternate pairs of bits, alternate groups of four bits, alternate
  bytes, and the low-order half of the int.

  The first statement determines the number of one-bits in each pair of
  bits. The second statement adds adjacent pairs of bits to get the
  number of bits in each group of four bits. Then these are added to get
  the number of bits in each byte, short int, and finally in the whole
  int.

  Dave

  On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:

   What is the most efficient algorithm to count the number of bits in an
   unsigned integer ?
   Explain your approach to the problem ?- Hide quoted text -

 - Show quoted text -

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



Re: [algogeeks] sbtration

2011-07-11 Thread Sunny T
the negative integer can be represented in 2's complement format..

so sub_result=a+(~b+1) will perform the subtraction of a and b
-b=(~b+1).

On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com wrote:

 how to do subtraction of two integers widout using subtractn??

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




-- 
Warm Regards,
Sunny T

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

2011-07-11 Thread Abhishek Sharma
x-y = add(x, add(~y, 1)) 
here add(~y,1) refers to the Two's complement of y...

On 7/12/11, Anika Jain anika.jai...@gmail.com wrote:
 how to do subtraction of two integers widout using subtractn??

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



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

2011-07-11 Thread aditya pratap
suppose u want to do 124 - 46

step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
step2: add 124 + 54 = 178
step3: neglect 1 from 178 and answer will be 78.

correct me if i am wrong.

On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com wrote:

 how to do subtraction of two integers widout using subtractn??

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




-- 
Regards
Aditya Pratap
MCA II

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



Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
are you saying that x finally contains the number of bits that are set to
1..??

On Tue, Jul 12, 2011 at 1:09 AM, Dave dave_and_da...@juno.com wrote:

 @rShetty: Ask a question. What do you need to know?

 Dave

 On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
  Some more Explanation of the working would be helpful
 
  Thank You ..
 
  On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:
 
 
 
   Assuming that the integer is 32 bits, this is pretty good:
 
   x = (x  0x) +  ((x  1)  0x);
   x = (x  0x) +  ((x  2)  0x);
   x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
   x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
   x = (x  0x) +  ((x  16)  0x);
 
   Notice that the hex constants are respectively alternate bits,
   alternate pairs of bits, alternate groups of four bits, alternate
   bytes, and the low-order half of the int.
 
   The first statement determines the number of one-bits in each pair of
   bits. The second statement adds adjacent pairs of bits to get the
   number of bits in each group of four bits. Then these are added to get
   the number of bits in each byte, short int, and finally in the whole
   int.
 
   Dave
 
   On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:
 
What is the most efficient algorithm to count the number of bits in
 an
unsigned integer ?
Explain your approach to the problem ?- Hide quoted text -
 
  - Show quoted text -

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



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



[algogeeks] Re: sbtration

2011-07-11 Thread Dave
@Aditya: Since 124 is a 3-digit number, I think it would make more
sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
954 = 1078. Since we are working in 3-digit numbers, the 1 represents
an overflow, which you ignore. Thus, the answer is 78.

Dave

On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
 suppose u want to do 124 - 46

 step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
 step2: add 124 + 54 = 178
 step3: neglect 1 from 178 and answer will be 78.

 correct me if i am wrong.

 On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com wrote:
  how to do subtraction of two integers widout using subtractn??

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

 --
 Regards
 Aditya Pratap
 MCA II

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



[algogeeks] Re: Bit Twiddles

2011-07-11 Thread Dave
@SkRiPt: Yes.

Dave

On Jul 11, 2:43 pm, SkRiPt KiDdIe anuragmsi...@gmail.com wrote:
 are you saying that x finally contains the number of bits that are set to
 1..??



 On Tue, Jul 12, 2011 at 1:09 AM, Dave dave_and_da...@juno.com wrote:
  @rShetty: Ask a question. What do you need to know?

  Dave

  On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
   Some more Explanation of the working would be helpful

   Thank You ..

   On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:

Assuming that the integer is 32 bits, this is pretty good:

x = (x  0x) +  ((x  1)  0x);
x = (x  0x) +  ((x  2)  0x);
x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
x = (x  0x) +  ((x  16)  0x);

Notice that the hex constants are respectively alternate bits,
alternate pairs of bits, alternate groups of four bits, alternate
bytes, and the low-order half of the int.

The first statement determines the number of one-bits in each pair of
bits. The second statement adds adjacent pairs of bits to get the
number of bits in each group of four bits. Then these are added to get
the number of bits in each byte, short int, and finally in the whole
int.

Dave

On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:

 What is the most efficient algorithm to count the number of bits in
  an
 unsigned integer ?
 Explain your approach to the problem ?- Hide quoted text -

   - Show quoted text -

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

 - Show quoted text -

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



Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
on executing the code :

#includeiostream
using namespace std;
int main()
{
int x=0x4000;
x = (x  0x) +  ((x  1)  0x);

coutxendl;
return 0;
}

OUTPUT=1073741824

ans should be 1 i suppose..??


On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:

 @SkRiPt: Yes.

 Dave

 On Jul 11, 2:43 pm, SkRiPt KiDdIe anuragmsi...@gmail.com wrote:
  are you saying that x finally contains the number of bits that are set to
  1..??
 
 
 
  On Tue, Jul 12, 2011 at 1:09 AM, Dave dave_and_da...@juno.com wrote:
   @rShetty: Ask a question. What do you need to know?
 
   Dave
 
   On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
Some more Explanation of the working would be helpful
 
Thank You ..
 
On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:
 
 Assuming that the integer is 32 bits, this is pretty good:
 
 x = (x  0x) +  ((x  1)  0x);
 x = (x  0x) +  ((x  2)  0x);
 x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
 x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
 x = (x  0x) +  ((x  16)  0x);
 
 Notice that the hex constants are respectively alternate bits,
 alternate pairs of bits, alternate groups of four bits, alternate
 bytes, and the low-order half of the int.
 
 The first statement determines the number of one-bits in each pair
 of
 bits. The second statement adds adjacent pairs of bits to get the
 number of bits in each group of four bits. Then these are added to
 get
 the number of bits in each byte, short int, and finally in the
 whole
 int.
 
 Dave
 
 On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:
 
  What is the most efficient algorithm to count the number of bits
 in
   an
  unsigned integer ?
  Explain your approach to the problem ?- Hide quoted text -
 
- Show quoted text -
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

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



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



Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
Got it :)

On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:

 @SkRiPt: Yes.

 Dave

 On Jul 11, 2:43 pm, SkRiPt KiDdIe anuragmsi...@gmail.com wrote:
  are you saying that x finally contains the number of bits that are set to
  1..??
 
 
 
  On Tue, Jul 12, 2011 at 1:09 AM, Dave dave_and_da...@juno.com wrote:
   @rShetty: Ask a question. What do you need to know?
 
   Dave
 
   On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
Some more Explanation of the working would be helpful
 
Thank You ..
 
On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:
 
 Assuming that the integer is 32 bits, this is pretty good:
 
 x = (x  0x) +  ((x  1)  0x);
 x = (x  0x) +  ((x  2)  0x);
 x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
 x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
 x = (x  0x) +  ((x  16)  0x);
 
 Notice that the hex constants are respectively alternate bits,
 alternate pairs of bits, alternate groups of four bits, alternate
 bytes, and the low-order half of the int.
 
 The first statement determines the number of one-bits in each pair
 of
 bits. The second statement adds adjacent pairs of bits to get the
 number of bits in each group of four bits. Then these are added to
 get
 the number of bits in each byte, short int, and finally in the
 whole
 int.
 
 Dave
 
 On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:
 
  What is the most efficient algorithm to count the number of bits
 in
   an
  unsigned integer ?
  Explain your approach to the problem ?- Hide quoted text -
 
- Show quoted text -
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

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



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



[algogeeks] C OUTPUT HELP

2011-07-11 Thread nicks
Guys plz help me in understanding the following output

*PROBLEM 1.*
*
*
#includestdio.h
main()
{
int scanf=78;
//int printf=45;
int getchar=6;
printf(%d,scanf);
printf(\n%d,getchar);
}

*OUTPUT-*
78
6

in this problem my problem is using printf and scanf as variable
names.they are functions in the stdio.h then how are they available for
variable name ??...generally what happens is that whenever we use some name
for the function and then use that name for some variable then compiler
gives error then why in this case error is not coming ??

*PROBLEM 2.*

#includestdio.h
main()
{
int i=1;
printf(\n%d %d,i^=1%2,i=1%2);  // does it evaluate the final value of i
before printing ??
**}
*OUTPUT-*
3 3

In gcc what i have observed is that arguments of printf are evaluated from
right to left i.e i=1%2 is evaluated before i^=1%2...hence i first becomes
2 then 3 after XOR with 1now output according to me should be 3
1.but what actually is happening is that it us evaluating i and then
printing it 3 3.can someone explain why this output is coming ?

and the last problem

*PROBLEM 3.*
*
*
#includestdio.h
main()
{
enum {low='a',high='b'}tag;
char try=low;
printf(Size=%d,sizeof(tag));
switch (try)
{
case 'a':printf(aaa);break;
case 'b':printf(bbb);
case 'c':printf(ccc);
}
//system(pause);
}

in this program size of enum comes out to be 4..help me in understanding the
size of enum...how it is stored in memory??...does the size of enum depend
on number of constant in it ?anyone link regarding that ??

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



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread nicks
@sandeep u mean whenever printf will demand for %f then it will print
2.0.is it random behavior or always going to happen ??

anyone else having better idea regarding 1st and 2nd problem...

On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain sandeep6...@gmail.com wrote:

 TurboC has many flaws, one of the simplest examples would be
 char *p;
 scanf(%s, p);

 In gcc/g++ this will surely lead to segmentation fault as memory has not
 been allocated. Whereas in TC it will execute fine in most of the cases.
 Infact this will crash when your code is really large.

 As for input, 2 will automatically be treated as 2.0 when scanf demands a
 floating value. However, if you enter characters in place of numbers or vice
 versa. You may experience weird behavior.




 Regards,
 Sandeep Jain




 On Mon, Jul 11, 2011 at 9:37 AM, nicks crazy.logic.k...@gmail.com wrote:

 @sandeep,kamakshiithanks both...your replies were really helpfuli
 understood my fault in 3,4,5...they are clea now..but i am still stuck
 with problem 1 and 2

 @sandeepwhat if i am using turbo C...though i am using gcc on terminal
 in my linux system.
 moreover acc. t KR printf uses it's first argument to decide how many
 arguments follow and what their types are. it will get confused,and you will
 get wrong answers,if there are not enough arguments or if they are the wrong
 type
 it's fine it will give the wrong answer then it's only the value we
 provide in input ???


 @kamakshii...can explain your point related to macro in detail.is it
 related to linking or something which is done after creating object file...

 On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal 
 kamakshi...@gmail.com wrote:

 probelm 5:It must be giving runtime error not segmentation fault coz it
 is an infinite recursion


 On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal 
 kamakshi...@gmail.com wrote:

 for the first question...it will take #ifdef getchar to be '1' only when
 it is defined as a MACRO in your program..if u dont define macro it will 
 not
 take it into consideration even if it is defined in header file.

 On Mon, Jul 11, 2011 at 12:38 AM, nicks crazy.logic.k...@gmail.comwrote:

 Someone please help me in understanding the following output -

 Problem *1.*
 #includestdio.h
 #ifdef getchar //this expression is evaluated to zero.why
 is so happening ??getchar is defined as macro in stdio.h.i 
 mean
 else part shouldn't be executed which is happening
 #undef getchar
 #else
 #define getchar scanf(%c,ch);
 #endif
 main()
 {
 char ch;
  int c;
 c=getchar;
 printf(%d,c);
 }

 *OUTPUT-  1*
 *
 *
 *
 *
 *2.*
 #includestdio.h
 void main()
 {
 long x;
  float t;
 scanf(%f,t);
 printf(%d\n,t);
  x=90;
 printf(%ld\n,x);
 {
  x=1;
 printf(%f\n,x);
 {
  x=30;
 printf(%f\n,x);
 }
  printf(%f\n,x);
 }
 x==9;
  printf(%f\n,x);
 }

 *OUTPUT(INPUT IS 2) -*
 *2*
 *0*
 *90*
 *2.00*
 *2.00*
 *2.00*
 *2.00*
 *
 *
 In this problem i failed to Understand why t is printed as 0 (though
 float is converted to integer by truncation of the fractional part)
 and how the value of t is transferred to xlooks very strange to me
 !!


 *3.*
 #includestdio.h
 main()
 {
 printf(\nACM-CIC+3);
 printf(4+\nACM-CIC);

 }

 *OUTPUT -*
 *M-CIC-CIC*
 *
 *
 What does +3 and +4 doing and does it matter to use them before the
 format string or after it ??

 *4.*
 #includestdio.h
 main()
 {
 long long i=50;
 i==1000;
  printf(i=%d\n\n%lld,sizeof(i),i);
 //system(pause);
 }

 *OUTPUT -*
 *i=8*
 *
 *
 *50*
 *
 *
 Assigning very large value to i isn't changing it's value.why is so
 happening ??

 and the last one

 *5.*
 #includestdio.h
 main()
 {
 static int i=0;
  if(i=-1)
 printf(\nBull's Eye);
 else
  {
 main();
 _exit(1);
  }
 i++;
 }

 *OUTPUT -*
 *segementation fault*
 *
 *
 What's Wrong with the above Code due to which it is giving Runtime
 errorplz help me pointing it out !!

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




 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

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

2011-07-11 Thread mittal
How much do we have to shift if a complete match is found.
I am looking for all cases and not just disjoint occurences.


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

2011-07-11 Thread mittal
Sorry, no need, got it

-- 
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/-/2KMiqR0hgx0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread varun pahwa
problem 3. I think tag is a reference so its size is 4 bytes.

On Tue, Jul 12, 2011 at 1:29 AM, nicks crazy.logic.k...@gmail.com wrote:

 Guys plz help me in understanding the following output

 *PROBLEM 1.*
 *
 *
 #includestdio.h
 main()
 {
 int scanf=78;
  //int printf=45;
 int getchar=6;
 printf(%d,scanf);
  printf(\n%d,getchar);
 }

 *OUTPUT-*
 78
 6

 in this problem my problem is using printf and scanf as variable
 names.they are functions in the stdio.h then how are they available for
 variable name ??...generally what happens is that whenever we use some name
 for the function and then use that name for some variable then compiler
 gives error then why in this case error is not coming ??

 *PROBLEM 2.*

 #includestdio.h
 main()
 {
 int i=1;
 printf(\n%d %d,i^=1%2,i=1%2);  // does it evaluate the final value of i
 before printing ??
 **}
 *OUTPUT-*
 3 3

 In gcc what i have observed is that arguments of printf are evaluated from
 right to left i.e i=1%2 is evaluated before i^=1%2...hence i first becomes
 2 then 3 after XOR with 1now output according to me should be 3
 1.but what actually is happening is that it us evaluating i and then
 printing it 3 3.can someone explain why this output is coming ?

 and the last problem

 *PROBLEM 3.*
 *
 *
 #includestdio.h
 main()
 {
 enum {low='a',high='b'}tag;
  char try=low;
 printf(Size=%d,sizeof(tag));
 switch (try)
  {
 case 'a':printf(aaa);break;
 case 'b':printf(bbb);
  case 'c':printf(ccc);
 }
 //system(pause);
 }

 in this program size of enum comes out to be 4..help me in understanding
 the size of enum...how it is stored in memory??...does the size of enum
 depend on number of constant in it ?anyone link regarding that ??

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




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

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

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



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread oppilas .
 *OUTPUT-*
 78
 6

 in this problem my problem is using printf and scanf as variable
 names.they are functions in the stdio.h then how are they available for
 variable name ??...generally what happens is that whenever we use some name
 for the function and then use that name for some variable then compiler
 gives error then why in this case error is not coming ??

 Think it in terms of global and local reference.
http://ideone.com/u6bQ

 *PROBLEM 2.*

 #includestdio.h
 main()
 {
 int i=1;
 printf(\n%d %d,i^=1%2,i=1%2);  // does it evaluate the final value of i
 before printing ??
 **}
 *OUTPUT-*
 3 3

 In gcc what i have observed is that arguments of printf are evaluated from
 right to left i.e i=1%2 is evaluated before i^=1%2...hence i first becomes
 2 then 3 after XOR with 1now output according to me should be 3
 1.but what actually is happening is that it us evaluating i and then
 printing it 3 3.can someone explain why this output is coming ?

 and the last problem

Left to right. Try on ideone.
void P(int a,int b){ printf a b;}
main(){ int x;
P (x++,++x);
print x++,++x
}


 *PROBLEM 3.*
 *
 *
 #includestdio.h
 main()
 {
 enum {low='a',high='b'}tag;
  char try=low;
 printf(Size=%d,sizeof(tag));
 switch (try)
  {
 case 'a':printf(aaa);break;
 case 'b':printf(bbb);
  case 'c':printf(ccc);
 }
 //system(pause);
 }

 in this program size of enum comes out to be 4..help me in understanding
 the size of enum...how it is stored in memory??...does the size of enum
 depend on number of constant in it ?anyone link regarding that ??

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

2011-07-11 Thread oppilas .
On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.com wrote:

 Can anybody give a full explanation

 http://ideone.com/K1QmV

 On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 try to find out the binary representation of float value 5.2


 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.comwrote:

 int main(){
 int i;
 float a=5.2;
 char *ptr;
 ptr=(char *)a;
 for(i=0;i=3;i++)
 printf(%d ,*ptr++);
 }

 output:
  102 102 -90 64.explain?

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




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

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


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

2011-07-11 Thread rajeev bharshetty
@Dave Got It Thanks

On Tue, Jul 12, 2011 at 1:23 AM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:

 Got it :)


 On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:

 @SkRiPt: Yes.

 Dave

 On Jul 11, 2:43 pm, SkRiPt KiDdIe anuragmsi...@gmail.com wrote:
  are you saying that x finally contains the number of bits that are set
 to
  1..??
 
 
 
  On Tue, Jul 12, 2011 at 1:09 AM, Dave dave_and_da...@juno.com wrote:
   @rShetty: Ask a question. What do you need to know?
 
   Dave
 
   On Jul 11, 1:26 pm, rShetty rajeevr...@gmail.com wrote:
Some more Explanation of the working would be helpful
 
Thank You ..
 
On Jul 11, 11:11 pm, Dave dave_and_da...@juno.com wrote:
 
 Assuming that the integer is 32 bits, this is pretty good:
 
 x = (x  0x) +  ((x  1)  0x);
 x = (x  0x) +  ((x  2)  0x);
 x = (x  0x0F0F0F0F) +  ((x  4)  0x0F0F0F0F);
 x = (x  0x00FF00FF) +  ((x  8)  0x00FF00FF);
 x = (x  0x) +  ((x  16)  0x);
 
 Notice that the hex constants are respectively alternate bits,
 alternate pairs of bits, alternate groups of four bits, alternate
 bytes, and the low-order half of the int.
 
 The first statement determines the number of one-bits in each pair
 of
 bits. The second statement adds adjacent pairs of bits to get the
 number of bits in each group of four bits. Then these are added to
 get
 the number of bits in each byte, short int, and finally in the
 whole
 int.
 
 Dave
 
 On Jul 11, 12:44 pm, rShetty rajeevr...@gmail.com wrote:
 
  What is the most efficient algorithm to count the number of bits
 in
   an
  unsigned integer ?
  Explain your approach to the problem ?- Hide quoted text -
 
- Show quoted text -
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

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


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




-- 
Regards
Rajeev N B http://www.opensourcemania.co.cc

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



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread Sandeep Jain
I'll put it in simple words, when printf is executed, it expects the
arguments to be of the same type and in the same order as they appear in the
format string.
Otherwise, it starts to exhibit random behavior whenever a first mismatch
occurs.


Regards,
Sandeep Jain



On Tue, Jul 12, 2011 at 1:32 AM, nicks crazy.logic.k...@gmail.com wrote:

 @sandeep u mean whenever printf will demand for %f then it will print
 2.0.is it random behavior or always going to happen ??

 anyone else having better idea regarding 1st and 2nd problem...

 On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain sandeep6...@gmail.comwrote:

 TurboC has many flaws, one of the simplest examples would be
 char *p;
 scanf(%s, p);

 In gcc/g++ this will surely lead to segmentation fault as memory has not
 been allocated. Whereas in TC it will execute fine in most of the cases.
 Infact this will crash when your code is really large.

 As for input, 2 will automatically be treated as 2.0 when scanf demands a
 floating value. However, if you enter characters in place of numbers or vice
 versa. You may experience weird behavior.




 Regards,
 Sandeep Jain




 On Mon, Jul 11, 2011 at 9:37 AM, nicks crazy.logic.k...@gmail.comwrote:

 @sandeep,kamakshiithanks both...your replies were really helpfuli
 understood my fault in 3,4,5...they are clea now..but i am still stuck
 with problem 1 and 2

 @sandeepwhat if i am using turbo C...though i am using gcc on
 terminal in my linux system.
 moreover acc. t KR printf uses it's first argument to decide how many
 arguments follow and what their types are. it will get confused,and you will
 get wrong answers,if there are not enough arguments or if they are the wrong
 type
 it's fine it will give the wrong answer then it's only the value we
 provide in input ???


 @kamakshii...can explain your point related to macro in detail.is it
 related to linking or something which is done after creating object file...

 On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal 
 kamakshi...@gmail.com wrote:

 probelm 5:It must be giving runtime error not segmentation fault coz it
 is an infinite recursion


 On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal 
 kamakshi...@gmail.com wrote:

 for the first question...it will take #ifdef getchar to be '1' only
 when it is defined as a MACRO in your program..if u dont define macro it
 will not take it into consideration even if it is defined in header file.

 On Mon, Jul 11, 2011 at 12:38 AM, nicks crazy.logic.k...@gmail.comwrote:

 Someone please help me in understanding the following output -

 Problem *1.*
 #includestdio.h
 #ifdef getchar //this expression is evaluated to zero.why
 is so happening ??getchar is defined as macro in stdio.h.i 
 mean
 else part shouldn't be executed which is happening
 #undef getchar
 #else
 #define getchar scanf(%c,ch);
 #endif
 main()
 {
 char ch;
  int c;
 c=getchar;
 printf(%d,c);
 }

 *OUTPUT-  1*
 *
 *
 *
 *
 *2.*
 #includestdio.h
 void main()
 {
 long x;
  float t;
 scanf(%f,t);
 printf(%d\n,t);
  x=90;
 printf(%ld\n,x);
 {
  x=1;
 printf(%f\n,x);
 {
  x=30;
 printf(%f\n,x);
 }
  printf(%f\n,x);
 }
 x==9;
  printf(%f\n,x);
 }

 *OUTPUT(INPUT IS 2) -*
 *2*
 *0*
 *90*
 *2.00*
 *2.00*
 *2.00*
 *2.00*
 *
 *
 In this problem i failed to Understand why t is printed as 0 (though
 float is converted to integer by truncation of the fractional part)
 and how the value of t is transferred to xlooks very strange to me
 !!


 *3.*
 #includestdio.h
 main()
 {
 printf(\nACM-CIC+3);
 printf(4+\nACM-CIC);

 }

 *OUTPUT -*
 *M-CIC-CIC*
 *
 *
 What does +3 and +4 doing and does it matter to use them before the
 format string or after it ??

 *4.*
 #includestdio.h
 main()
 {
 long long i=50;
 i==1000;
  printf(i=%d\n\n%lld,sizeof(i),i);
 //system(pause);
 }

 *OUTPUT -*
 *i=8*
 *
 *
 *50*
 *
 *
 Assigning very large value to i isn't changing it's value.why is
 so happening ??

 and the last one

 *5.*
 #includestdio.h
 main()
 {
 static int i=0;
  if(i=-1)
 printf(\nBull's Eye);
 else
  {
 main();
 _exit(1);
  }
 i++;
 }

 *OUTPUT -*
 *segementation fault*
 *
 *
 What's Wrong with the above Code due to which it is giving Runtime
 errorplz help me pointing it out !!

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




 --
 Regards,
 Kamakshi
 kamakshi...@gmail.com

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

Re: [algogeeks] Re: sbtration

2011-07-11 Thread chandy jose paul
Y are u guys complicating things.Its as simple as this

 x=a-b = (a/b)*b + a%b

On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:

 @Aditya: Since 124 is a 3-digit number, I think it would make more
 sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
 954 = 1078. Since we are working in 3-digit numbers, the 1 represents
 an overflow, which you ignore. Thus, the answer is 78.

 Dave

 On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
  suppose u want to do 124 - 46
 
  step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
  step2: add 124 + 54 = 178
  step3: neglect 1 from 178 and answer will be 78.
 
  correct me if i am wrong.
 
  On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com
 wrote:
   how to do subtraction of two integers widout using subtractn??
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Regards
  Aditya Pratap
  MCA II

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



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



[algogeeks] Re: sbtration

2011-07-11 Thread Dave
@Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2
= 5. Check?

Dave

On Jul 11, 11:38 pm, chandy jose paul jpchaa...@gmail.com wrote:
 Y are u guys complicating things.Its as simple as this

  x=a-b = (a/b)*b + a%b



 On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
  @Aditya: Since 124 is a 3-digit number, I think it would make more
  sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
  954 = 1078. Since we are working in 3-digit numbers, the 1 represents
  an overflow, which you ignore. Thus, the answer is 78.

  Dave

  On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
   suppose u want to do 124 - 46

   step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
   step2: add 124 + 54 = 178
   step3: neglect 1 from 178 and answer will be 78.

   correct me if i am wrong.

   On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com
  wrote:
how to do subtraction of two integers widout using subtractn??

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

   --
   Regards
   Aditya Pratap
   MCA II

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

 - Show quoted text -

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



Re: [algogeeks]

2011-07-11 Thread sagar pareek
new and delete operator calls condtructors and destructors respectively :)

On Wed, Jul 6, 2011 at 6:23 PM, Navneet Gupta navneetn...@gmail.com wrote:

 The basic reason is graduation.

 Since C++ is object oriented and designers wanted to provide more
 safety in case of dynamic memory allocations, they defined new and
 delete operators to handle allocation and deallocation.

 If you see malloc, if does only one function - allocate the memory,
 with new operator on an object, it's appropriate constuctor will be
 called and you are guaranteed with proper initialization specially
 when we use standard libraries. So new faciliates allocation as well
 as initialization, similarly delete faciliates deallocation as well as
 destruction (clean up code inside destructor function).

 With free, user won't be having any handle on object if allocated with
 new until it is allocated memory and appropriately initialized.

 Also, AFAIK, chances of getting proper memory allocation are more with
 new than malloc. Somebody on the group may confirm.

 On Wed, Jul 6, 2011 at 6:07 PM, Tamanna Afroze afroze...@gmail.com
 wrote:
  I think C++ has some advanced feature for memory allocation like new.
 
  On Wed, Jul 6, 2011 at 6:34 PM, Piyush Sinha ecstasy.piy...@gmail.com
  wrote:
 
  Why is it suggested not to use malloc() or calloc() in C++ for memory
  allocation?
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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,
  Tamanna
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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.




-- 
**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] Re: sbtration

2011-07-11 Thread Sunny T
i would say.. implementing subtraction using division and modulus is more
costly and complicated. bit manipulation is the fastest among all
these techniques.

 x=a-b = (a/b)*b + a%b

.here u are performing... totally 4 operations..1 division,1
multiplication,1 modulus and 1 addition..

it can be easily done by...

x=a+(~b+1). this solution takes less number of operation than
ur solution and involve less costly operators.

On Tue, Jul 12, 2011 at 10:29 AM, Dave dave_and_da...@juno.com wrote:

 @Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2
 = 5. Check?

 Dave

 On Jul 11, 11:38 pm, chandy jose paul jpchaa...@gmail.com wrote:
  Y are u guys complicating things.Its as simple as this
 
   x=a-b = (a/b)*b + a%b
 
 
 
  On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
   @Aditya: Since 124 is a 3-digit number, I think it would make more
   sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
   954 = 1078. Since we are working in 3-digit numbers, the 1 represents
   an overflow, which you ignore. Thus, the answer is 78.
 
   Dave
 
   On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
suppose u want to do 124 - 46
 
step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
step2: add 124 + 54 = 178
step3: neglect 1 from 178 and answer will be 78.
 
correct me if i am wrong.
 
On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain anika.jai...@gmail.com
 
   wrote:
 how to do subtraction of two integers widout using subtractn??
 
 --
 You received this message because you are subscribed to the Google
   Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
 
--
Regards
Aditya Pratap
MCA II
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

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




-- 
Warm Regards,
Sunny T

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



Re: [algogeeks] Re: sbtration

2011-07-11 Thread Vishal Thanki
z = x + (-y)

:)

On Tue, Jul 12, 2011 at 10:58 AM, Sunny T sunny.1...@gmail.com wrote:
 i would say.. implementing subtraction using division and modulus is more
 costly and complicated. bit manipulation is the fastest among all
 these techniques.
  x=a-b = (a/b)*b + a%b
 .here u are performing... totally 4 operations..1 division,1
 multiplication,1 modulus and 1 addition..

 it can be easily done by...

 x=a+(~b+1). this solution takes less number of operation than
 ur solution and involve less costly operators.

 On Tue, Jul 12, 2011 at 10:29 AM, Dave dave_and_da...@juno.com wrote:

 @Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2
 = 5. Check?

 Dave

 On Jul 11, 11:38 pm, chandy jose paul jpchaa...@gmail.com wrote:
  Y are u guys complicating things.Its as simple as this
 
   x=a-b = (a/b)*b + a%b
 
 
 
  On Tue, Jul 12, 2011 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
   @Aditya: Since 124 is a 3-digit number, I think it would make more
   sense to use the 3-digit 10's complement of 46, i.e., 954. Then 124 +
   954 = 1078. Since we are working in 3-digit numbers, the 1 represents
   an overflow, which you ignore. Thus, the answer is 78.
 
   Dave
 
   On Jul 11, 2:42 pm, aditya pratap contacttoadity...@gmail.com wrote:
suppose u want to do 124 - 46
 
step1 : write 10's complement of 46 i.e. 53 (9's complement) +1 = 54
step2: add 124 + 54 = 178
step3: neglect 1 from 178 and answer will be 78.
 
correct me if i am wrong.
 
On Tue, Jul 12, 2011 at 12:54 AM, Anika Jain
anika.jai...@gmail.com
   wrote:
 how to do subtraction of two integers widout using subtractn??
 
 --
 You received this message because you are subscribed to the Google
   Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
 
--
Regards
Aditya Pratap
MCA II
 
   --
   You received this message because you are subscribed to the Google
   Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

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




 --
 Warm Regards,
 Sunny T

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