Question: Know the Pre-and mid-order series of a binary tree and print its post-order series.
The time complexity of the following algorithm: O (n ^ 2) -- the worst case is the left single decision tree.
/* Kown the preorder listing and the inorder listing of a tree, print it's postorder listing */void PrintPostOrder (const char * pre, int s1, int e1, const char * in, int s2, int e2) {if (s1> e1 | s2> e2) return; char root = pre [s1]; for (int I = s2; I <= e2; I ++) if (in [I] = root) break; int offset = i-s2; PrintPostOrder (pre, s1 + 1, s1 + offset, in, s2, I-1); PrintPostOrder (pre, s1 + offset + 1, e1, in, I + 1, e2); printf ("% c", root );} int main () {const char * pre = "ABCDEF"; const char * in = "FEDCBA"; printf ("PreOrder: % s \ n", pre ); printf ("InOrder: % s \ n", in); printf ("PostOrder:"); PrintPostOrder (pre, 0, strlen (pre)-1, in, 0, strlen (in)-1); printf ("\ n"); return 0 ;}