You have 3 free guides left 😟
Unlock your guides
You have 3 free guides left 😟
Unlock your guides

5.1 Tree Terminology and Properties

3 min readjuly 19, 2024

Trees are fundamental data structures that represent hierarchical relationships. They consist of nodes connected by edges, with each node storing data and references to other nodes. Understanding tree concepts is crucial for organizing and efficiently accessing information in computer science.

Trees come in various types, including binary trees and binary search trees, each with specific properties. Relationships between nodes, such as paths and common ancestors, play a vital role in tree operations. methods allow systematic exploration of tree structures, enabling efficient data manipulation and analysis.

Tree Fundamentals

Fundamental concepts of trees

Top images from around the web for Fundamental concepts of trees
Top images from around the web for Fundamental concepts of trees
  • Tree represents a hierarchical data structure composed of nodes connected by edges
    • Acyclic property ensures no cycles or loops exist within the structure
    • Directed edges establish a specific direction from parent to child nodes
  • Node serves as the basic unit in a tree, storing data and references to other nodes
    • Root node sits at the topmost position in the tree hierarchy, lacking a parent
    • directly connects to and resides above another node
    • directly connects to and resides below another node
      • nodes share a common parent node
    • Leaf (external node) represents a node without any children
    • Internal node signifies a node with at least one child
  • Edge denotes a connection between two nodes, signifying a parent-child relationship
  • constitutes a portion of a tree, including a node and all its descendants

Properties and characteristics of trees

  • indicates the number of edges from the root to a particular node
    • Level refers to nodes positioned at the same depth within the tree
      • Root node resides at level 0, its children at level 1, and so on
  • represents the maximum depth of any node in the tree
    • Height of a node equals the number of edges on the longest from the node to a leaf
    • Height of a tree corresponds to the height of the root node
  • denotes the number of children associated with a node
    • Degree of a tree signifies the maximum degree of any node within the tree

Tree Types and Relationships

Types of trees

  • restricts each node to have at most two children, designated as left and right child
    • Strict/proper binary tree mandates each node to have either 0 or 2 children
    • requires all levels, except possibly the last, to be entirely filled, with nodes positioned as far left as possible
  • (BST) adheres to specific properties:
    • Left subtree of a node contains only nodes with keys less than the node's key
    • Right subtree of a node contains only nodes with keys greater than the node's key
    • Both left and right subtrees must also satisfy BST properties
  • maintains a height difference of at most one between the left and right subtrees of any node
    • Examples include AVL trees and Red-Black trees
    • Guarantees O(logn)O(\log n) time complexity for search, insertion, and operations

Relationships between tree nodes

  • Path represents a sequence of nodes and edges connecting a node with its descendant
    • corresponds to the number of edges in a path
  • between two nodes equals the number of edges on the path connecting them
  • (LCA) identifies the deepest node that serves as an ancestor to both nodes
    • LCA helps determine the distance between two nodes
  • involves visiting each node in a tree exactly once
    • Preorder traversal: visit root, then left subtree, followed by right subtree
    • Inorder traversal: visit left subtree, then root, followed by right subtree
    • : visit left subtree, then right subtree, followed by root
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.
Glossary
Glossary