basukinjal Newbie Poster

Suppose we have two array inorder and preorder containing the elements in the said format.
Using these two arrays how can i generate the binary tree??

Any help on the algorithm to be followed will be highly appreciated.

For eg:
inorder is : 2 3 4 5 6 7 8
preorder is : 5 3 2 4 7 6 8

then the Binary tree shld be
____5
____/\
_3_7
___/_/\
2_4 6_8

How can i form this binary tree??
i know the algorithm by hand but how do i implement it in C??

basukinjal Newbie Poster

Ive made my binary tree in the following format
[code=C]
typedef struct node
{ int info;
struct node left;
struct node
right;
}*nodeptr;
[/code]

Im looking for a function that will accept the root pointer and print the tree in a graphical format.
for eg.
i want the output to be
5
/\
__37
__//\
_268
____
\
__9
How can i get such and output (without the underscores .. given only because spaces cannot be detected.)
Please Help!!

basukinjal Newbie Poster

I have a broadband connection that i want to dial at a specific time automatically.
Can anyone tell me how to do it??
Its Urgent.. Please help

basukinjal Newbie Poster

Ive written the following simple code to find the addresses of the varialbles

[code=C]

include

int main()
{ int a;
int b;
char c;
float d;
printf("\nInt : %x\nInt : %x\nChar : %x\nfloat : %x",&a,&b,&c,&d);
return 0;
}

/* OUTPUT

Int : 12ff4c
Int : 12ff48
Char : 12ff47
float : 12ff40

*/
[/code]

My Question is why is there an extra gap of 3 in the memory??

basukinjal

Lets say i hv the permutation
2,5,4,1,0,7,6,3.

Now i want to bring it to
0,1,2,3,4,5,6,7.
Sorting will easily do the thing for me.

But im looking for a better algorithm than sorting.
i.e. since sorting (any type) will bring nos say 1,9,6,7,0 to 0,1,6,7,9
It doesn't take into consideration that all nos from 0 to 9 are present or not.

But i know that all nos are from 0 to N -1 (N = 8 in given case) are present in the array.
So can i can i modify the sorting algorithm in any way such that the time complexity is reduced? i.e a better algorithm with the known given condition.

basukinjal

I know what identity mapping is.
i.e. Array[i]=i.
From the random permutation i can come to this stage by sorting.
My question if can i do any better?? i.e sorting algorithm does not take into fact that all nos are present. but since i already know that all nos are present..can i do anything better to solve the problem. Im looking for a better algorithm than sorting.

basukinjal Newbie Poster

Suppose i have a random permutation of 0,1,...., N-1. Now if i want to get the identity mapping from this can i do anything better than sorting?? I mean, sorting does not take into fact that all nos from 0 to N-1 are in the array or not. But in this case as we know that all the nos from 0 to N-1 are present...can I get a better algorithm and just sorting the array??

Please Help