# Category Archives: Trees

## Longest word in ternary search treeSeptember 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 »

## Print the nodes at odd levels of a treeSeptember 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 »

## Diameter of a Binary Tree in O(n) [A new method]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 »

## Implementation of Binary Search Tree in JavascriptAugust 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 »

## Deletion in a Binary Tree

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 »

## Find root of the tree where children id sum for every node is givenAugust 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 »

## Height of n-ary tree if parent array is given

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 »

## Insertion in a Binary TreeAugust 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 »

## Construct the full k-ary tree from its preorder traversalAugust 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 »

## Sum of all leaf nodes of binary treeAugust 25, 2017

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

## Find sum of all right leaves in a given Binary TreeAugust 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 »

## Sum of all nodes in a binary tree

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 »

## Diameter of a tree using DFSAugust 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 »

## Find right sibling of a binary tree with parent pointersAugust 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 »

## Counting the number of words in a TrieAugust 17, 2017

A Trie is used to store dictionary words so that they can be searched efficiently and prefix search can be done. The task is to… Read More »