Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread amrit harry
@sidarth your method would not work it think. let a case sub tree: 4Main tree: 6 5 6 4 7 5 8 inorder traversal of sub tree

Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread Mahesh Thakur
First Tree: 1 2 3 4 5 67 Inorder traverse will be : 4251637 Second Tree: 6 1 3 Inorder traversal is 163. But they second tree is not subset. let me know if i got the question wrong. On Wed, Mar 21, 2012 at 10:27 AM, shady

[algogeeks] Amazon question

2012-03-21 Thread amrit harry
hi i found this qstn frum career cup pls help to solve this. Given an integer n, compute 2 integers x, y satisfying: n=x*y=n+2; |x-y| is minimal. Thanks Regards Amrit -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion

Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread shady
seems correct with pre-order traversal if not give some example On Wed, Mar 21, 2012 at 10:32 AM, Mahesh Thakur tmahesh...@gmail.comwrote: First Tree: 1 2 3 4 5 67 Inorder traverse will be : 4251637 Second Tree: 6 1 3

Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread amrit harry
@shady consider this case Main tree 1 subtree 1 2 3 2 4 3 preorder of Main= 1234 subtree= 123 but not subtree On Wed, Mar 21, 2012 at 1:24 PM, shady sinv...@gmail.com

Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread amrit harry
i have an idea to solve this. use preorder traversal and a sentinal(#) on the place of Null nodes. lets take a example Main tree 1 subtree 1 2 3 2 4 3

Re: [algogeeks] Re: Run Length Decoding... inplace

2012-03-21 Thread atul anand
wasnt able to come up with an algo which would satisfy all the cases input like a1b1c4 here output length is equal to input length . till now i dont knw how to handle these type of input. :( :( On Wed, Mar 21, 2012 at 10:02 AM, atul anand atul.87fri...@gmail.comwrote: @Gene : yes you are right

Re: [algogeeks] Amazon question

2012-03-21 Thread Rujin Cao
One possible way is: 1) Put the three candidate number together into an array [n, n + 1, n + 2] 2) Iterate each element *E* in that array and test whether *E* is a prime number 2.1) If it is, there will be only one way to find the two numbers product to be *E*, i.e. {x = 1, y = E} OR {x =

Re: [algogeeks] Re: Google written test

2012-03-21 Thread atul anand
@Hemesh : dats would be an over kill , you are converting O(n) solution to a subset sum problem which NP On Tue, Mar 20, 2012 at 7:35 PM, Hemesh Singh hemesh.mn...@gmail.comwrote: Isn't it a standard subset sum problem? You can generate the Fibonacci numbers and put them in an array. Now just

Re: [algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread atul anand
@amrit : i guess this will work. On Wed, Mar 21, 2012 at 1:51 PM, amrit harry dabbcomput...@gmail.comwrote: i have an idea to solve this. use preorder traversal and a sentinal(#) on the place of Null nodes. lets take a example Main tree 1 subtree 1

[algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread Dheeraj Sharma
Yeah..i wrote sumthig similar..i placed L for left null and R for right null..and then checked for substring in preorder traversal..i dont know if its correct or not.. On 3/21/12, atul anand atul.87fri...@gmail.com wrote: @amrit : i guess this will work. On Wed, Mar 21, 2012 at 1:51 PM, amrit

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-03-21 Thread Anurag atri
@Sunny: A little doubt, how are you making sure that the candidate sum is actually a sum that can be formed by contiguous elements of the array? Can you please explain your algo for this array : 1 , 2 , 99 , 100 , we need the 3rd smallest sum. On Wed, Feb 22, 2012 at 3:11 PM, atul anand

[algogeeks] Re: Check if one tree is sub tree of other

2012-03-21 Thread Lucifer
@All [ Let the tree to be searched in be 'T' and the subtree to be matched be 'S'] If i understood the previous posts correctly.. then basically we discussed about 2 methods: 1) Brute force, wherein we consider each node of the 'T' as the root of new subtree and try to compare it with 'S'.

Re: [algogeeks] Re: Run Length Decoding... inplace

2012-03-21 Thread Ashish Goel
Gene, Atul How would a string of say 257 or say 10 times a would be represented, will it be a10 or aascii of 10 Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Mar 21, 2012 at 2:04 PM, atul anand atul.87fri...@gmail.com wrote: wasnt able to

Re: [algogeeks] Amazon question

2012-03-21 Thread atul anand
@Rujin : mathematically point 2.2 seems straight forward but can we achieve value of x and y with an algo whose complexity wud be O(sqrt(E)) ?? On Wed, Mar 21, 2012 at 2:37 PM, Rujin Cao drizzle...@gmail.com wrote: One possible way is: 1) Put the three candidate number together into an array