Drawing Trees Through MATHHELPBOARDS: Pre-Order, In-Order, Post-Order

  • Context:
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Drawing Trees
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
13 replies · 3K views
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

  • pre.png
    pre.png
    5.2 KB · Views: 158
  • pre.png
    pre.png
    4.6 KB · Views: 148
  • pre.png
    pre.png
    4.7 KB · Views: 163
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

  • preorder.png
    preorder.png
    3.8 KB · Views: 148
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

  • in.png
    in.png
    4.3 KB · Views: 144
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

  • how.png
    how.png
    2.8 KB · Views: 140
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)