Question

Assume ArrayList<E> arrayBinaryTree = new ArrayList<E>( ) is used to store a binary tree. The root...

Assume ArrayList<E> arrayBinaryTree = new ArrayList<E>( ) is used to store a binary tree. The root node is stored at the cell whose index is 0 (first element in the array). Providing a method with signature public boolean isInternal (int target)  to check if the element stored at cell target (refers to an index) is an internal node or not. Return true for yes and false for no.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public boolean isInternal(int target) {
    int left = 2 * target + 1, right = 2 * target + 2;
    return target > 0 && target < arrayBinaryTree.size()
            && ((left < arrayBinaryTree.size() && arrayBinaryTree.get(left) != null)
            || (right < arrayBinaryTree.size() && arrayBinaryTree.get(right) != null))
            && arrayBinaryTree.get(target) != null;
}
Add a comment
Know the answer?
Add Answer to:
Assume ArrayList<E> arrayBinaryTree = new ArrayList<E>( ) is used to store a binary tree. The root...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT