Making tree from traversals

Given the pre-order and in-order traversal of a Binary Tree. Construct the tree from these traversals. InOrder: 1 4 5 8 10 30 40 PreOrder: 10 5 4 1 8 30 40 Can you construct the Tree if only post-order and in-order traversals are given? Can you construct a tree if only pre-order and post-order […]

Basic Tree Traversals (Preorder, Inorder, Postorder)

If the node of a Binary tree is defined as below: struct Node{ Node * lptr; // Pointer to Left subtree int data; Node *rptr; // Pointer to Right subtree }; write functions which will traverse the tree in in-Order, Pre-Order and Post-Order.

Understanding Recursion

What is recursion? What is head-recursion and tail-recursion? Should we use recursive or non-recursive functions?

Has Path Sum (binary tree)

Given a Binary Tree and a number x, Write a function to see if there exist a root to leaf path in the tree whose sum is equal to x.

Checking if a number is fibonacci

By definition first 2 Fibonacci numbers are defined as 0 and 1. nth Fibonacci number can be computed as sum of (n-2)th & (n-1)th Fibonacci numbers Hence the Fibonacci numbers are as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … A number is given to you, how will you […]

3 basket puzzle (Apple/Orange Puzzle)

There are 3 baskets labeled ‘Apples’, ‘Oranges’ & ‘Mixture’. One of them contains only Apples, one only Oranges and  one has mix of apples and oranges both. These baskets are not labeled correctly. In fact, the labels on these baskets always lie. (i.e. if the label says Oranges, Then you are sure the basket either […]

'man-in-the-middle' attack on data being transfered over Network

There are multiple types of attack which are possible on the data when the data is being transferred over the network from one machine to another. One such attack is called ‘Man-In-The-Middle’. What is it and what are the different types? (Other type of attacks may be ‘IP Spoofing’, eavesdropping etc.)