MCPcopy Create free account
hub / github.com/SR-Sunny-Raj/Hacktoberfest2021-DSA / isSubtree

Function isSubtree

14. Tree/check_binary_tree_subtree.cpp:39–57  ·  view source on GitHub ↗

This function returns true if S is a subtree of T, otherwise false */

Source from the content-addressed store, hash-verified

37/* This function returns true if S
38is a subtree of T, otherwise false */
39bool isSubtree(node *T, node *S)
40{
41 /* base cases */
42 if (S == NULL)
43 return true;
44
45 if (T == NULL)
46 return false;
47
48 /* Check the tree with root as current node */
49 if (areIdentical(T, S))
50 return true;
51
52 /* If the tree with root as current
53 node doesn't match then try left
54 and right subtrees one by one */
55 return isSubtree(T->left, S) ||
56 isSubtree(T->right, S);
57}
58
59
60/* Helper function that allocates

Callers 1

mainFunction · 0.85

Calls 1

areIdenticalFunction · 0.85

Tested by

no test coverage detected