Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem #1: In this problem, you will write some Java code for a simple operatio

ID: 3738385 • Letter: P

Question

Problem #1: In this problem, you will write some Java code for a simple operation on binary search trees where keys are integers. Assume you already have the following code. public class Binar Noge public int key; public BinaryNode left; public BinaryNode right; Write a method in Java that takes as input a binary search tree, and two integer values, lower and upper, which are ordered so that lower upper, and prints all elements in the binary search tree such that lower S key s upper. Note: Your program should run in O(K +logN) average time, where K is the number of keys printed. Use the following method signature: static void printRange(int lower, int upper, BinaryNode t)

Explanation / Answer

    static void printRange(int lower, int upper, Binaryt t) {
        if (t == null) {
            return;
        }
        if (lower < t.key) {
            printRange(lower, upper, t.left);
        }
       if (lower <= t.key && upper >= t.key) {
            System.out.print(t.key + " ");
        }
       if (upper > t.key) {
            printRange(lower, upper, t.right);
        }
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote