Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

sahar90

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
  1. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 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
  2. sahar90
    Best Response
    You've already chosen the best response.
    Medals 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
  3. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    kind of hard to read, but yeah returning the variable count is the better choice.

    • one year ago
  4. sahar90
    Best Response
    You've already chosen the best response.
    Medals 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
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.