Suppose that in a binary tree (not binary search tree), if the value of a node is greater than at least one of its children, then it is considered a "power node". For example, in the following tree, nodes 25 is a power node because is greater than both children 16 and 9. Similarly, node 16 is also a power node as it is greater than the left child 12. Other power nodes include 24 and 17. Consequently, in this tree, there are four power nodes.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
Suppose that in a binary tree (not binary search tree), if the value of a node is greater
than at least one of its children, then it is considered a "power node. For example, in
the following tree, nodes 25 is a power node because is greater than both children
16 and 9. Similarly, node 16 is also a power node as it is greater than the left child
12. Other power nodes include 24 and 17. Consequently, in this tree, there are four
power nodes.
25
16
IN
12 24
17
28 16 23 31 10
Complete the non-recursive method count PowerNodes, which takes a TreeNode
parameter node (a reference to a node in a binary tree) and retums the number of
power nodes in the tree rooted at node. If node is null or there are no power
nodes, the method returns 0.
public class TreeNode
private int m info;
private TreeNode m left;
private TreeNode m right;
public int getInfo()
(return m info;H
public void setinfo(int valae 1 im info- inferR
public TreeNode getLeft()
return m left:}
public void setleft(TreeNade left) {m left left
public TreeNode getRightt
public void setRigh (TreeNode right) (m tight right;)
(return msight;)
/ Note: This is recursive methad You wil1 receive
/points is any 1ooping statementsare used.
int countPowerNoces (TreNode nodel
Transcribed Image Text:Suppose that in a binary tree (not binary search tree), if the value of a node is greater than at least one of its children, then it is considered a "power node. For example, in the following tree, nodes 25 is a power node because is greater than both children 16 and 9. Similarly, node 16 is also a power node as it is greater than the left child 12. Other power nodes include 24 and 17. Consequently, in this tree, there are four power nodes. 25 16 IN 12 24 17 28 16 23 31 10 Complete the non-recursive method count PowerNodes, which takes a TreeNode parameter node (a reference to a node in a binary tree) and retums the number of power nodes in the tree rooted at node. If node is null or there are no power nodes, the method returns 0. public class TreeNode private int m info; private TreeNode m left; private TreeNode m right; public int getInfo() (return m info;H public void setinfo(int valae 1 im info- inferR public TreeNode getLeft() return m left:} public void setleft(TreeNade left) {m left left public TreeNode getRightt public void setRigh (TreeNode right) (m tight right;) (return msight;) / Note: This is recursive methad You wil1 receive /points is any 1ooping statementsare used. int countPowerNoces (TreNode nodel
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY