##
DFS for a n-ary tree (acyclic graph) represented as adjacency list
September 22, 2017

A tree consisting of n nodes is given, we need to print its DFS. Examples : Input : Edges of graph 1 2 1 3… Read More »

September 22, 2017

A tree consisting of n nodes is given, we need to print its DFS. Examples : Input : Edges of graph 1 2 1 3… Read More »

September 7, 2017

Given a set of words represented in a ternary search tree, find the length of largest word among them. Examples: Input : {“Prakriti”, “Raghav”, “Rashi”,… Read More »

September 4, 2017

Given a binary tree, print nodes of odd level in any order. Root is considered at level 1. For example consider the following tree 1… Read More »

September 3, 2017

The diameter of a tree is the number of nodes on the longest path between two leaves in the tree. The diagram below shows two… Read More »

August 31, 2017

In this article, we would be implementing the Binary Search Tree data structure in Javascript. A tree is a a collection of node connected by… Read More »

Given a binary tree, delete a node from it by making sure that tree shrinks from the bottom (the deleted not is replaced by bottommost… Read More »

August 30, 2017

Consider a binary tree whose nodes have ids from 1 to n where n is number of nodes in the tree. The tree is given… Read More »

Given a parent array P, where P[i] indicates the parent of ith node in the tree(assume parent of root node id indicated with -1). Find… Read More »

August 29, 2017

Given a binary tree and a key, insert the key into the binary tree at first position available in level order. Recommended: Please try your… Read More »

August 26, 2017

Given an array which contains the preorder traversal of full k-ary tree, construct the full k-ary tree and print its postorder traversal. A full k-ary… Read More »

August 25, 2017

Given a binary tree, find the sum of all the leaf nodes. Examples: Input : 1 / \ 2 3 / \ / \ 4… Read More »

August 23, 2017

Given a Binary Tree, find sum of all right leaves in it. Similar article : Find sum of all left leaves in a given Binary… Read More »

Give an algorithm for finding the sum of all elements in a binary tree. In the above binary tree sum = 66. Recommended: Please solve… Read More »

August 22, 2017

The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree. The… Read More »

August 20, 2017

Given a binary tree with parent pointers, find the right sibling of a given node(pointer to the node will be given), if it doesn’t exist… Read More »