# Binary Tree

Given a pointer to the root node of the tree, write code to find if it is an Almost Complete Binary Tree or not? A Binary Tree of depth d is Almost Complete iff: The tree is Complete Binary Tree (All nodes) till level (d-1). At level d, (i.e the last level), if a Node […]

Given a binary tree and two values. Find if these values appear in sibling nodes in the tree. For example, if tree is Then 2 and 6 are siblings but 6 and 9 are not siblings (they are cousin nodes).

The structure of Node of a Binary Tree and Doubly linked list are same. struct Node { int data; Node* left; Node* right; } Structure of Node of a Binary Tree struct Node { int data; Node* previous; Node* next; } Structure of Node of a Doubly linked list If we treat […]

Given a Binary tree, write code to find the length of longest path such that value of node in that path are consecutive and in decreasing order. For example is the tree is Then output should be: 3 because path (5, 4, 3) has all nodes in consecutively decreasing order. Note that Path <5, 6, 7> are […]

Given a binary tree and a number n representing the vertical level. Write code to compute the sum of all nodes which are at vertical level n. For example, if the binary tree given is as below: and n=-1, then the output should be 12. Because Nodes at level =1 are 7 and 5 and […]

Given a Binary Tree and a Node, Write a function that return the vertical distance of that node from root of the tree. The vertical distance of a node is computed as below: Then the vertical distance of root is 0. The vertical distance of right node is distance of root+1. The vertical distance of […]

Given a binary tree and a Number N, write code to check if there exist a subtree of the Binary tree with sum of all the nodes = N. For example, if the Binary tree is as given on the right: And N = 12, then the output should be ‘true’ because there exist a […]

Binary heap is used to implement Priority queue. It is an array object, visualized as an almost complete binary tree. Binary heap comes in two flavours Max-Heap Min-Heap A max-heap is an almost complete binary tree, where, value at each node is greater than the value of its children. Similarly, a min-heap is an almost complete binary tree where […]

One way to ask this question is: Given a Binary tree that represent a family hierarchy. A parent can have at most two children (at most one girl child and at most one boy child). A girl child (if present) is always represented as left child in the binary tree, and a boy child (if present) […]

This is video discussion of a typical interview problem to check if the given Binary tree is a complete Binary tree or not.