Tag Archives: Tree

Print a two-dimensional view of a Binary Tree

Problem Given a binary tree, the task is to print the two-dimensional view of it. Sample Input             1            /  \           9    3           / \   / \          2   5  6  10  Sample Output:                    10          3                    6 1                  5          9                    2 Approach This problem is based on the observations that we can make from the examples. Below… Read More »

Create a mirror of an m–ary Tree

Problem Given an m-ary tree that can have a count of children greater than 2. Convert it into its mirror tree. Sample Input Sample Output Approach We can use “Depth First Search” to solve this problem. We can first store all the children of each node in a list. We traverse the given tree in any order and… Read More »

Construction of an Expression Tree

Problem Given a postfix expression, the task is to generate an expression tree from it and return the infix notation of the expression tree. Example: Below is the expression tree for the given expression: 2 + 3 Sample Input 2 3 + Sample Output The infix expression is 2 + 3 Explanation Below is the expression tree for… Read More »

Types of Data Structure

In programming, we use so many types of data structures to provide a proper structure to our data. A data structure is basically used to collect and organize the data on which we are going to perform the operations. For example, we all know what is an array, it is one of the most-used data structures. We use… Read More »