Re: [algogeeks] a google question

2010-05-02 Thread mohit ranjan
@Algoose Chase

point taken
Thanks


Mohit Ranjan
Samsung India Software Operations.


On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.com wrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array will be
 max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using DP,
 moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array will be
 max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using DP
 moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.com wrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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


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



Re: [algogeeks] 400!

2010-05-02 Thread divya jain
wat is tail recursion plz explan in detail

On 2 May 2010 08:15, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 @divya use tail recursion and rest should be fine..

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

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



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



Re: [algogeeks] 400!

2010-05-02 Thread Rohit Saraf
google it... u will gt it

i am on mobile... cannot explain now..

On 5/2/10, divya jain sweetdivya@gmail.com wrote:
 wat is tail recursion plz explan in detail

 On 2 May 2010 08:15, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 @divya use tail recursion and rest should be fine..

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

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



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




-- 
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14

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



Re: [algogeeks] a google question

2010-05-02 Thread vignesh radhakrishnan
@divya You're rite. Post a solution if you have one.

--
Regards,
Vignesh

On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

 @Mohit

 according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
 then i is incremented   i is now 2 so for next iteration u ll compare a[2]
 b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever. think
 for ths case also.


 On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

 @Algoose Chase

 point taken
 Thanks


 Mohit Ranjan
 Samsung India Software Operations.


 On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan 
 shoonya.mo...@gmail.comwrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array will
 be max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using DP,
 moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan 
 shoonya.mo...@gmail.comwrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array will
 be max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using DP
 moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.comwrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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


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


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




-- 
There are two kinds of people. Those who care for others and The others

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



Re: [algogeeks] 400!

2010-05-02 Thread vignesh radhakrishnan
I agree with abhijith. But given some very large x for which i would have to
find factorial.
I would either
(i) use gmp in cpp or BigInteger or java if its not a lab exercise or an
interview
(ii) use simple brute multiplication algorithm.
The second approach requires
 (a) The no. of digits in n! for making storage available
 (b) The calculation itself which I would brute force

References:
http://inder-gnu.blogspot.com/2009/08/find-number-of-digits-in-factorial-of.html
http://stackoverflow.com/questions/1113167/can-one-know-how-large-a-factorial-would-be-before-calculating-it
http://delphiforfun.org/programs/big_factorials.htm


On 2 May 2010 13:59, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 google it... u will gt it

 i am on mobile... cannot explain now..

 On 5/2/10, divya jain sweetdivya@gmail.com wrote:
  wat is tail recursion plz explan in detail
 
  On 2 May 2010 08:15, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
 
  @divya use tail recursion and rest should be fine..
 
  --
  --
  Rohit Saraf
  Second Year Undergraduate,
  Dept. of Computer Science and Engineering
  IIT Bombay
  http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14
 http://www.cse.iitb.ac.in/%7Erohitfeb14
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
  .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 


 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

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




-- 
There are two kinds of people. Those who care for others and The others

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



Re: [algogeeks] a google question

2010-05-02 Thread Shishir Mittal
This problem has been discussed before @
http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1aa8cf1ed437/d451cd9468d985f7

I believe, the problem can't be solved in O(n) but only in O(nlog n).

@Divya: Are you sure the interviewer explicitly asked for an O(n) time
algorithm?

On Sun, May 2, 2010 at 1:48 PM, vignesh radhakrishnan 
rvignesh1...@gmail.com wrote:

 @divya You're rite. Post a solution if you have one.

 --
 Regards,
 Vignesh


 On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

 @Mohit

 according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
 then i is incremented   i is now 2 so for next iteration u ll compare a[2]
 b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever. think
 for ths case also.


 On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

 @Algoose Chase

 point taken
 Thanks


 Mohit Ranjan
 Samsung India Software Operations.


 On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan 
 shoonya.mo...@gmail.comwrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array will
 be max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using
 DP, moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan shoonya.mo...@gmail.com
  wrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array will
 be max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using
 DP moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.comwrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of
 such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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


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


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




 --
 There are two kinds of people. Those who care for others and The others

 --
 You received this message because you 

Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
Hi

will this work ?

since we need Set S with n pairs of largest values , any such pair within
the set would (always) contain A[0] or B[0] because they maximize the value
of the pair.

so

// code snippet
typedef std::vectorint,int Pairs;

