Binary Tree

  • 1.1) What is Tree data structure?
    A tree data structure is a hierarchical, non-linear data structure that organizes elements in a tree-like manner. It consists of nodes connected by edges, where each node contains data and can have zero or more child nodes. The topmost node of the tree is called the root, and nodes with no children are called leaves.
  • 1.2) Binary Tree
    A Binary Tree is a type of data structure where each node can have at most two children. It’s like a branching structure where each node has the potential to lead to two other nodes. This structure is used in various computer science applications to organize and manage data.
  • 1.3) In-Order traversal of Binary Tree
    In-Order traversal is a way of visiting all nodes of a Binary Tree following a specific order: Left-Root-Right. This means you start from the left child, then visit the root, and finally move to the right child.
  • 1.4) Pre-Order Traversal of Binary Tree
    Pre-Order traversal visits nodes of a Binary Tree in the order: Root-Left-Right.This means you start by visiting the root, then move to the left child, and finally to the right child.
  • 1.5) Post-Order traversal of a Binary Tree
    Post-Order traversal visits nodes of a Binary Tree in the order: Left-Right-Root. This means you start by visiting the left child, then the right child, and finally the current node (root).
  • 1.6) Level Order traversal of a Binary Tree
    Level Order traversal explores nodes level by level, visiting all nodes at a given level before moving to the next level. This traversal order is useful for tasks like breadth-first search, finding the shortest path, or printing the tree in a structured way.
  • 1.7) Binary Tree Zig-Zag traversal (Spiral Form Traversal)
    Spiral form traversal of a Binary Tree involves traversing the nodes level by level, alternating the direction between left to right and right to left. This creates a “zigzag” pattern as you move down the levels.
  • 2.1) Size of Binary Tree
    The size of a Binary Tree is the total number of nodes present in the tree. It represents the count of nodes, which includes both internal nodes (with children) and leaf nodes (without children). Calculating the size of a Binary Tree involves traversing the tree and counting the nodes.
  • 2.2) Find Maximum value among all nodes in the tree
    Write a function to find and return the maximum value among all nodes in the tree.
  • 2.3) Find Height of Binary Tree
    Given a Binary Tree, write a function to find and return the height of the tree. The height of a Binary Tree is the maximum number of edges on the longest path from the root node to any leaf node.
  • 2.4) To Print Nodes at K Distance
    Given a Binary Tree and an integer value K, write a function to print all the nodes that are at a distance K from the root node.
  • 2.5) Find whether Binary Tree satisfies the Children Sum Property or not?
    The Children Sum Property states that, for each node in a Binary Tree, the value of the node must be equal to the sum of the values of its left and right children. If the node has no children, then the property is still satisfied.
  • 2.6) Average of Levels in Binary Tree
    Given the root of a binary tree, return the average value of the nodes on each level of the tree.
  • 2.7) Diameter of Binary Tree
    Given a binary tree, find the length of the longest path between any two nodes in the tree. This path may or may not pass through the root.
  • 2.8) Two Trees are Same or not
    Given two binary trees, determine if they are structurally identical and have the same node values at corresponding positions.
  • 2.9) Find All The Lonely Nodes
    Given the root of a binary tree, a lonely node is a node that has no siblings (i.e., it’s the only child of its parent). Return an array containing the values of all lonely nodes in the tree, sorted in ascending order.
  • 3.1) Maximum Depth of Binary Tree
    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
  • 3.2) Minimum Depth of Binary Tree
    Given a binary tree, find the minimum depth of the tree. The minimum depth is defined as the minimum distance from the root node to the nearest leaf node. A leaf node is a node with no children.
  • 3.3) N-ary Tree Level Order Traversal
    Given the root of an N-ary tree, return the level order traversal of its nodes’ values. Level order traversal means visiting all nodes at each level from left to right before moving on to the next level.
  • 3.4) Count Nodes in Complete Binary Tree
    Given a complete Binary Tree, write a function to count and return the total number of nodes present in the tree.
  • 3.5) Serialize/Deserialize Binary Tree
    To convert a binary tree into a string representation (serialization) and then converting it back from the string to the original binary tree (deserialization).
  • 3.6) Iterative Inorder Traversal of Binary Tree
    Given a binary tree, write a program to perform an iterative in-order traversal and print the values of the nodes as they are visited.
  • 3.7) Iterative Preorder Traversal of Binary Tree
    Given a binary tree, write a program to perform an iterative preorder traversal and print the values of the nodes as they are visited.
  • 3.8) Iterative Postorder Traversal of Binary Tree
    Write a program to perform an iterative post order traversal and print the values of the nodes as they are visited.
  • Range Sum of BST
    Given the root of a binary search tree (BST), and integers low and high, find the sum of all node values in the BST that are within the range [low, high].

Leave a Reply