- #1
s3a
- 818
- 8
Homework Statement
a) Draw a single binary tree that gave the following traversals:
Inorder: T N C K V A S M W Q B R L
Postorder: T C N V S A W M B Q L R K
b) Assume that the binary tree from the above part (a) of this question is stored in an array-list as a complete binary tree as discussed in class. Specify the contents of such an array-list for this tree.
Homework Equations
If the first element's index starts at pos=1, the index of the left child of a certain element is 2*pos, and the index of the right child of a certain element is 2*pos+1.
The Attempt at a Solution
Here is the tree sought by part a.:
...K
.../\
..N...R
../\.../\
T..C...Q..L
.../\
...M..B
.../\
...A..W
.../\
..V..S
I am trying to do part b.
If I (incorrectly) assume that the above tree is a complete tree (like it seems that the question wants me to do), I get stuck when implementing the tree into an array(list), as can be seen below. (Sorry about the formatting.):
Indices: 0 1 2 3 4 5 6 7 8 9 10 11 12
Elements in the same order as the indices above: K N R T C Q L ? ? ? ? M B
What am I doing wrong?
Any input would be GREATLY appreciated!