Are duplicate keys allowed in the definition of binary search trees?

I’m trying to find the definition of a binary search tree and I keep finding different definitions everywhere.

Some say that for any given subtree the left child key is less than or equal to the root.

Some say that for any given subtree the right child key is greater than or equal to the root.

And my old college data structures book says “every element has a key and no two elements have the same key.”

Is there a universal definition of a bst? Particularly in regards to what to do with trees with multiple instances of the same key.

EDIT: Maybe I was unclear, the definitions I’m seeing are

1) left <= root < right

2) left < root <= right

3) left < root < right, such that no duplicate keys exist.

12 Answers
12

Leave a Comment