Introduction to Trees
Learning Traversals DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Types of Binary Trees and Their Structural Properties, Binary Tree, Tree Traversal, Depth-First Search, Breadth-First Search, Height Calculation, Recursion, Queue, Node, Time Complexity, Space Complexity, Data Structures, Algorithm, data structures, binary tree, tree properties, node, Binary Tree, Tree Terminology, Types of Binary Trees.
Tree Properties Identification Problem Statement Given the root of a binary tree, determine if it possesses the properties of a Full Binary Tree, a Complete Binary Tree, a Perfect Binary Tree, a Balanced Binary Tree, and a Degenerate Tree. For each property, output "Yes" or "No". A binary tree is a hierarchical data structure where each node has at most two children, referred to as the left child and the right child. The problem requires classifying the given tree based on specific structural definitions: Full Binary Tree : Every node has either zero or two children. Complete Binary Tree : All levels are completely filled except possibly the last level, which is filled from left to right. All nodes on the last level are as far left as possible. Perfect Binary Tree : All internal nodes have exactly two children, and all leaf nodes are at the same level. Balanced Binary Tree : For every node, the heights of its two subtrees differ by at most one. Degenerate Tree : Every node has at most one child, resulting in a tree that resembles a linked list. Input Specification The input will be the root node of a binary tree. Each node is represented by a TreeNode object which has an integer val, a left child (which is either another TreeNode or None), and a right child (which is either another TreeNode or None). Output Specification Print five lines, each indicating "Yes" or "No" for a specific tree property, in the following order: 1. Is it a Full Binary Tree? 2. Is it a Complete Binary Tree? 3. Is it a Perfect Binary Tree? 4. Is it a Balanced Binary Tree? 5. Is it a Degenerate Tree? Constraints No specific constraints on tree size or node values are provided in the original content. Sample Test Cases No specific sample test cases are provided in the original content.