Invert Binary Tree
Description
In this lesson, your task is to invert a given a binary tree, T.
Let’s look at an example below:
Invert binary tree
Solution
We can solve this problem using depth-first search (DFS).
The inverse of an empty tree is the empty tree. To invert tree T with root and subtrees left and right, we keep root the same and invert the right and left subtrees.
Let’s review the implementation below:
Invert binary tree
Complexity measures
| Time Complexity | Space Complexity |
|---|---|
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy