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:
>
@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
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
@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
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
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
@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
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
+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
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
// 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);
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???
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???
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
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
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
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
> / \
>
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:
>
5
/\
3 4
is this subtree of
1
/ \
34
/ \
51
/ \
34
/
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
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
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
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
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
@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
@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(
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
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_
28 matches
Mail list logo