Given a binary tree, find the minimum depth of the tree. Minimum depth of a binary tree is the length of the shortest path of all paths from root to any leaf.Java code is provided in code snippet section. Java visualization is provided in algorithm visualization section.
AVL tree deletion algorithm is basically a modification of BST deletion algorithm. This algorithm is similar to AVL insertion algorithm when it comes to height balancing. We will try to understand this algorithm using an example but before that let's go over the major steps of this algorithm. Note that this algorithm is a bottom-up algorithm and hence height restoration of the tree proceeds from leaves to root.
AVL tree is a type of binary search tree in which at any given node, absolute difference between heights of left sub-tree and right sub-tree cannot be greater than 1. This property of the AVL tree helps to keep the tree height balanced. Let's look at following examples to understand the definition of the AVL tree.
Diagonal sum of a binary tree - Consider lines drawn at an angle of 135 degrees(that is slope = -1) which cut through the left branches of a given binary tree. A diagonal is formed by nodes which lie between two such consecutive lines. Diagonal sum in a binary tree is sum of all node's values lying between these lines. Here is a tutorial with video that explains the algorithm with examples and animation.
Write a program that populates right neighbors for all nodes in a binary tree. This has to be done using recursion and in O(1) extra space. A 'neighbor' node for node 'n' is defined as the node located on the immediate right hand side of node 'n'. A node and its neighbor node would be on the same level. If there is no node located on the immediate right hand side of node 'n', then neighbor of node 'n' is null.