DSA Lesson 14 of 33

Trees

Learn hierarchical data structures and tree terminology.

Course Progress42%

Theory

A tree is a hierarchical data structure made up of nodes connected by edges. Important terms include root, parent, child, leaf, depth and height. Trees are widely used in file systems, databases and searching.

Example

class TreeNode { constructor(value) { this.value = value; this.children = []; } } const root = new TreeNode("Root"); root.children.push(new TreeNode("Child")); console.log(root.value);

Expected Output

Root

Practice

Create a simple tree with one root and three child nodes.

Interview Questions

  1. What is a tree?
  2. What is the root node?
  3. What is a leaf node?
  4. What is the difference between a tree and graph?