## Heap vs Binary Search Tree (BST)

What is the difference between a heap and BST? When to use a heap and when to use a BST? If you want to get the elements in a sorted fashion, is BST better over heap? 8 Answers 8

What is the difference between a heap and BST? When to use a heap and when to use a BST? If you want to get the elements in a sorted fashion, is BST better over heap? 8 Answers 8

Why is std::map implemented as a red-black tree? There are several balanced binary search trees (BSTs) out there. What were design trade-offs in choosing a red-black tree? 6 Answers 6

Can anyone please explain the difference between binary tree and binary search tree with an example? 12 Answers 12

Sure – you simply can’t apply the > operator between objects. What would you expect it to do? You can’t apply any of the other binary operators either – +, -, / etc (with the exception of string concatenation). Ideally, you should make your TreeNode generic, and either have a Comparator<T> which is able to compare any two instances, or make T extend Comparable<T>. Either way, … Read more

Your function does not have a return for every possible circumstance. You have: if (null)… if (less than root)… else ( if …) else (no return!) What do you return if it is not null, and goes to the final else? Nothing is returned. You can either return getParent… in the else statement. or return … Read more