Drawing tree traversals for MATHHELPBOARDS

  • Topic:
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Drawing Trees
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
13 replies · 4K views · last reply
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I want to draw trees, that traverse "MATHHELPBOARDS" in:

  • pre-order
  • in-order
  • post-order

That's what I have tried:




Could you tell me if it is right or if I have done something wrong? (Thinking)
 
Attachments
  • Binary tree diagram with nodes labelled M, A, B, T, E, O, D, H, H, L, P, A, R, S, showing a letter sequence spelling MATHHELPBOARDS across its levels.
    pre.png
    5.2 KB · Views: 173
  • Binary tree diagram with root P, children H and R, then A, E, O, S, then leaves M, T, H, L, B, A, D, labelled in green nodes.
    pre.png
    4.6 KB · Views: 159
  • Binary tree diagram with root S, children L and D, and leaves M, A, H, H, P, B, A beneath the intermediate nodes T, E, O, R.
    pre.png
    4.7 KB · Views: 171
Physics news on Phys.org
evinda said:
Hello! (Wave)

I want to draw trees, that traverse "MATHHELPBOARDS" in:

  • pre-order
  • in-order
  • post-order

Hey! (Blush)

All of them are right! (Clapping)

Are they the only possibilities? (Wondering)
 
I like Serena said:
Hey! (Blush)

All of them are right! (Clapping)

(Party) (Happy)

I like Serena said:
Are they the only possibilities? (Wondering)

No, there are more possibilities. An other tree, that traverses "MATHHELPBOARDS" in pre-order is this:

View attachment 3585

Or am I wrong? (Thinking)
 
Attachments
  • Binary tree diagram with nodes labelled M, A, T, H, H, E, L, P, B, O, A, R, D, S, arranged as a branching tree with M at the root.
    preorder.png
    3.8 KB · Views: 158
evinda said:
No, there are more possibilities. An other tree, that traverses "MATHHELPBOARDS" in pre-order is this:

Or am I wrong? (Thinking)

Nice! (Happy)

I see they are all binary trees.
Do they have to be binary trees? (Wondering)
 
I like Serena said:
Nice! (Happy)

I see they are all binary trees.
Do they have to be binary trees? (Wondering)

I think that it is possible that they are not binary trees.. Am I right? (Thinking)
 
evinda said:
I think that it is possible that they are not binary trees.. Am I right? (Thinking)

We could put the 'M' in the root, and ATHHELPBOARDS as children of the root.
This is pre-order.
Can we also do in-order? (Wondering)
 
I like Serena said:
We could put the 'M' in the root, and ATHHELPBOARDS as children of the root.
This is pre-order.
Can we also do in-order? (Wondering)

Is this a possible tree? (Thinking)

View attachment 3592
Or am I wrong? (Thinking)
 
Attachments
  • Tree diagram with root S connected to R, R with children P, A and D, and P with children L, H, B and O, H with children M, T and E, M with child A, and T with child H.
    in.png
    4.3 KB · Views: 154
evinda said:
Is this a possible tree? (Thinking)

I don't think so. (Worried)
Why would M be the first node in this tree? (Wondering)
 
I like Serena said:
I don't think so. (Worried)
Why would M be the first node in this tree? (Wondering)

(Worried) With which node should I start then? :confused:
 
evinda said:
(Worried) With which node should I start then? :confused:

Well, I'm assuming that S is the root.
Or isn't it? (Thinking)

So if we do a pre-order traversal, S should be the first letter.
For a post-order traversal, L is the first letter.
And in in-order traversal is not properly defined for a tree that is not binary, but if it was, L would still be the first letter. (Nerd)

How can M be the first letter? (Wondering)
 
I like Serena said:
Well, I'm assuming that S is the root.
Or isn't it? (Thinking)

So if we do a pre-order traversal, S should be the first letter.
For a post-order traversal, L is the first letter.
And in in-order traversal is not properly defined for a tree that is not binary, but if it was, L would still be the first letter. (Nerd)

How can M be the first letter? (Wondering)

So, can we just traverse a tree in post-order and in-order, if it is a binary tree?
But.. we can traverse all trees in pre-order?
Or have I understood it wrong? (Thinking)
 
evinda said:
So, can we just traverse a tree in post-order and in-order, if it is a binary tree?
But.. we can traverse all trees in pre-order?
Or have I understood it wrong? (Thinking)

We can traverse any tree in both pre-order and post-order.
It's just that in-order requires us to be able to distinguish between left and right.
And we can only do that with a binary tree. (Wasntme)
 
I like Serena said:
We can traverse any tree in both pre-order and post-order.
It's just that in-order requires us to be able to distinguish between left and right.
And we can only do that with a binary tree. (Wasntme)

At the post-order, we have this row: left, right, root, right? (Thinking)

So, when we have, for example, this tree:

View attachment 3604

where do we have to put t? :confused:
 
Attachments
  • Rooted tree diagram of blue ellipse nodes joined by lines, with nodes labelled m and a near the bottom left; no other labels are visible.
    how.png
    2.8 KB · Views: 152
evinda said:
At the post-order, we have this row: left, right, root, right? (Thinking)
So, when we have, for example, this tree:

where do we have to put t? :confused:

Post-order would not start wit the 'm', but with the leftmost unlabeled node.
That is, it repeated takes the leftmost branch starting from the root until it encounters a leaf. (Worried)

Once we get to the 'm', the next node is indeed the 'a', and after that its right sibling. (Mmm)