Which node satisfies this property?

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Property
In summary, the pre-order traversal of the tree yields the numbers in this row: $9,17,11,15,13,5,7,3$.
  • #1
evinda
Gold Member
MHB
3,836
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
  • #2
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)
 
  • #3
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)
 
  • #4
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)
 
  • #5
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)
 
  • #6
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)
 
  • #7
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)
 
  • #8
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)
 
  • #9
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: 64
  • #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)
 

FAQ: Which node satisfies this property?

What is a node?

A node is a fundamental unit in a data structure that contains data and links to other nodes.

What does it mean for a node to satisfy a property?

For a node to satisfy a property means that the node meets the specific criteria or conditions set for that property.

How do I determine which node satisfies a property?

To determine which node satisfies a property, you need to analyze the data and the links within the data structure and compare it to the criteria or conditions for the property.

Can a node satisfy multiple properties?

Yes, a node can satisfy multiple properties if it meets the criteria or conditions for each of those properties.

What happens if no node satisfies a property?

If no node satisfies a property, it means that there is no node in the data structure that meets the criteria or conditions for that property. This could be due to incorrect data or the property being too specific.

Similar threads

Replies
1
Views
1K
Replies
9
Views
2K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
1
Views
1K
Back
Top