Reverse an integer array in java using iterative & recursive algorithm
Given an integer array in java. Reverse input array using iterative & recursive algorithm. Example to reverse an integer array […]
Given an integer array in java. Reverse input array using iterative & recursive algorithm. Example to reverse an integer array […]
A prime number is a natural number greater than 1 that has no positive divisors other than 1 & itself. e.g.Number 7
Given two sorted integer arrays containing unique or distinct elements. We would like to find out the union of two
Given two sorted arrays containing distinct elements. We would like to find out the intersection of two sorted arrays. Intersection
Given an array of integers in java. Replace every element of array with greatest number on its right. The right
Given an integer array in java, find out the leader elements in an array. What is leader element in an
Given an integer array in java, find the majority (element exist more than half element) element in an array using Boyer Moore’s voting algorithm.
Given an array containing n-1 distinct positive numbers range from 1 to n. e.g suppose n = 5, array will contain 4 unique
Given an array of integer containing positive numbers. All number in an array is occurring even number of times except one
What is level in binary tree?
Level is distance or hops of node with respect to root node. The root node is considered to be at level 0, so children of root node will be at level 1 (level of root node + 1). So, we can calculate the level of all the nodes in binary tree.
As an example, consider the tree:
Given the binary tree, We need to find the maximum width of binary tree. What is width of binary tree? The number of nodes at any level provides the width of binary tree (at that level). We will find the width at each level and maximum among these widths will be our desired output.
Given the binary tree, we need to print the nodes at a K (Means it can be any number as per the user input like 1 or 2 or 3 or any arbitrary number) distance from Leaf Nodes. Let us elaborate the problem statement by taking example.
Given the binary tree, we need to print the nodes at a K (Means it can be any number as per the user input like 1 or 2 or 3 or any arbitrary number) distance from root.
Given the binary tree, we need to print the number which are in a given range. We will be given the two numbers K1 and K2, we need to print all numbers within the range of K1 and K2 ( number > k1 and number < k2).
Let us understand the problem statement. Given the number , we need to find the node in the binary tree having data equal to given number and we will delete the found node. Suppose we are given the tree as shown in Fig 1, we will analyse BST to delete a node.
Predecessor of any node is the previous node of binary traversal. Let us take an example to understand the inorder predecessor in binary search tree. We have already discussed about the inorder successor. The logical flow of inorder predecessor and inorder successor is same. If we understand any one of them, other can be solved in similar manner.
Successor of node is the next node of binary traversal. Let us take an example to understand the inorder successor in binary search tree. We have discussed about the inorder predecessor. The logical flow of inorder predecessor and inorder successor is same.
Lowest or least common ancestor is the earliest possible node where concerned child nodes joined.
Let us take an example tree, we will discuss some examples to clarify the LCA. We have already discussed about finding lowest common ancestor in binary tree (not binary search tree)
What is Binary Search Tree?
The binary search tree is specialized form of binary tree having following properties
Left child of binary tree node is less than its parent node
Right child of binary tree node is greater than its parent node
We are given the node value (or data), we need to find the node in the binary search tree. let us take a example to understand the problem statement.
What is Binary Search Tree?
The binary search tree is specialized form of binary tree having following properties
Left child of binary tree node is less than its parent node
Right child of binary tree node is greater than its parent node
We are given two binary tree, we need to find out whether one binary tree is identical to other binary tree.
We need to check whether
Composition of both binary trees are same
Data of nodes of both binary tree (at respective position) are same
Given the binary tree, There are multiple paths exist from root to leaf nodes. We need to check whether the given number equals the sum of all the nodes for any path. Let us elaborate more on this.
Given the binary tree, There are multiple paths (equal to number of leaf nodes) exist from root to leaf nodes, We need to calculate the sum of all nodes in each root to leaf path, then we need to print the maximum sum and the corresponding path. Let us take the example to elaborate our problem statement.
What is Vertical Order of Binary Tree?
The nodes, which are at same distance from the root nodes, are said to be on same vertical path. Suppose root is at a distance of 0. Now we will calculate the distance wrt. root node. As we go left
What is Vertical Order of Binary Tree?
The nodes, which are at same distance from the root nodes, are said to be on same vertical path. Suppose root is at a distance of 0. Now we will calculate the distance wrt root node. As we go left
What is diameter of binary tree?
The longest distance between two leaf nodes in binary tree provides us the diameter of binary tree. Let us take the couple of examples.
Given the binary tree, we need to find number of nodes in the given binary tree. To count the number of nodes in binary tree, we need to visit all the nodes at least once. We have counted the number of nodes without recursion using level order traversal in this post.
We are given the Binary Tree, we need to find the minimum and maximum element in the Binary Tree. We will recursively scan the complete binary tree and find out the minimum and maximum element in the binary tree.
Height of binary tree is number of edges from root to the deepest leaf node. We have already discussed the height of binary without recursion using level order traversal.