Which node satisfies this property?

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Property
Click For Summary
SUMMARY

The discussion focuses on constructing a binary tree from a given pre-order traversal sequence: 9, 17, 11, 15, 13, 5, 7, 3. The participants establish that 9 is the root node, with 17 as its left child. They confirm that the tree satisfies the property where all keys in the left subtree are greater than the key of the node, and all keys in the right subtree are smaller. Ultimately, they conclude that the only valid tree structure that meets the criteria is one where 11 is the right child of 9, and 15 is the left child of 11.

PREREQUISITES
  • Understanding of binary tree properties
  • Knowledge of pre-order traversal in binary trees
  • Familiarity with tree node relationships
  • Basic skills in tree diagram construction
NEXT STEPS
  • Study binary tree traversal methods, focusing on pre-order traversal
  • Learn about binary search tree properties and their implications
  • Explore tree construction algorithms from traversal sequences
  • Investigate tree balancing techniques and their importance
USEFUL FOR

Computer science students, software developers, and anyone interested in data structures and algorithms, particularly those focusing on binary trees and their properties.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hi! (Smirk)

It is a given binary tree $T$, for each node $ n$ of which , all the keys of the nodes of the left subtree of $n$ are greater than the key of $n$ and all the keys of the nodes of the right subtree of $n$ are smaller than the key of $n$.

We suppose that $T$ contains the nodes $3,5,7,9,11,13,15,17$ and we are given that the pre-order traversal of the tree, gives as result the numbers in this row: $9,17,11,15,13,5,7,3$.
I have to draw the tree.

How can I find the first node $n$, which satisfies the first property? (Thinking)
 
Technology news on Phys.org
evinda said:
Hi! (Smirk)

It is a given binary tree $T$, for each node $ n$ of which , all the keys of the nodes of the left subtree of $n$ are greater than the key of $n$ and all the keys of the nodes of the right subtree of $n$ are smaller than the key of $n$.

We suppose that $T$ contains the nodes $3,5,7,9,11,13,15,17$ and we are given that the pre-order traversal of the tree, gives as result the numbers in this row: $9,17,11,15,13,5,7,3$.
I have to draw the tree.

How can I find the first node $n$, which satisfies the first property? (Thinking)

Hey! (Happy)

A pre-order visits first the root of each node, then the left subtree (beginning with its root), and then the right subtree. (Nerd)

So we can already tell that $9$ is the root of the tree.
To which subtree will $17$ belong? (Wondering)
 
I like Serena said:
Hey! (Happy)

A pre-order visits first the root of each node, then the left subtree (beginning with its root), and then the right subtree. (Nerd)

So we can already tell that $9$ is the root of the tree.
To which subtree will $17$ belong? (Wondering)

So, does this means that $17$ and $11$ will be the children of $9$?
If so, can we conclude from a pre-order which will be the left child and which the right? (Thinking)
 
evinda said:
So, does this means that $17$ and $11$ will be the children of $9$?
If so, can we conclude from a pre-order which will be the left child and which the right? (Thinking)

$17$ will definitely be a child of $9$.
What does the problem statement say about whether it should be left or right? (Wondering)

As for $11$, that comes later, but I don't think it can be a child of $9$. (Shake)
 
I like Serena said:
$17$ will definitely be a child of $9$.
What does the problem statement say about whether it should be left or right? (Wondering)
Since the keys of the nodes of the left subtree are greater than the key, does this mean that 17 is the left child of 9?

I like Serena said:
As for $11$, that comes later, but I don't think it can be a child of $9$. (Shake)

How can we find then the right child of 9? :confused:

What do we conclude then from the fact that 11 is at the third position of the pre-order? (Thinking)
 
evinda said:
Since the keys of the nodes of the left subtree are greater than the key, does this mean that 17 is the left child of 9?

Yes. (Nod)
How can we find then the right child of 9? :confused:

What do we conclude then from the fact that 11 is at the third position of the pre-order? (Thinking)

Suppose we look at the tree:
Code:
    9
  /   \
17     11
What is then its pre-order? (Wondering)
Does the tree satisfy the problem statement criteria?

Can you think of another tree that has the same pre-order? (Wondering)
 
I like Serena said:
Suppose we look at the tree:
Code:
    9
  /   \
17     11
What is then its pre-order? (Wondering)

It is 9,17,11, right? (Thinking)

I like Serena said:
Does the tree satisfy the problem statement criteria?
Yes, the problem statement criteria are satisfied.. (Nod) Or am I wrong? (Thinking)

I like Serena said:
Can you think of another tree that has the same pre-order? (Wondering)

Isn't this the only one? (Thinking)
 
evinda said:
It is 9,17,11, right? (Thinking)

Yep! (Nod)
evinda said:
and all the keys of the nodes of the right subtree of $n$ are smaller than the key of $n$.
Yes, the problem statement criteria are satisfied.. (Nod) Or am I wrong? (Thinking)

Since $11$ is in the right sub tree of $9$, is it smaller? (Wondering)
Isn't this the only one? (Thinking)

How about:
Code:
     9
    /
  17
 /
11

Or:
Code:
     9
    /
  17
    \
    11
(Wondering)
 
I like Serena said:
Since $11$ is in the right sub tree of $9$, is it smaller? (Wondering)

Oh no! I am sorry! (Blush)

I like Serena said:
How about:
Code:
     9
    /
  17
 /
11

Or:
Code:
     9
    /
  17
    \
    11
(Wondering)

Oh yes, you are right! (Tmi)
 
  • #10
So, the first number of the pre-order is always the root, right? (Thinking)
Then, do we know that the next two numbers are the children of the root?
Or do we know this only for the second one? Or for none of them? (Thinking)
 
  • #11
evinda said:
Oh yes, you are right! (Tmi)

Which of these satisfies the criteria of the problem statement? (Wondering)
 
  • #12
I like Serena said:
Which of these satisfies the criteria of the problem statement? (Wondering)

This:

Code:
     9
    /
  17
    \
    11

satisfies the criteria of the problem statement, right? (Thinking)
 
  • #13
evinda said:
This:

Code:
     9
    /
  17
    \
    11

satisfies the criteria of the problem statement, right? (Thinking)

Yep! (Nod)
 
  • #14
I like Serena said:
Yep! (Nod)

Nice! And 15 will be now the left child of 11? Or am I wrong? (Thinking)
 
  • #15

Attachments

  • tree7.png
    tree7.png
    3.1 KB · Views: 114
  • #16
evinda said:
So, will the tree be like that?

Yep! (Party)
 
  • #17
I like Serena said:
Yep! (Party)

Great! (Party) And this is the only tree, that can be found, right? (Thinking)
 
  • #18
evinda said:
Great! (Party) And this is the only tree, that can be found, right? (Thinking)

When you were building up the tree, did you have any choices to make? (Wondering)
 
  • #19
I like Serena said:
When you were building up the tree, did you have any choices to make? (Wondering)

No (Shake) So, it is the only possible tree, right? (Smile)
 
  • #20
evinda said:
No (Shake) So, it is the only possible tree, right? (Smile)

Yes! (Nod)
 
  • #21
I like Serena said:
Yes! (Nod)

Nice, thank you very much! (Smirk)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
7K
Replies
6
Views
8K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K