Question: Given two pointers to the root nodes of two different, unbalanced, binary search trees (TreeNode * ptr), write a function compare to determine if

Given two pointers to the root nodes of two different, unbalanced, binary

Given two pointers to the root nodes of two different, unbalanced, binary search trees (TreeNode * ptr), write a function "compare" to determine if the two trees contain the same values. You may assume each node has a data section and left, right and parent pointer, but may not assume any other items exist in the nodes. Your solution should be as efficient as possible both in terms of space and time complexity.

Step by Step Solution

3.47 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To compare two binary search trees efficiently we can pe... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!