Postorder Tree Traversal – Iterative and Recursive
Given a binary tree, write an iterative and recursive solution to traverse the tree using postorder traversal in C++, Java, and Python.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree, write an iterative and recursive solution to traverse the tree using postorder traversal in C++, Java, and Python.
Given a binary tree, write an efficient algorithm to compute the diameter of it. Binary tree diameter equals the total number of nodes on the longest path between any two leaves in it.
Given a device having left, right, top, and bottom buttons and an OK button to enter a text from a virtual keypad having alphabets from A–Y arranged in a 5 × 5 grid. Find the shortest route in the device to construct a given string if we start from the top-left position in the keypad.
Given a binary tree, determine if it is a subtree of another binary tree or not. A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T.
Given a binary tree, check if it is a sum tree or not. In a sum tree, each non-leaf node’s value is equal to the sum of all elements present in its left and right subtree. The value of a leaf node can be anything.
Given a binary tree, print all cousins of a given node. Two nodes of a binary tree are cousins of each other only if they have different parents, but they have the same level.
Given a binary tree, determine if two given nodes are cousins of each other or not. Two nodes of a binary tree are cousins of each other only if they have different parents, but they have the same level.
Given a binary tree, check if it is a complete binary tree or not. A complete binary tree is a binary tree in which every level, except possibly the last, is filled, and all nodes are as far left as possible.
Given a binary tree and a node in it, write an efficient algorithm to find its next node at the same level as the node.
Given a binary tree, print the top view of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, print the bottom view of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, print its nodes level by level in spiral order, i.e., all nodes present at level 1 should be printed first from left to right, followed by nodes of level 2 right to left, followed by nodes of level 3 from left to right and so on…