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

2012-03-20 Thread atul anand
this will work even if run length is 1. #include #define MAX 1000 int copy(char *str,int len) { int max_len=MAX-1,i; for(i=len-1;i>=0;i--) { str[max_len]=str[i]; max_len--; } return max_len+1; } void runLength(char *str) { unsigned int j,k=1,loop=0,res_len=0; int i,n_

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

2012-03-20 Thread atul anand
using Gene logic , but we need to take care of number with more than 1 digits , so updated gene's code is as follows :- #include #define MAX 1000 int copy(char *str,int len) { int max_len=MAX-1,i; for(i=len-1;i>=0;i--) { str[max_len]=str[i]; max_len--; } return max_l

Re: [algogeeks] Explain the code

2012-03-20 Thread Sajal Choudhary
@amit: *1. **printf *returns the length of the string it outputs. i.e. printf("%d",printf("abcd")) ==> will give 4 as output. 2. Also in printf("%*s) , %**s *tells to read the precision field from the next argument provided in printf(). Here *printf("%*s%*s",a,"",b,"") *is equivalent to* printf(

Re: [algogeeks] Explain the code

2012-03-20 Thread Amit Kumar
@sajal I mean the same. Warm Regards Amit Kumar Master Of Computer Applications 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 g

Re: [algogeeks] Explain the code

2012-03-20 Thread rahul
I thought it print 12 because 2 is printed by insider printf ( because of 2 string) and 1 is printed by outsider printf( 1 print) statement, how come sum of two strings came into picture. On Tue, Mar 20, 2012 at 1:42 PM, Amit Kumar wrote: > @sajal > I mean the same. > > > > > Warm Regards > Ami

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

2012-03-20 Thread Gene
I don't think you're seeing the requirement completely. The problem promises only that the output buffer will be big enough to hold the output. You have made it huge. I tried your code on an input of a1b1c6 with the required output space of 8 characters (plus 1 for the C null character), and i

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

2012-03-20 Thread Dheeraj Sharma
How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

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

2012-03-20 Thread Dheeraj Sharma
How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

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

2012-03-20 Thread vIGNESH v
FROM, V.VIGNESH. On 20 March 2012 17:58, Dheeraj Sharma wrote: > How to check if one binary tree is a sub tree of other? > Any Solution other then bruteforce? > Prototype > bool check(node *t1,node *subtree) > > -- > Sent from my mobile device > > *Dheeraj Sharma* > > -- > You received this me

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

2012-03-20 Thread shady
5 /\ 3 4 is this subtree of 1 / \ 34 / \ 51 / \ 34 /

Re: [algogeeks] Re: Google written test

2012-03-20 Thread Hemesh Singh
Isn't it a standard subset sum problem? You can generate the Fibonacci numbers and put them in an array. Now just apply the standard algorithm to find that which Fibonacci numbers add up to make the given sum. Please correct me if I am wrong. On Mon, Mar 19, 2012 at 8:58 PM, atul anand wrote: >

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

2012-03-20 Thread rahul sharma
http://www.geeksforgeeks.org/archives/13942 then call for On Tue, Mar 20, 2012 at 7:16 PM, shady wrote: > 5 > /\ > 3 4 > > is this subtree of > > 1 > / \ >

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

2012-03-20 Thread Dheeraj Sharma
Geeksforgeeks gives brute force approach @shady.. No its not..the sub tree should be a perfect sub tree..there should be no node below that sub tree in the main tree On 3/20/12, rahul sharma wrote: > http://www.geeksforgeeks.org/archives/13942 > > then call for > > On Tue, Mar 20, 2012 at 7:16 PM

Re: [algogeeks] Vertical Sum in a given Binary Tree

2012-03-20 Thread rahul sharma
we have to include every node??if distance for two or more nodes is same they are summed???m i ryt???i doubt On Mon, Mar 19, 2012 at 9:36 PM, shady wrote: > oops no 2 there > > > On Mon, Mar 19, 2012 at 9:36 PM, shady wrote: > >> if tree is like >> >> 1 / \ 2 3 / \ / \ 4 5 6 7 >> / \ >> 12 -8

Re: [algogeeks] Vertical Sum in a given Binary Tree

2012-03-20 Thread shady
yes, that's what he wrote in the definition of vertical sum as well. On Tue, Mar 20, 2012 at 10:24 PM, rahul sharma wrote: > we have to include every node??if distance for two or more nodes is same > they are summed???m i ryt???i doubt > > > On Mon, Mar 19, 2012 at 9:36 PM, shady wrote: > >> oo

Re: [algogeeks] Vertical Sum in a given Binary Tree

2012-03-20 Thread rahul sharma
ohk...thnx all... On Tue, Mar 20, 2012 at 11:03 PM, shady wrote: > yes, that's what he wrote in the definition of vertical sum as well. > > > On Tue, Mar 20, 2012 at 10:24 PM, rahul sharma wrote: > >> we have to include every node??if distance for two or more nodes is same >> they are summed???

Re: [algogeeks] Vertical Sum in a given Binary Tree

2012-03-20 Thread rahul sharma
ohk...thnx all... On Tue, Mar 20, 2012 at 11:03 PM, shady wrote: > yes, that's what he wrote in the definition of vertical sum as well. > > > On Tue, Mar 20, 2012 at 10:24 PM, rahul sharma wrote: > >> we have to include every node??if distance for two or more nodes is same >> they are summed???

[algogeeks] Re: Vertical Sum in a given Binary Tree

2012-03-20 Thread Don
// Assuming a vector container template class which allocates space as needed and allows negative index values vector result = {0}; void verticalSum(tree *root, int dist=0) { if (root) { result[dist] += root->val; verticalSum(tree->left, dist-1); verticalSum(tree->right, dist+1);

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

2012-03-20 Thread Don
bool equals(node *t1, node *t2) { return (t1 && t2) ? (t1->value == t2->value) && equals(t1->left, t2- >left) && equals(t1->right, t2->right) : !t1 && !t2; } bool check(node *t1, node *subtree) { return t1 ? equals(t1, subtree) || check(t1->left, subtree) || check(t1->right, subtree) : !subtre

Re: [algogeeks] ITRIX'12 OPC

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

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

2012-03-20 Thread HARSHIT PAHUJA
bool isSubtree(Tree * A,Tree *B) { if(!B) return true; if(!A)return false; if(A->data==B->data) return (isSubtree(A->left,B->left) && isSubtree(A->right,B->right)); else return (isSubtree(A->left,B) && isSubtree(A->right,B)); } } On Wed, Mar 21, 2012 at 2:33

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

2012-03-20 Thread atul anand
@Gene : yes you are right , i misunderstood the problem . so m/m available is just enough to hold the output. thanks for correcting ... that would make this ques little interesting :) :)...i guess my first posted code can be modified to meet the requirement. i will post the updated code. On Tue, M