Pairs.push(A[0],B[0])
int i = 1; // index for ListA
int j = 1; // index for list B
count = 1;
while( count = n)
{
  if( A[0] + B[j]  B[0] + A[i] )
  {
Pairs.push(A[0],B[j])
j++;
  }
  else
  {
 Pairs.Add(A[i],B[0])
 i++;
  }
  count++;
}

since there are n items in both the lists, j and i wont go beyond n in the
while loop


On Sun, May 2, 2010 at 3:44 PM, Shishir Mittal 1987.shis...@gmail.comwrote:

 This problem has been discussed before @
 http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1aa8cf1ed437/d451cd9468d985f7

 I believe, the problem can't be solved in O(n) but only in O(nlog n).

 @Divya: Are you sure the interviewer explicitly asked for an O(n) time
 algorithm?


 On Sun, May 2, 2010 at 1:48 PM, vignesh radhakrishnan 
 rvignesh1...@gmail.com wrote:

 @divya You're rite. Post a solution if you have one.

 --
 Regards,
 Vignesh


 On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

 @Mohit

 according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
 then i is incremented   i is now 2 so for next iteration u ll compare
 a[2] b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever.
 think for ths case also.


 On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

 @Algoose Chase

 point taken
 Thanks


 Mohit Ranjan
 Samsung India Software Operations.


 On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] 
 since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan shoonya.mo...@gmail.com
  wrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array will
 be max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using
 DP, moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan 
 shoonya.mo...@gmail.com wrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array will
 be max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using
 DP moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.comwrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G,
 let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a
 \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of
 such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n
 pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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


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

Re: [algogeeks] Where does OS scheduling run??

2010-05-02 Thread praba garan
@ Pradeep

*CPU stop its current processing and goes to the interrupt subroutine*

you have mentioned that the CPU stops its current processing and goes to the
interrupt subroutine..

My Question is how does the CPU stops its execution(any special hardware
involved) because it is busy in executing the current instruction.


With Regards,
Prabagaran.


On Sun, May 2, 2010 at 4:02 AM, pradeep verma ppradeep...@gmail.com wrote:

 lets suppose Processor executing a instruction(process1) and another
 process2 tries to take the control of CPU so inorder to inform CPU it has to
 interrupt the CPU right
 now we know that if interrupt comes CPU stop its current processing and
 goes to the interrupt subroutine...now CPU knows that its a pre-emption
 interrupt so CPU first run its short term scheduler(this will inform CPU
 that the interruting process priority is less or greater ..n if greater than
 CPU goes to previous process1 preempt it and start executing higher priority
 process2 )

 I think its clear

 Regards
 Pradeep



 On Sun, May 2, 2010 at 3:06 AM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 The link gives the overall abstract idea.
 I am talking in register level.
 When a user process executes

 1. PC program counter will contain the address of the next instruction in
 user code.
 2. Processor registers(accumulator ...) contain the current instruction
 data.

 Then where does the interrupt actually arrives??

 And by that time the user process the control, then who does the
 preempting and how??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 2:35 AM, Guillermo Garcia gegarci...@gmail.comwrote:


 read here - http://en.wikipedia.org/wiki/Preemption_%28computing%29



 Time slice

 The period of time for which a process is allowed to run in a preemptive
 multitasking system is generally called the *time slice*, or *quantum*.
 The scheduler is run once every time slice to choose the next process to
 run. If the time slice is too short then the scheduler will consume too much
 processing time.

 An interrupt http://en.wikipedia.org/wiki/Interrupt is scheduled to
 allow the operating systemhttp://en.wikipedia.org/wiki/Operating_system
 kernel http://en.wikipedia.org/wiki/Kernel_%28computer_science%29 to
 switch between processes when their time slices expire, effectively allowing
 the processor’s time to be shared between a number of tasks, giving the
 illusion that it is dealing with these tasks simultaneously, or
 concurrently. The operating system which controls such a design is called a
 multi-tasking system.




 On Sat, May 1, 2010 at 5:26 PM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 Suppose a user program is executing and and clock interrupt arrives..
 Then who receives the interrupt??
 Can you xplain me the clock interrupt(like any hardwares involved) bit
 detailed??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 1:38 AM, Guillermo Garcia 
 gegarci...@gmail.comwrote:

 The scheduler takes control with a clock interruption. Then it analyzes
 if it has to preempt or not the running task.

 On Sat, May 1, 2010 at 5:00 PM, praba garan prabagara...@gmail.comwrote:

 Hi all,
 I have a doubt in OS.
 The scheduler does the process of preemption.
 And one processor can run atmost 1 instruction at a time.
 Then how  where does the scheduler run??

 With Regards,
 Prabagaran.

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


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


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


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


  --
 You received this message 

[algogeeks] Re: a google question

2010-05-02 Thread Satish
This problem can be simplified to a variation of merge part of merge
sort algorithm.

- Break the set S having n^2 values into n individual arrays of length
n, say S1, S2,..Sn, where S1 = [a1+b1, a1+b2,...a1+bn].
- One can observe that each Si has entries which are themselves sorted
within Si.
- Perform merge of S1, S2,..Sn where take the largest values of each
Si, and create a heap of these individual max values.
- In each step, return the max value from heap and then add the next
max value from the Si that had the current max value and add it in the
max-heap.
- Repeat this step n times and then exit.

Time: O(n).

Satish

On May 2, 5:41 pm, Algoose Chase harishp...@gmail.com wrote:
 Hi

 will this work ?

 since we need Set S with n pairs of largest values , any such pair within
 the set would (always) contain A[0] or B[0] because they maximize the value
 of the pair.

 so

 // code snippet
 typedef std::vectorint,int Pairs;

 Pairs.push(A[0],B[0])
 int i = 1; // index for ListA
 int j = 1; // index for list B
 count = 1;
 while( count = n)
 {
   if( A[0] + B[j]  B[0] + A[i] )
   {
     Pairs.push(A[0],B[j])
     j++;
   }
   else
   {
      Pairs.Add(A[i],B[0])
      i++;
   }
   count++;

 }

 since there are n items in both the lists, j and i wont go beyond n in the
 while loop

 On Sun, May 2, 2010 at 3:44 PM, Shishir Mittal 1987.shis...@gmail.comwrote:





  This problem has been discussed before @
 http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1...

  I believe, the problem can't be solved in O(n) but only in O(nlog n).

  @Divya: Are you sure the interviewer explicitly asked for an O(n) time
  algorithm?

  On Sun, May 2, 2010 at 1:48 PM, vignesh radhakrishnan 
  rvignesh1...@gmail.com wrote:

  @divya You're rite. Post a solution if you have one.

  --
  Regards,
  Vignesh

  On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

  @Mohit

  according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
  then i is incremented   i is now 2 so for next iteration u ll compare
  a[2] b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever.
  think for ths case also.

  On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

  @Algoose Chase

  point taken
  Thanks

  Mohit Ranjan
  Samsung India Software Operations.

  On Sat, May 1, 2010 at 8:43 PM, Algoose Chase 
  harishp...@gmail.comwrote:

  @mohit

  The idea of DP is fine.
  When you find the Max i dont think you need to include A[i+1]+B[j+1]
  because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] 
  since
  both the lists are sorted in decreasing order.

  On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan shoonya.mo...@gmail.com
   wrote:

  oops

  Sorry didn't read properly
  last algo was for array sorted in ascending order

  for this case, just reverse the process

  A[n] and B[n] are two array

  loop=n, i=0, j=0;

  while(loop0)  // for n largest pairs
  {
    print A[i]+B[j];          // sum of first index from both array will
  be max

    foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] )     // using
  DP, moving forward

    if foo==A[i+1]+B[j]; i++   // only increment A
    if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
    if foo==A[i]+B[j+1]; j++  // increment only B

  }

  Mohit Ranjan
  Samsung India Software Operations.

  On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan 
  shoonya.mo...@gmail.com wrote:

  Hi Divya,

  A[n] and B[n] are two array

  loop=n, i=n-1, j=n-1;

  while(loop0)  // for n largest pairs
  {
    print A[i]+B[j];          // sum of last index from both array will
  be max

    foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] )     // using
  DP moving backward

    if foo=A[i-1]+B[j]; i--   // only reduce A
    if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
    if foo=A[i]+B[j-1]; j--  // reduce only B
  }

  Time: O(n)

  Mohit Ranjan

  On Fri, Apr 30, 2010 at 5:35 PM, divya 
  sweetdivya@gmail.comwrote:

  Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G,
  let's
  say they are decreasingly sorted), we define a set S = {(a,b) | a
  \in
  A
  and b \in B}. Obviously there are n^2 elements in S. The value of
  such
  a pair is defined as Val(a,b) = a + b. Now we want to get the n
  pairs
  from S with largest values. The tricky part is that we need an O(n)
  algorithm.

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

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

[algogeeks] tree from linked list

2010-05-02 Thread divya
u are given a sorted lnked list construct a balanced binary search
tree from it.

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



Re: [algogeeks] a google question

2010-05-02 Thread divya jain
i found this question on some site and it was mentioned there todo in  o(n).
i dont have the solution
@ above

ur solution doesnt include the case of ncluding a[i] b[j] it takes only a[i]
b[0] or b[j] a[0]

On 2 May 2010 18:11, Algoose Chase harishp...@gmail.com wrote:

 Hi

 will this work ?

 since we need Set S with n pairs of largest values , any such pair within
 the set would (always) contain A[0] or B[0] because they maximize the value
 of the pair.

 so

 // code snippet
 typedef std::vectorint,int Pairs;

 Pairs.push(A[0],B[0])
 int i = 1; // index for ListA
 int j = 1; // index for list B
 count = 1;
 while( count = n)
 {
   if( A[0] + B[j]  B[0] + A[i] )
   {
 Pairs.push(A[0],B[j])
 j++;
   }
   else
   {
  Pairs.Add(A[i],B[0])
  i++;
   }
   count++;
 }

 since there are n items in both the lists, j and i wont go beyond n in the
 while loop


 On Sun, May 2, 2010 at 3:44 PM, Shishir Mittal 1987.shis...@gmail.comwrote:

 This problem has been discussed before @
 http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1aa8cf1ed437/d451cd9468d985f7

 I believe, the problem can't be solved in O(n) but only in O(nlog n).

 @Divya: Are you sure the interviewer explicitly asked for an O(n) time
 algorithm?


 On Sun, May 2, 2010 at 1:48 PM, vignesh radhakrishnan 
 rvignesh1...@gmail.com wrote:

 @divya You're rite. Post a solution if you have one.

 --
 Regards,
 Vignesh


 On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

 @Mohit

 according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
 then i is incremented   i is now 2 so for next iteration u ll compare
 a[2] b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever.
 think for ths case also.


 On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

 @Algoose Chase

 point taken
 Thanks


 Mohit Ranjan
 Samsung India Software Operations.


 On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] 
 since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan 
 shoonya.mo...@gmail.com wrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array
 will be max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using
 DP, moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan 
 shoonya.mo...@gmail.com wrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array
 will be max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using
 DP moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.comwrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G,
 let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a
 \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of
 such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n
 pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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

Re: [algogeeks] 400!

2010-05-02 Thread Prasoon Mishra
I think challenge here is not the Execution time, but the storage. 300 ! or
400! should generally go beyond the storage capabilities of long long ints
in cpp.
@ Rohit Saraf: Hence, I don't know if even tail recursion will ultimately be
able to store the output.
I think Rajesh Patidar's answer fits the bill well, in terms of storage.

On Sun, May 2, 2010 at 2:23 PM, vignesh radhakrishnan 
rvignesh1...@gmail.com wrote:

 I agree with abhijith. But given some very large x for which i would have
 to find factorial.
 I would either
 (i) use gmp in cpp or BigInteger or java if its not a lab exercise or an
 interview
 (ii) use simple brute multiplication algorithm.
 The second approach requires
  (a) The no. of digits in n! for making storage available
  (b) The calculation itself which I would brute force

 References:

 http://inder-gnu.blogspot.com/2009/08/find-number-of-digits-in-factorial-of.html

 http://stackoverflow.com/questions/1113167/can-one-know-how-large-a-factorial-would-be-before-calculating-it
 http://delphiforfun.org/programs/big_factorials.htm



 On 2 May 2010 13:59, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 google it... u will gt it

 i am on mobile... cannot explain now..

 On 5/2/10, divya jain sweetdivya@gmail.com wrote:
  wat is tail recursion plz explan in detail
 
  On 2 May 2010 08:15, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
 
  @divya use tail recursion and rest should be fine..
 
  --
  --
  Rohit Saraf
  Second Year Undergraduate,
  Dept. of Computer Science and Engineering
  IIT Bombay
  http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14
 http://www.cse.iitb.ac.in/%7Erohitfeb14
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
  .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 


 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

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




 --
 There are two kinds of people. Those who care for others and The others

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


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



Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
OOPs.. sorry

this doesnt work !

