Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
sahar90
Group Title
i have a bst and i want to count the number of element of that in java language. and it is so important to run fast; do u think is it ok in all aspect?
int countTwoChildren(Node node) { return (node == null ? 0 : countTwoChildren(node.left) + countTwoChildren(node.right) + (node.left!=null && node.right!=null ? 1 : 0)); }
 one year ago
 one year ago
sahar90 Group Title
i have a bst and i want to count the number of element of that in java language. and it is so important to run fast; do u think is it ok in all aspect? int countTwoChildren(Node node) { return (node == null ? 0 : countTwoChildren(node.left) + countTwoChildren(node.right) + (node.left!=null && node.right!=null ? 1 : 0)); }
 one year ago
 one year ago

This Question is Closed

KonradZuse Group TitleBest ResponseYou've already chosen the best response.0
Yeah the code looks really ugly.... if anything with "speed" it's going to do the same calculations just return funky.... This doesn't work does it? do all your calculations, then return calculation.
 one year ago

sahar90 Group TitleBest ResponseYou've already chosen the best response.0
tnx for ur help; do u think is it betther? public int nbNodes(Node root){ int count = 1 // our actual node if(root.left != null){ count += nbNodes(root.left); } if(root.right != null){ count += nbNodes(root.right); } return count; }
 one year ago

KonradZuse Group TitleBest ResponseYou've already chosen the best response.0
kind of hard to read, but yeah returning the variable count is the better choice.
 one year ago

sahar90 Group TitleBest ResponseYou've already chosen the best response.0
excuse me; i'll be type it better to be useful for others; tnx for ur help again public int nbNodes(Node root){ int count = 1 if(root.left != null){ count += nbNodes(root.left); } if(root.right != null){ count += nbNodes(root.right); } return count; }
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.