• #### Pre Order Binary Tree Traverse

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

#### puzzlu Profile Answers by puzzlu Questions by puzzlu

• 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..). Read Best Answer

• 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!

#### Gaurav.khurana Profile Answers by Gaurav.khurana Questions by Gaurav.khurana

• Apr 25th, 2015

@vandita Just a minor correction i think we should go till n-1 only so the in for loop it should be and should use i+1 since nbrs are starting from 1 and not 0

```Codefor (int i=0 ; i<n ; i++)
{
swap(a[i],a[a[i]-1]
}
//since 1 is stored at 0th position```

#### bakesh

• Mar 16th, 2015

9

• #### 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.

#### sunil

• Feb 26th, 2017

Several forms having same name is called polymorphism.
We have two types of polymorphism in C++.