Trees
Potential Issues to Watch Out For
Binary Tree vs. Binary Search Tree
Don't jump to conclusions. Remember to ask the
interviewer to clarify.
Balanced vs. Unbalanced
Ask interviewer to clarify. Usually balanced within
a certain tolerance.
Full and Complete
Again, ask to clarify. Full - 0 or n children, where
n is derived from the n-ary tree.
Common Types
Binary Trees
Tree structure categorized by having at most two children, commonly referred to as
left and right. Other terms often associated with binary trees arefull, complete, balanced, and perfect.
Link: https://en.wikipedia.org/wiki/Binary_tree
Binary Search Trees
A subset of binary trees, where for all nodes left of root, left.val < root.val. Similarly, for all nodes right of root, root.val < right.val.
https://en.wikipedia.org/wiki/Binary_search_tree
AVL Trees
A self-balancing binary search tree. This leads to better worst case performance for typical BST functions
such as insert, find, and remove.
https://en.wikipedia.org/wiki/AVL_tree
B Trees
Yo dude
n-ary Trees
A tree that for any node, it can have at most n children. Binary trees are a special case of n-ary trees
where n=2. https://en.wikipedia.org/wiki/K-ary_tree
Trie Trees
Also called a prefix-tree or radix-tree, According to Wikipedia:
"All the descendants of a node have a common prefix of the string associated with that node, and the
root is associated with the empty string. Values are normally not associated with every node, only with
leaves and some inner nodes that correspond to keys of interest.
Though tries are most commonly keyed by character strings, they don't need to be. The same algorithms
can easily be adapted to serve similar functions of ordered lists of any construct, e.g., permutations
on a list of digits or shapes. In particular, a bitwise trie is keyed on the individual bits making up
a short, fixed size of bits such as an integer number or memory address."
They are sometimes used as a replacement to hashtables. This StackOverflow thread does a great job weighing why you'd use one over the other. In summary (because I know no one likes clicking
on links), it says, verbatim:https://en.wikipedia.org/wiki/Triek-d Trees
A multi-dimensional binary search tree. Very trippy stuff man. Nearest neighbor is a common thing on this tree.
https://en.wikipedia.org/wiki/K-d_tree