Back to Learning Paths
Tree Problems

شرح LeetCode 572 - Subtree of Another Tree

Subtree of Another Tree Using C++ Time Complexity = O(N × M) because for each of the N nodes in root, we might check all M nodes in subRoot using isSameTree. Worst case happens when many nodes match and we compare the full subtree each time. (it can be reduced to O(N + M)) Try To Do IT ! Space complexity: O(N + M)

More from Tree Problems