0

I am trying to disprove this statement that for each two nodes v and w in a binary search tree if you delete v and then w will be the same as deleting w and then v.

I'm looking for a counter example, I hope someone can help me with that.

Thank you in advance

Scarlett Lux
  • 73
  • 1
  • 5
  • 1
    Possible duplicate of [Deletion procedure for a Binary Search Tree](http://stackoverflow.com/questions/2990486/deletion-procedure-for-a-binary-search-tree) –  Jun 07 '16 at 14:36

1 Answers1

0

The property of BST is that there's an ordering relationship between every node and its children. Therefore, irrespective of the order in which deletion is going to performed, the relationship between the nodes should stay intact.

An easy way to prove this is printing the elements of tree on in inorder form:

1.) Delete x, then y, and print all elements in inorder form

2.) Delete y, then x, and print all elements in inorder form

One of the properties of inorder expression is that it will always print the BST values in the sorted order. Therefore, if both (1) and (2) are sorted, and the in the same order, we'll have proved that deletion of x followed by y is the same as deletion of y followed by x since the BST node relationship remains intact.

attaboy182
  • 2,039
  • 3
  • 22
  • 28
  • The inorder traversals being the same does not prove that the trees have the same shape. In fact, the first answer to this question, http://stackoverflow.com/questions/2990486/deletion-procedure-for-a-binary-search-tree, shows an example in which changing the deletion order results in different trees. – Jim Mischel Jun 09 '16 at 13:14