4

I have a very simple question regarding BSTs. I have seen multiple definitions of BSTs regarding duplicate entries. Some define BSTs as not allowing duplicate entries, others that node's left child is <= to the nodes value and the right child is greater than the node's value, and some definitions are the opposite of that ( left child is < than the node, right child is >=).

So my question is what is the official definition (if one exists) for BSTs regarding duplicate entries? For example what would a BST look like after inserting the values : 3, 5, 10, 8, 5, 10?

Thank you in advance for clarifying the definition and answering my question!

Tareq
  • 788
  • 6
  • 8
  • "official definition"? What would you consider "official"? What level of authority is required here? – S.Lott Jan 02 '12 at 18:35
  • I guess it's not so much level of authority, as much as it is what is the most commonly accepted definition of BSTs regarding duplicate entries. – Tareq Jan 02 '12 at 19:14

2 Answers2

6

One of the well-known books in the algorithm and data structure area is the CLRS book, also known as the bible of data structures and algorithms:

enter image description here

According to the definition of this book, the duplicate entries are placed in the right tree of the node that contains the same key. As an example, take a look at the insertion algorithm of BSTs adopted from this book:

enter image description here

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
3

the important point is that not having duplicates in the tree assures the fast lookup times. If you have duplicates in one side of the node your search time will suffer because you have to go through all duplicates before you can continue.

http://en.wikipedia.org/wiki/Binary_search_tree

light_303
  • 2,101
  • 2
  • 18
  • 35