Equivalent Binary Trees
Last updated
Last updated
Two binary trees are equivalent if the sequences from their in order traversals are the same.
An easy approach is to construct with time and space . Just in order traverse tree A and store that and traverse tree B then store that and compare in the end.
We can compute the next value in the iterator in parallel after retrieving it. That will be a lot faster if the tree depth is high.
Goroutine is a more powerful version of coroutine because it can be parallelized.
A better way is to use two iterators to terminate early and only use the space.
A tour of go -
Stackoverflow -