On Sun, May 2, 2010 at 6:11 PM, Algoose Chase harishp...@gmail.com wrote:

 Hi

 will this work ?

 since we need Set S with n pairs of largest values , any such pair within
 the set would (always) contain A[0] or B[0] because they maximize the value
 of the pair.

 so

 // code snippet
 typedef std::vectorint,int Pairs;

 Pairs.push(A[0],B[0])
 int i = 1; // index for ListA
 int j = 1; // index for list B
 count = 1;
 while( count = n)
 {
   if( A[0] + B[j]  B[0] + A[i] )
   {
 Pairs.push(A[0],B[j])
 j++;
   }
   else
   {
  Pairs.Add(A[i],B[0])
  i++;
   }
   count++;
 }

 since there are n items in both the lists, j and i wont go beyond n in the
 while loop


 On Sun, May 2, 2010 at 3:44 PM, Shishir Mittal 1987.shis...@gmail.comwrote:

 This problem has been discussed before @
 http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1aa8cf1ed437/d451cd9468d985f7

 I believe, the problem can't be solved in O(n) but only in O(nlog n).

 @Divya: Are you sure the interviewer explicitly asked for an O(n) time
 algorithm?


 On Sun, May 2, 2010 at 1:48 PM, vignesh radhakrishnan 
 rvignesh1...@gmail.com wrote:

 @divya You're rite. Post a solution if you have one.

 --
 Regards,
 Vignesh


 On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote:

 @Mohit

 according to ur algo if a[1], b[0] has sum greater than a[0],b[1]
 then i is incremented   i is now 2 so for next iteration u ll compare
 a[2] b[0] and a[1] b1]. but what about a[0] b[1] this pair s lost forever.
 think for ths case also.


 On 2 May 2010 11:22, mohit ranjan shoonya.mo...@gmail.com wrote:

 @Algoose Chase

 point taken
 Thanks


 Mohit Ranjan
 Samsung India Software Operations.


 On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote:

 @mohit

 The idea of DP is fine.
 When you find the Max i dont think you need to include A[i+1]+B[j+1]
 because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] 
 since
 both the lists are sorted in decreasing order.


 On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan 
 shoonya.mo...@gmail.com wrote:

 oops

 Sorry didn't read properly
 last algo was for array sorted in ascending order

 for this case, just reverse the process


 A[n] and B[n] are two array

 loop=n, i=0, j=0;


 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of first index from both array
 will be max

   foo = MAX ( A[i+1]+B[j], A[i+1]+B[j+1], A[i]+B[j+1] ) // using
 DP, moving forward

   if foo==A[i+1]+B[j]; i++   // only increment A
   if foo==A[i+1]+B[j+1]; i++; j++   // increment both A and B
   if foo==A[i]+B[j+1]; j++  // increment only B

 }



 Mohit Ranjan
 Samsung India Software Operations.


 On Fri, Apr 30, 2010 at 8:40 PM, mohit ranjan 
 shoonya.mo...@gmail.com wrote:

 Hi Divya,


 A[n] and B[n] are two array

 loop=n, i=n-1, j=n-1;

 while(loop0)  // for n largest pairs
 {
   print A[i]+B[j];  // sum of last index from both array
 will be max

   foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using
 DP moving backward

   if foo=A[i-1]+B[j]; i--   // only reduce A
   if foo=A[i-1]+B[j-1]; i--; j--   // reduce both A and B
   if foo=A[i]+B[j-1]; j--  // reduce only B
 }

 Time: O(n)


 Mohit Ranjan



 On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.comwrote:

 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G,
 let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a
 \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of
 such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n
 pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

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



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


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

Re: [algogeeks] a google question

2010-05-02 Thread Jitendra Kushwaha
Here is a solution of O(n)  , taking 4 pointers 2 for each array


#include cstdio
#includeiostream
using namespace std;

#define N 10

int main(void)
{
int arr1[N] = {8,7,4,3,2,1,1,1,1,1};
int arr2[N] = {34,23,21,19,15,13,11,8,4,2};
int *p11,*p12,*p21,*p22;
p11 = p12 = arr1;
p21 = p22 = arr2;
int f1;
f1 = 0;

for(int i=0;iN;i++) {
int ans=0;
int a,b,c,d;
a = *p11 + *p21;
b = *p11 + *p22;
c = *p21 + *p12;
d = *(p11+1) + *(p21+1);

//printf(a=%d b=%d c=%d d=%d\n,a,b,c,d); //debug

if(f1==0)ans = a  ,p12++ , p22++ , f1=1;

else if(b = c  b = d )ans = b  , p22++ ;

else if(c = b  c = d )ans = c , p12++ ;

elseans = d , p11++ , p21++ ,printf(4 );

printf(%d\n,ans);
}
}


Regards
Jitendra Kushwaha
Undergradute Student
Computer Science  Eng.
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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Where does OS scheduling run??

2010-05-02 Thread CM Saikanth Varma
@Prabagaran
Execution of an instruction, by the CPU, is an ATOMIC operation. Interrupts,
if any, will be processed after the execution of the current instruction.

CPU has interrupt pins attached to it. Whenever an interrupt occurs, the CPU
will be informed about the interrupt through these hardwired pins. That's
how the CPU will get to know the occurrence of an interrupt. For now, please
assume that somehow, these pins will be set to the corresponding values, if
any interrupt occurs.

Please refer to the Intel's Manual for further details on Interrupt
Handling.

Now, when a timer interrupt occurs, the kernel will get to know that the
time quantum assigned to the current process has expired and then it loads
the next waiting process to execute on the CPU.

Hope this helps.

--
CM Saikanth Varma




On Sun, May 2, 2010 at 10:25 PM, praba garan prabagara...@gmail.com wrote:

 @ Pradeep

 *CPU stop its current processing and goes to the interrupt subroutine*

 you have mentioned that the CPU stops its current processing and goes to
 the interrupt subroutine..

 My Question is how does the CPU stops its execution(any special hardware
 involved) because it is busy in executing the current instruction.


 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 4:02 AM, pradeep verma ppradeep...@gmail.comwrote:

 lets suppose Processor executing a instruction(process1) and another
 process2 tries to take the control of CPU so inorder to inform CPU it has to
 interrupt the CPU right
 now we know that if interrupt comes CPU stop its current processing and
 goes to the interrupt subroutine...now CPU knows that its a pre-emption
 interrupt so CPU first run its short term scheduler(this will inform CPU
 that the interruting process priority is less or greater ..n if greater than
 CPU goes to previous process1 preempt it and start executing higher priority
 process2 )

 I think its clear

 Regards
 Pradeep



 On Sun, May 2, 2010 at 3:06 AM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 The link gives the overall abstract idea.
 I am talking in register level.
 When a user process executes

 1. PC program counter will contain the address of the next instruction in
 user code.
 2. Processor registers(accumulator ...) contain the current instruction
 data.

 Then where does the interrupt actually arrives??

 And by that time the user process the control, then who does the
 preempting and how??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 2:35 AM, Guillermo Garcia 
 gegarci...@gmail.comwrote:


 read here - http://en.wikipedia.org/wiki/Preemption_%28computing%29



 Time slice

 The period of time for which a process is allowed to run in a preemptive
 multitasking system is generally called the *time slice*, or *quantum*.
 The scheduler is run once every time slice to choose the next process to
 run. If the time slice is too short then the scheduler will consume too 
 much
 processing time.

 An interrupt http://en.wikipedia.org/wiki/Interrupt is scheduled to
 allow the operating systemhttp://en.wikipedia.org/wiki/Operating_system
 kernel http://en.wikipedia.org/wiki/Kernel_%28computer_science%29 to
 switch between processes when their time slices expire, effectively 
 allowing
 the processor’s time to be shared between a number of tasks, giving the
 illusion that it is dealing with these tasks simultaneously, or
 concurrently. The operating system which controls such a design is called a
 multi-tasking system.




 On Sat, May 1, 2010 at 5:26 PM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 Suppose a user program is executing and and clock interrupt arrives..
 Then who receives the interrupt??
 Can you xplain me the clock interrupt(like any hardwares involved) bit
 detailed??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 1:38 AM, Guillermo Garcia gegarci...@gmail.com
  wrote:

 The scheduler takes control with a clock interruption. Then it
 analyzes if it has to preempt or not the running task.

 On Sat, May 1, 2010 at 5:00 PM, praba garan 
 prabagara...@gmail.comwrote:

 Hi all,
 I have a doubt in OS.
 The scheduler does the process of preemption.
 And one processor can run atmost 1 instruction at a time.
 Then how  where does the scheduler run??

 With Regards,
 Prabagaran.

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


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For 

