Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is a sustabable nodes?


I have the nodes g (green) and b (black.
Here's an assigment:

This exercise is about rooted binary trees. Each node x has fields x.parent, x.left and x.right denoting the parent, left
child, and right child of x. The root of the tree is denoted by root and root.parent = null. Furthermore, each node x also
has a field x.color, called the color of x, that can be either green or black. Throughout the exercise, we let n denote the
size of the input tree.

2.1 (2 %) A node x is sustainable if the color of x is green and the color of all descendants of x is also green. Consider
the tree below. Nodes with a g are green and nodes with a b are black. Mark all sustainable nodes in the tree. Do so
directly on the vertices in the tree.


What I have tried:

I've never heard of sustainable nodes, how should that work?
Posted
Updated 18-May-20 23:14pm
v2
Comments
OriginalGriff 19-May-20 4:14am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Thank you for the update - it helps to give us information, even if it's only your actual homework question!

So read the question carefully - it specifies exactly what a "sustainable node" is:
Quote:
A node x is sustainable if the color of x is green and the color of all descendants of x is also green.

I.e. is a node is Green and all it's "child nodes" are also all Green then the node is sustainable. Any Black nodes in a nodes descendants make it non-sustainable.

So create your tree, fill it with the appropriate data, and search the tree to identify sustainable nodes.

Hint: I'd start by setting all nodes as non-sustainable and traverse the tree from the bottom up. Hitting a Black node prevents any nodes above it from being sustainable, so there is no point in traversing them.
 
Share this answer
 
Comments
Maciej Los 19-May-20 5:34am    
5ed!
Member 14836053 19-May-20 5:56am    
Thanks that made sense ;-)
OriginalGriff 19-May-20 5:59am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900