05. Trees


Trees are a nonlinear data structure that represents a hierarchical tree structure with a set of connected nodes. A tree usually starts with a single root node and every child of the tree descends from this parent node. Every child descends only from one parent. Within a tree you can have a subtree, for example in this image [3, 6 and 7] form a subtree of the main tree.


Source: Mastering the coding interview - Udemy

Uses

  • the DOM (Document object model) is a tree data structure, head and body are children of the HTML tag and inside the body there are children, that are connected hierarchically to one another
  • Facebook comments, where I can comment on a friends photo and they can comment on my comment
  • Chess game (before machine learning) picked moves based on a tree data structure
  • Family tree
  • Abstract syntax tree, used to represent the structure of a program's source code for the compiler to use

Types of trees

  • Linked lists
  • Binary search tree

← Back to main blog