reading-notes

Trees

Binary Trees:

Binary Search Trees (BSTs):

K-ary Trees:

Tree Cheat Sheet:

  1. Tree: A hierarchical data structure composed of nodes.

    • Consists of a root node and zero or more child nodes.
    • Each child node can have its own child nodes, forming a recursive structure.
    • No cycles or loops are allowed in a tree.
  2. Binary Tree:

    • Each node has at most two children: a left child and a right child.
    • Nodes can have zero, one, or two children.
    • Useful for representing hierarchical relationships.
  3. Binary Search Tree (BST):

    • A Binary Tree with the following property:
      • For any node, the values in the left subtree are less than the node’s value.
      • The values in the right subtree are greater than the node’s value.
    • Enables efficient searching, insertion, and deletion operations.
    • In-order traversal of a BST visits nodes in ascending order.
  4. K-ary Tree:

    • Each node can have up to K children.
    • K is a positive integer.
    • Generalization of Binary Trees.
    • Useful for representing hierarchical structures with multiple branches.
  5. Common Tree Terminology:

    • Root: The topmost node in a tree.

    • Parent: The node directly above a given node.

    • Child: A node directly below another node.

    • Sibling: Nodes that share the same parent.

    • Leaf: A node with no children.

    • Height: The length of the longest path from the root to a leaf node.

    • Depth: The length of the path from a node to the root.

    • Subtree: A portion of a tree, consisting of a node and its descendants.

Back