In general a tree data strucuture is a widely-used data structure that allows storing hierarchical data via a set of linked nodes. Each node in a tree has zero or more child nodes. A node that has a child is called the child's parent node (ancestor node). Nodes with no children are called leaf nodes. Siblings are nodes that share the same parent node.


As the simple case of a graph—a tree data structure is a connected graph containing no cycles—the tree is very suited for an interview question, as it allows the creation of problems that are small and can be coded within less than 10-15 lines, but the solutions are not obvious and require good problem-solving  abilities. Probably the most common questions are related to the binary tree.  A binary tree is a special kind of tree, one in which all nodes have at most two children. For a given node in a binary tree, the first child is referred to as the left child, while the second child is referred to as the right child.


Answers and Comments