Solution to Count Visible Nodes in Binary Tree

25 Jul

Questioin Name: Count Visible Nodes in Binary Tree

Question: In a binary tree, if in the path from root to the node A, there is no node with greater value than A’s, this node A is visible. We need to count the number of visible nodes in a binary tree. For example, in the following tree:

 There are four (4) visible nodes: 5, 20, 21, and 10.

 

Leave a Reply

Your email address will not be published. Required fields are marked *