Re: [algogeeks] Explain the code

2012-03-20 Thread siddharam suresh
output is: 12(12 white spaces before 12) Thank you, Sid. phone:+91-8971070727, +91-9916809982 On Tue, Mar 20, 2012 at 5:30 PM, rahul wrote: > I thought it print 12 because 2 is printed by insider printf ( because of > 2 string) and 1 is printed by outsider printf( 1 print) statemen

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

2012-03-20 Thread siddharam suresh
get the inorder traversal both tree (into strings) check weather one string substring of other if yes then one tree is sub tree of other. Thank you, Sid. phone:+91-8971070727, +91-9916809982 On Wed, Mar 21, 2012 at 9:23 AM, HARSHIT PAHUJA wrote: > bool isSubtree(Tree * A,Tree *B) > { > > if(!B

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

2012-03-20 Thread shady
@Sid +100 On Wed, Mar 21, 2012 at 10:20 AM, siddharam suresh wrote: > get the inorder traversal both tree (into strings) check weather one > string substring of other if yes then one tree is sub tree of other. > > > Thank you, > Sid. > phone:+91-8971070727, > +91-9916809982 > > > > On Wed, Mar 21

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

2012-03-20 Thread Dheeraj Sharma
No..am nt talking about binary search tree..bt about binary tree.. It was asked in my amazon written @shady..doing the substring search..as we have to search for subset of tree..it searchng substrn might find some false nodes..that doesnt belong to that subtree On 3/21/12, Don wrote: > bool equ

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

2012-03-20 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 str1

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

2012-03-20 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 wrote: >