(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

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.

2. Relevant 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.

3. 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!

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Array-list implementation of tree problem

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**