Re: [algogeeks] Where does OS scheduling run??

2010-05-02 Thread pradeep verma
we know that there are many pins available in microprocessor chips one of
them is INTR(interrupt Req)

When a CPU receives an Interrupt Request (IRQ), it first checks if it must
react to the interrupt. So-called Maskable Interrupts allow a programmer to
specify that the CPU does ignore it, while Non-Maskeable Interrupt requests
must be serviced.

now if a process wants a control of CPU it sends a positive signal on INTR
pin this will interrupt CPU n this is how CPU is being interrupted.

after that CPU stops its current processing 


I think now its clear

Regards
Pradeep

On Sun, May 2, 2010 at 10:25 PM, praba garan prabagara...@gmail.com wrote:

 @ Pradeep

 *CPU stop its current processing and goes to the interrupt subroutine*

 you have mentioned that the CPU stops its current processing and goes to
 the interrupt subroutine..

 My Question is how does the CPU stops its execution(any special hardware
 involved) because it is busy in executing the current instruction.


 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 4:02 AM, pradeep verma ppradeep...@gmail.comwrote:

 lets suppose Processor executing a instruction(process1) and another
 process2 tries to take the control of CPU so inorder to inform CPU it has to
 interrupt the CPU right
 now we know that if interrupt comes CPU stop its current processing and
 goes to the interrupt subroutine...now CPU knows that its a pre-emption
 interrupt so CPU first run its short term scheduler(this will inform CPU
 that the interruting process priority is less or greater ..n if greater than
 CPU goes to previous process1 preempt it and start executing higher priority
 process2 )

 I think its clear

 Regards
 Pradeep



 On Sun, May 2, 2010 at 3:06 AM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 The link gives the overall abstract idea.
 I am talking in register level.
 When a user process executes

 1. PC program counter will contain the address of the next instruction in
 user code.
 2. Processor registers(accumulator ...) contain the current instruction
 data.

 Then where does the interrupt actually arrives??

 And by that time the user process the control, then who does the
 preempting and how??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 2:35 AM, Guillermo Garcia 
 gegarci...@gmail.comwrote:


 read here - http://en.wikipedia.org/wiki/Preemption_%28computing%29



 Time slice

 The period of time for which a process is allowed to run in a preemptive
 multitasking system is generally called the *time slice*, or *quantum*.
 The scheduler is run once every time slice to choose the next process to
 run. If the time slice is too short then the scheduler will consume too 
 much
 processing time.

 An interrupt http://en.wikipedia.org/wiki/Interrupt is scheduled to
 allow the operating systemhttp://en.wikipedia.org/wiki/Operating_system
 kernel http://en.wikipedia.org/wiki/Kernel_%28computer_science%29 to
 switch between processes when their time slices expire, effectively 
 allowing
 the processor’s time to be shared between a number of tasks, giving the
 illusion that it is dealing with these tasks simultaneously, or
 concurrently. The operating system which controls such a design is called a
 multi-tasking system.




 On Sat, May 1, 2010 at 5:26 PM, praba garan prabagara...@gmail.comwrote:

 @ Guillermo Garcia

 Suppose a user program is executing and and clock interrupt arrives..
 Then who receives the interrupt??
 Can you xplain me the clock interrupt(like any hardwares involved) bit
 detailed??

 With Regards,
 Prabagaran.



 On Sun, May 2, 2010 at 1:38 AM, Guillermo Garcia gegarci...@gmail.com
  wrote:

 The scheduler takes control with a clock interruption. Then it
 analyzes if it has to preempt or not the running task.

 On Sat, May 1, 2010 at 5:00 PM, praba garan 
 prabagara...@gmail.comwrote:

 Hi all,
 I have a doubt in OS.
 The scheduler does the process of preemption.
 And one processor can run atmost 1 instruction at a time.
 Then how  where does the scheduler run??

 With Regards,
 Prabagaran.

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


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

Re: [algogeeks] Where does OS scheduling run??

2010-05-02 Thread harit agarwal
although CPU is busy in exexcution...it check's its registers values for the
pending interrupts ..
if any interrupt is pending at the end of the current CPU cycle...it
shedules the interrupt handler to further execute the interrupt
subroutine...

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



[algogeeks] What happens when you double click a file??

2010-05-02 Thread praba garan
What happens when you double click a file??
(changes in Kernel DATA STRUCTURES and interrupts)

With Regards,
Prabagaran.

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