Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
easy

Recursive Pre-Order Tree Traversal

Mark
< Prev
Next >

Consider the following class definitions. What is printed when the main method in the PreorderTraversal class is executed?

class Node {
    String val;
    Node left, right;
    Node(String v) { val = v; }
}

public class PreorderTraversal {
    public static void preOrder(Node root) {
        if(root == null) return;
        System.out.print(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }
    
    public static void main(String[] args) {
        Node a = new Node("A");
        Node b = new Node("B");
        Node c = new Node("C");
        Node d = new Node("D");
        a.left = b;
        a.right = c;
        b.left = d;
        preOrder(a);
    }
}
A

C A B D

B

A B D C

C

A D B C

D

D B A C

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|