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

后端 未结 12 853
慢半拍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:25

    Duplicate Keys • What happens if there's more than one data item with the same key? – This presents a slight problem in red-black trees. – It's important that nodes with the same key are distributed on both sides of other nodes with the same key. – That is, if keys arrive in the order 50, 50, 50, • you want the second 50 to go to the right of the first one, and the third 50 to go to the left of the first one. • Otherwise, the tree becomes unbalanced. • This could be handled by some kind of randomizing process in the insertion algorithm. – However, the search process then becomes more complicated if all items with the same key must be found. • It's simpler to outlaw items with the same key. – In this discussion we'll assume duplicates aren't allowed

    One can create a linked list for each node of the tree that contains duplicate keys and store data in the list.

提交回复
热议问题