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

后端 未结 12 858
慢半拍i
慢半拍i 2020-11-29 15:40

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 k

12条回答
  •  一生所求
    2020-11-29 16:24

    1.) left <= root < right

    2.) left < root <= right

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

    I might have to go and dig out my algorithm books, but off the top of my head (3) is the canonical form.

    (1) or (2) only come about when you start to allow duplicates nodes and you put duplicate nodes in the tree itself (rather than the node containing a list).

提交回复
热议问题