jeudi 27 mai 2010

Given two binary trees, return true if they have same elements (irrespective of tree structure)

We need to traverse the trees and compare their elements.
We could traverse each tree and store each of their different elements in two arrays. Then we sort the array and verify that they are identical.

Question/Assumption: What about the frequency of items? With the previous approach we do not take into account the fact that some items may be repeated a different nb of times

Aucun commentaire:

Enregistrer un commentaire