1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with multiple choice question

  1. Mar 13, 2008 #1
    1. The problem statement, all variables and given/known data
    Which is true about the method find?

    //Return TreeNode with target value, or null if target not found
    public static TreeNode find(TreeNode root, Comparable target)
    {
    if(root == null)
    return null;
    else if(target.compareTo(root.getValue()) == 0)
    return root;
    else if(target.compareTo(root.getValue()) < 0)
    return find(root.getLeft(), target);
    else
    return find(root.getRight(), target);
    }

    A) Method find will never work as intended
    B) Method find will always work as intended
    C) Method find will only work as intended if target is not in the tree.
    D) Method find will always work as intended if the tree is a binary search tree
    E) Method find will only work as intended if the tree is a binary search tree and target occurs no more than once in the tree

    2. Relevant equations



    3. The attempt at a solution

    I chose E. Since it uses methods getLeft() and getRight(), it appears to work only for binary search trees. Also, it target occured twice, it could return one of two pointers right?
     
  2. jcsd
  3. Mar 14, 2008 #2
    I'll agree with you and for the same reasons.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Help with multiple choice question
Loading...