Pages

06/06/2021

[Java] Check if two binary trees are equal

A simple problem necessary for another one I've been working on: given two binary trees, determine whether they are equal.

A O(N) solution time and space is simply to do a parallel BFS on both trees and break as soon as we find a non matching value.

You can check my implementation of areEqualBST on my Gist along with some tests in AreBSTEqualJTests.

No comments:

Post a Comment

With great power comes great responsibility