Answered Questions

  • Pre Order Binary Tree Traverse

    Design a conventional iterative algorithm to traverse a binary tree represented in two dimensional array in preorder.


    • Sep 21st, 2010

    Binary tree in 2 dimensional array?Here is the solution for binary tree in link list as node
    {int info;node *left;node *right;};preOreder(node * Tree){push(tree);while(stack is not empty){myNode= pop();print myNode->info;push(node->right);push(node->left);}}

  • There are numbers from 1 to N in an array. out of these, one of the number gets duplicated and one is missing. The task is to find out the duplicate number. Conditions: you have to do it in O(n) time without using any auxilary space (array, bitsets, maps etc..).

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: David Rachutin

    • Dec 27th, 2006

    use the following method:

    mark the missing number as M and the duplicated as D

    1) compute the sum of regular list of numbers from 1 to N call it RegularSum

    2) compute the sum of your array (the one with M and D) call it MySum

    now you know that MySum-M+D=RegularSum

    this is one equation.

    the second one uses multiplication:

    3) compute the multiplication of numbers of regular list of numbers from 1 to N call it RegularMultiplication

    4) compute the multiplication of numbers of your list  (the one with M and D) call it MyMultiplication

    now you know that MyMultiplication=RegularMultiplication*D/M

    at this point you have two equations with two parameters, solve and rule!


    • Mar 16th, 2015


  • What is polymorphism? Explain with an example?  

    "Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.  

    Tech4 u

    • Jul 22nd, 2017

    The ability to define more than one function with the same name is called polymorphism.

    This provides the facility of sending the same message to objects of parent class and objects of the sub classes.


    • Feb 26th, 2017

    Several forms having same name is called polymorphism.
    We have two types of polymorphism in C++.
    1) Compile time Polymorphism or function overloading
    2) Runtime Polymorphism or function overriding