We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Am afraid, that's an inaccurate statement from the author. You can have duplicates as long as your satisfy the BST property. Just to quote Cormen, "The keys in a binary search tree are always stored in such a way as to satisfy the
binary-search-tree property:
Let x be a node in a binary search tree. If y is a node in the left subtree
of x, then y:key <= x:key. If y is a node in the right subtree of x, then
y:key >= x:key.". However the point to be noted is, the duplicate conditions are trivial.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Am afraid, that's an inaccurate statement from the author. You can have duplicates as long as your satisfy the BST property. Just to quote Cormen, "The keys in a binary search tree are always stored in such a way as to satisfy the binary-search-tree property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then y:key <= x:key. If y is a node in the right subtree of x, then y:key >= x:key.". However the point to be noted is, the duplicate conditions are trivial.