Left view of a binary tree

Write code to print the left-view of a binary tree. Left-view of the tree is the nodes visible when the tree is seen from the left side. If there are two nodes at the same level, then only the left-most node will be visible in the left-view as shown below:

Sort in C++ standard template library

Two elements of complex data types are not directly comparable. Consider the student structure defined as below struct Student { int rollNo; char name[25]; char grade; }; Student arr[MAX_NUM_STUDENTS]; Objects of Student type are not directly comparable. To sort array arr, we need to specify how one student compares with another student. If there are […]

Check if a Tree is Almost Complete 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 […]

Birthday Paradox (Birthday Problem)

You may solve the simple probability, “Given a set of n randomly chosen people, what is the probability of two people having same birthday?” You may also solve,  “At least how many people need to be picked to make the probability 100% that at least two of them have same birthday?” Answer to the second question is […]

Hashing introduction

Let us design a data structure in which we want to store numbers (taking it for simplicity, else it can be anything). We want to minimise the time taken by the following three operations: Insertion, time taken to insert a new value. Deletion, time taken to remove an existing value. Searching, time taken to search […]

Medicine tablet (Pill) taking puzzle

Doctor gave you two types of medicine tablets (pils) A and B, and asked you to take one from each daily. The two tablets are in different bottles and look exactly same One day, while taking the pills, you open Bottle-A and tap one pill out in your hand. Then you open the second bottle to […]

Check if two node are siblings in a binary tree

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).