Skip to content

Update 20160422_binary_tree.md#4

Open
nostrademons wants to merge 1 commit intovkarpov15:masterfrom
nostrademons:patch-1
Open

Update 20160422_binary_tree.md#4
nostrademons wants to merge 1 commit intovkarpov15:masterfrom
nostrademons:patch-1

Conversation

@nostrademons
Copy link

Doesn't the original code reverse t destructively? Javascript passes objects mutably, so when you've assigned to t.left and t.right, you've altered the original tree. This doesn't affect the answer you get out of isSymmetric (as long as the two subtrees do not share structure, i.e. you're not actually working with a graph), but would be a very unexpected side-effect for a user of isSymmetric.

Doesn't the original code reverse t *destructively*?  Javascript passes objects mutably, so when you've assigned to t.left and t.right, you've altered the original tree.  This doesn't affect the answer you get out of isSymmetric (as long as the two subtrees do not share structure, i.e. you're not actually working with a graph), but would be a very unexpected side-effect for a user of isSymmetric.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant