Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
Binary Search Tree - Tracing

The following code recurses over a Binary Search Tree (BST) and prints to standard output occasionally. Please trace through the code for the given BST and write what would be printed out after the code terminates. Do not write the return value of the method. Just write each print statement’s output on a new line. Ensure that the print statements’ outputs are correct and in the correct order. The method is run on the root of the BST.

```java
public class Node<T> {
    public T data;
    public Node<T> left;
    public Node<T> right;
}

public int mysteryRec(Node current) {
    if (current == null) {
        return 0;
    }

    int left = mysteryRec(current.left);
    int right = mysteryRec(current.right);
    int tmp = left + current.data + right;

    if (tmp > 15) {
        System.out.println(current.data);
    }
    return tmp;
}
```

Diagram Explanation:

Input BST:

- The Root Node is 20. 
- The left child of 20 is 10, with a further left child of 5.
- The right child of 20 is 50, with left and right children 30 and 70, respectively.

Output:

The output section is currently empty. Use the code to determine which node values will be printed by the `System.out.println()` statement.
expand button
Transcribed Image Text:Binary Search Tree - Tracing The following code recurses over a Binary Search Tree (BST) and prints to standard output occasionally. Please trace through the code for the given BST and write what would be printed out after the code terminates. Do not write the return value of the method. Just write each print statement’s output on a new line. Ensure that the print statements’ outputs are correct and in the correct order. The method is run on the root of the BST. ```java public class Node<T> { public T data; public Node<T> left; public Node<T> right; } public int mysteryRec(Node current) { if (current == null) { return 0; } int left = mysteryRec(current.left); int right = mysteryRec(current.right); int tmp = left + current.data + right; if (tmp > 15) { System.out.println(current.data); } return tmp; } ``` Diagram Explanation: Input BST: - The Root Node is 20. - The left child of 20 is 10, with a further left child of 5. - The right child of 20 is 50, with left and right children 30 and 70, respectively. Output: The output section is currently empty. Use the code to determine which node values will be printed by the `System.out.println()` statement.
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education