Pinterest • The world’s catalogue of ideas

This article covers basics of AVL trees like definition of AVL trees, why are they used and rotation operations to maintain their height balance.

1

AVL tree | Basics

ideserve.co.in

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.

1

Minimum Depth of a Binary Tree

ideserve.co.in

Find the 'n'th most frequent number in array - IDeserve

Find the 'n'th most frequent number in array

ideserve.co.in

Populate right neighbors for all nodes in a binary tree - IDeserve

Populate right neighbors for all nodes in a binary tree

ideserve.co.in

Convert the given n-ary tree to its mirror image - IDeserve

Convert the given n-ary tree to its mirror image

ideserve.co.in

Check if two nodes are cousins in a Binary tree - IDeserve

Check if two nodes are cousins in a Binary tree

ideserve.co.in

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 | Deletion

ideserve.co.in

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.

AVL tree | Insertion

ideserve.co.in

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.

Diagonal Sum of a Binary Tree.

ideserve.co.in

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.

Populate right neighbors for all nodes in a binary tree

ideserve.co.in