Re: [algogeeks] 400!

2010-05-03 Thread Rajesh Patidar
you have to store the result some where for that you don't have
inbuilt datatype like python those will take care of your overflow

On Mon, May 3, 2010 at 9:46 AM, siddharth srivastava
akssps...@gmail.com wrote:
 But is there any way to accomplish this without an array ? Even for 100!.

 On 2 May 2010 06:15, Prasoon Mishra prasoonbluel...@gmail.com wrote:

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




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

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



 --
 Siddharth Srivastava

 Human Knowledge is for all

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




-- 
BL/\CK_D!AMOND

-- 
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-03 Thread Rajesh Patidar
ya string one even will be more suitable way..

On Mon, May 3, 2010 at 5:33 PM, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
 are forget abt representation. It can be stored as string anyways.
 Tail recursion is awesome at times !
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14


 On Mon, May 3, 2010 at 9:46 AM, siddharth srivastava akssps...@gmail.com
 wrote:

 But is there any way to accomplish this without an array ? Even for 100!.

 On 2 May 2010 06:15, Prasoon Mishra prasoonbluel...@gmail.com wrote:

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




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

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



 --
 Siddharth Srivastava

 Human Knowledge is for all

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

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to 

Re: [algogeeks] 400!

2010-05-01 Thread Rajesh Patidar
take an long array of integer (to store the answer)
let Mod=1 (maximum allowable size or number in the array element
initialize the last element of array with 1
and know start multiplying the 1--n into the last number to first of array
if any number crosses the given then take
 m=a[i]/mod
and set a[i]=a[i]%Mod;
 and add m to the next adjacent element

eg let calculating 5!
taken an array of integer and Mod=10
A={0,0,1}
mutliplying 1 in all from the back side
A={0,0,1}
multiplying 2
A={0,0,2}
multiplying 3
A={0,0,6}
multiplying 4
the number in the last element goes 24
so setting 24%10 =4 stetting it into the that element and adding
24/10=2 to the next
A=[0,2,4}
multiplying 5
4*5=20(setting 0 and adding 2 to next}
2*5+2=12(setting 2 and adding 1 to next)
0*5+1=1
so A={1,2,0}


On Sat, May 1, 2010 at 3:06 PM, divya sweetdivya@gmail.com wrote:
 give an algo to calculate 300! or even 400!

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





-- 
BL/\CK_D!AMOND

-- 
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] Build BST from binary tree without extra space

2010-04-30 Thread Rajesh Patidar
thing is that u r using recursion and we don't have to use it(
recussion  use memory indirectly) as per the question

On Thu, Apr 29, 2010 at 3:55 PM, Algoose Chase harishp...@gmail.com wrote:
 If you mean to convert the binary tree to binary search tree directly , then

 BinarytoBST(Node* root)
 {
    if( root == nulll) return;

    BinarytoBST(root-left);
    BinarytoBST(root-right);

    if( root-left )
    Node* NodeL = MAX(root-left);
    if ( root-right )
    Node* NodeR = MIN(root-right);

    if( NodeL-Data  root-data)
    {
    // swap values.
    temp = NodeL-data;
    NodeL-data = root-data;
    root-data = temp;

    BinarytoBST(NodeL);
    }
    if( NodeR-Data = root-data)
    {
    // swap values.
    temp = NodeR-data;
    NodeR-data = root-data;
    root-data = temp;

    BinarytoBST(NodeR);
    }

 



 On Thu, Apr 29, 2010 at 11:23 AM, Algoose Chase harishp...@gmail.com
 wrote:

 Hi,

 How do you define without extra space ?
 Doing any order traversal either using recursion or using iteration is
 going to take extra space .

 If you are given a binary tree represented by pointers that points to
 children nodes is it possible to do a heap sort without an array ?

 On Thu, Apr 29, 2010 at 6:59 AM, sharad kumar aryansmit3...@gmail.com
 wrote:

 my choice is build  a min heap .sort the array with heap sort.then find
 the median of the sorted array and build tree

 On Wed, Apr 28, 2010 at 10:16 PM, Vivek S s.vivek.ra...@gmail.com
 wrote:

 @Rajesh Patidar
 I think we should do in Post order traversal alone. If we go by
 Preorder/Inorder we might lose track of children node that is currently
 being inserted into the BST. - correct me if im wrong :)

 On 28 April 2010 15:30, Rajesh Patidar patidarc...@gmail.com wrote:

 pickup node in any order no matter(pre,post,inorder)  and just one by
 one. start adding the node into bst no need to use extra space u have
 to just ditach the node from binary tree and attach it in bst.

 On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra amishra@gmail.com
 wrote:
  How to build BST from binary tree in place i.e without extra space ??
 
  --
  You received this message because you are subscribed to the Google
  Groups
  Algorithm Geeks group.
  To post to this group, send email to 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.
 



 --
 BL/\CK_D!AMOND

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




 --
 Reduce, Reuse and Recycle
 Regards,
 Vivek.S

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



 --
 yezhu malai vaasa venkataramana Govinda Govinda

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


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




-- 
BL/\CK_D!AMOND

-- 
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-04-30 Thread Rajesh Patidar
ignore the previous mail it wrongly send.

On Fri, Apr 30, 2010 at 11:12 PM, Rajesh Patidar patidarc...@gmail.com wrote:
 let consider the list in two different part one traversing list B with
 respect to A and A with B
 (a.len,b.len) is always solution
 a1=a2=a.len

 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.com.
 For more options, visit this group at 
 http://groups.google.com/group/algogeeks?hl=en.





 --
 BL/\CK_D!AMOND




-- 
BL/\CK_D!AMOND

-- 
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] Build BST from binary tree without extra space

2010-04-29 Thread Rajesh Patidar
ya post order traversal will not have these problem theme time i
haven't thought the problem with pre and inorder.

On Wed, Apr 28, 2010 at 10:16 PM, Vivek S s.vivek.ra...@gmail.com wrote:
 @Rajesh Patidar
 I think we should do in Post order traversal alone. If we go by
 Preorder/Inorder we might lose track of children node that is currently
 being inserted into the BST. - correct me if im wrong :)

 On 28 April 2010 15:30, Rajesh Patidar patidarc...@gmail.com wrote:

 pickup node in any order no matter(pre,post,inorder)  and just one by
 one. start adding the node into bst no need to use extra space u have
 to just ditach the node from binary tree and attach it in bst.

 On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra amishra@gmail.com
 wrote:
  How to build BST from binary tree in place i.e without extra space ??
 
  --
  You received this message because you are subscribed to the Google
  Groups
  Algorithm Geeks group.
  To post to this group, send email to 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.
 



 --
 BL/\CK_D!AMOND

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




 --
 Reduce, Reuse and Recycle
 Regards,
 Vivek.S

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




-- 
BL/\CK_D!AMOND

-- 
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] Build BST from binary tree without extra space

2010-04-29 Thread Rajesh Patidar
@ashish
i forgot recussion uses memory but if we have to do it without using
stack also then
pickup the root and add it to the bst and to fill the vacant position
of root choose left node and make it root and to adjust previous right
node at it to leaf
eg :

  D
   / \
  A  E
/ \
  B  C
add D to the BST and add E to the leaf
  A
   / \
  B C
/
  E
adding E to the leaf node can be done memory without using extra memory.



On Wed, Apr 28, 2010 at 8:22 PM, Ashish Mishra amishra@gmail.com wrote:
 @rajesh can u explain your soln
 how u r doing inorder, pre or whatever (without using stack) and at same
 time build BST

 On Wed, Apr 28, 2010 at 3:30 PM, Rajesh Patidar patidarc...@gmail.com
 wrote:

 pickup node in any order no matter(pre,post,inorder)  and just one by
 one. start adding the node into bst no need to use extra space u have
 to just ditach the node from binary tree and attach it in bst.

 On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra amishra@gmail.com
 wrote:
  How to build BST from binary tree in place i.e without extra space ??
 
  --
  You received this message because you are subscribed to the Google
  Groups
  Algorithm Geeks group.
  To post to this group, send email to 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.
 



 --
 BL/\CK_D!AMOND

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




 --
 Ashish Mishra
 http://ashishmishra.weebly.com/

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




-- 
BL/\CK_D!AMOND

-- 
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] Build BST from binary tree without extra space

2010-04-28 Thread Rajesh Patidar
pickup node in any order no matter(pre,post,inorder)  and just one by
one. start adding the node into bst no need to use extra space u have
to just ditach the node from binary tree and attach it in bst.

On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra amishra@gmail.com wrote:
 How to build BST from binary tree in place i.e without extra space ??

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




-- 
BL/\CK_D!AMOND

-- 
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] first K digit

2010-03-04 Thread rajesh patidar
i wanna to know how to find the kirst k digit of n^n
n can wary from 0n10^9

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