MCPcopy Create free account
hub / github.com/careercup/ctci / subTree

Method subTree

java/Chapter 4/Question4_8/Question.java:20–27  ·  view source on GitHub ↗
(TreeNode r1, TreeNode r2)

Source from the content-addressed store, hash-verified

18 * rooted at r2 as a subtree somewhere within it.
19 */
20 public static boolean subTree(TreeNode r1, TreeNode r2) {
21 if (r1 == null)
22 return false; // big tree empty & subtree still not found.
23 if (r1.data == r2.data) {
24 if (matchTree(r1,r2)) return true;
25 }
26 return (subTree(r1.left, r2) || subTree(r1.right, r2));
27 }
28
29 /* Checks if the binary tree rooted at r1 contains the
30 * binary tree rooted at r2 as a subtree starting at r1.

Callers 1

containsTreeMethod · 0.95

Calls 1

matchTreeMethod · 0.95

Tested by

no test coverage detected