We have the following algorithm that allows us to generate a binary tree.
root <- INSERT(x, v) // x is the root and v is the key we want to insert in the tree.
//The definition of the algorithm
INSERT(x, v):
if x is an external node:
y <- new node with key v
return y
if v < x.key:
x.left <- INSERT(x.left, v)
else:
x.right <- INSERT(x.right, v)
return x
The tree is built by a sequence of INSERT(root, v) we provide each time the current root and the key we want to insert.
I want to prove or find a counter-example to the following affirmation: If we purposefully insert a key in such a way that it violates the binary tree propriety (left_child <= parent <= right_child) but continue inserting compliant keys afterwards, the only misplaced node will be that one we purposefully misplaced. This also implies that the violating node will only have one child.
To illustrate I made this schema (the red node should contain 20 and not 10):
As you notice the red key (is 20 not 10) is our violation and the keys that comes after it are correct keys. We can see in that example that the only key in violation is the red one. It does not impact the keys that comes after it.
This is just one example. I haven't found a counter-example yet. I want to know how can I generally prove this without having to rely in my proof on specific examples.
