Jul 302012

Write function to check whether two trees are similar or not. The signature of the function should be as shown below:

     * Function to check whether two trees are similar or not.
     * @param r1, r2: Pointer to root nodes of two trees.
     * Returns true(1) if the two are similar, else false(0)
    bool isSimilar(Node* r1, Node* r2);

Two trees are similar if they have same structure else they are not similar. Below pictures show Similar and non-similar (different) trees:


Continue reading »

Jul 052012

Singleton patterns are used, when you want to allow creation of only one instance(object) of a particular class. Such classes (which allow only single object to be created) are called Singleton Classes. For example, there is only one Window manager, so a class implementing Windows Manager, should be allowed to be instantiated only once.
Continue reading »

Jun 212012

C++11 is the latest version of C++ language originally designed by Stroustrup. I read an interview of him where he said that the latest standard (C++11 or C++0x) feels like a new language.

I will be publishing the new features added to the core language and to the STL in following articles in next few days. The first change (in the core language) which I want to focus today is the introduction of automatic type detection. Continue reading »

Jun 122012

A Camel has to transport 3000 bananas from point A to point B, both 1000km apart. There are few constraints

  1. There is only one Camel.
  2. Camel can not carry more than 1000 bananas at one time.
  3. Camel eats one banana every kilometer when he travels.

What is the maximum number of bananas which can be transported from point-A to point-B. Continue reading »