The Tree Data Structure
Overview
- Hierarchical data structure starting with a root node.
- An abstract data type; a collection of nodes with values.
- Maintains pointers to children at the bare minimum.
- Can have additional pointers, but this requires more memory.
- The level of a given node is important.
- Doesn’t necessarily uphold the heap property.
- Can utilize both breadth-first and deapth-first searching recursively.
Binary Trees
A binary tree is a specific case in which each node in a tree has at most two children, which are referred to as the left and right child respectively1. This type of tree is extremely common in CSCI-C 343 and computer science in general.
When to use trees
- When you want to flatten, sort, or dichotomize data.
- When a node’s level is important.
- When you need your data to be ordered in a hierarchy.
Practice Problems
Check out Medium user Coding Freak’s article titled “Binary Tree Interview Questions and Practice Problems” for examples to work through.