shantanu.msp
BAN USERConvert the tree into list where
left child->2n
right child->2n+i
while traversing and converting to a list, note the indexes of the list where the data of the nodes are saved say IndexX and IndexY. this is done in O(log n) base 2.
then all you have to do is match IndexX/2 and IndexY/2 by using left shift operator which is done in O(log n) base 2.
Total efficiency with worst case: 2log(n) base 2
Convert the tree into list where
left child->2n
right child->2n+i
while traversing and converting to a list, note the indexes of the list where the data of the nodes are saved say IndexX and IndexY.
then all you have to do is match IndexX/2 and IndexY/2 by using left shift operator.
and your job is done in O(n)
with an efficiency with worst case: n+log(n)
void main() {
- shantanu.msp September 18, 2012int i,j;
j = 10;
i = j++ - j++;
printf("++j - j++%d %d \n\n", i,j);
j = 10;
i = ++j - ++j;
printf("++j - j++%d %d \n\n", i,j);
j = 10;
i = j++ - ++j;
printf("++j - j++%d %d \n\n", i,j);
j = 10;
i = ++j - j++;
printf("++j - j++%d %d \n\n", i,j);
getch();
}
You get the same answer for all the above code because the expression is first evaluated and the (pre/post)-incremental takes place...