
Python code:
##############################
class Node:
def __init__(self,value):
self.left = None
self.right = None
self.val = value
###############################
class BinarySearchTree:
def __init__(self):
self.root = None
def print_tree(node):
if node == None:
return
print_tree(node.left)
print_tree(node.right)
print(node.val)
#################################################
# Task 1: get_nodes_in_range function
#################################################
def get_nodes_in_range(node,min,max):
#
# your code goes here
#
pass # fix this
if __name__ == '__main__':
BST = BinarySearchTree()
BST.root = Node(10)
BST.root.left = Node(5)
BST.root.right = Node(15)
BST.root.left.left = Node(2)
BST.root.left.right = Node(8)
BST.root.right.left = Node(12)
BST.root.right.right = Node(20)
BST.root.right.right.right = Node(25)
print(get_nodes_in_range(BST.root, 6, 20))
![In this lab you are provided with a pre-populated Binary Search Tree and asked to implement the function get_nodes_in_range (node,
min, max) which returns a list (Python built-in list) of all the values in nodes in the tree which are within the range (inclusive of the min and
max).
As an example, for the following BST:
BST = BinarySearchTree ()
BST.root = Node (10)
BST.root.left = Node (5)
BST.root.right = Node (15)
BST.root.left.left = Node (2)
BST.root.left.right = Node (8)
the expected output for get_nodes_in_range (BST.root, 6, 20) is a list containing the following values:
[8, 15, 10]
NOTE: the order of the nodes in the list doesn't matter. The tests will check that the list returned by your function contains the same values](https://content.bartleby.com/qna-images/question/45d19586-ebc3-4f1a-8702-47e93c6193b1/e9a8217d-36ef-4a7c-9855-d44be7067121/tdb9enh_thumbnail.png)

Step by stepSolved in 3 steps with 1 images

- #include <iostream>#include <cstdlib>using namespace std; class IntNode {public: IntNode(int dataInit = 0, IntNode* nextLoc = nullptr); void InsertAfter(IntNode* nodeLoc); IntNode* GetNext(); void PrintNodeData(); int GetDataVal();private: int dataVal; IntNode* nextNodePtr;}; // ConstructorIntNode::IntNode(int dataInit, IntNode* nextLoc) { this->dataVal = dataInit; this->nextNodePtr = nextLoc;} /* Insert node after this node. * Before: this -- next * After: this -- node -- next */void IntNode::InsertAfter(IntNode* nodeLoc) { IntNode* tmpNext = nullptr; tmpNext = this->nextNodePtr; // Remember next this->nextNodePtr = nodeLoc; // this -- node -- ? nodeLoc->nextNodePtr = tmpNext; // this -- node -- next} // Print dataValvoid IntNode::PrintNodeData() { cout << this->dataVal << endl;} // Grab location pointed by nextNodePtrIntNode* IntNode::GetNext() { return this->nextNodePtr;} int IntNode::GetDataVal() {…arrow_forwardAssurne class LinkedQueue has been defined using the irplementation in your textbook thet myQueue has been initialized sa it is empty. Type the EXACT output of the following code segment. You may assurne that the code compiles and executes without erors. LinkedQueue myQueue int i - 1: int j-2; int k-3; int n-43B ryQueue.enqueue (n) myQueue.enquese G i- myQueue.peekFront (): myQueue.dequeue ( myQueue.cmqueue kk n-myQueue.peekFront (k myQueue.dequeue ( myQueue.enqueue (n) 2 aranbuarananbAu while CmyQueueisEmpty () i-myQueue.peckFront (k myQueue.dequeue(k cout <arrow_forward个 O codestepbystep.com/problem/view/java/loops/ComputeSumOfDigits?problemsetid=4296 You are working on problem set: HW2- loops (Pause) ComputeSumOfDigits ♡ Language/Type: % Related Links: Java interactive programs cumulative algorithms fencepost while Scanner Write a console program in a class named ComputeSumOfDigits that prompts the user to type an integer and computes the sum of the digits of that integer. You may assume that the user types a non-negative integer. Match the following output format: Type an integer: 827184 Digit sum is 22 JE J @ C % 123 A 2 7 8 9 Class: Write a complete Java class. Need help? Stuck on an exercise? Contact your TA or instructor If something seems wrong with our site, please contact us. Submit t US Oct 13 9:00 Aarrow_forward
- import java.util.Scanner; public class Inventory { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); InventoryNode headNode; InventoryNode currNode; InventoryNode lastNode; String item; int numberOfItems; int i; // Front of nodes list headNode = new InventoryNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ) { item = scnr.next(); numberOfItems = scnr.nextInt(); currNode = new InventoryNode(item, numberOfItems); currNode.insertAtFront(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode…arrow_forwardJava programming language I have to create a remove method that removes the element at an index (ind) or space in an array and returns it. Thanks! I have to write the remove method in the code below. i attached the part where i need to write it. public class ourArrayList<T>{ private Node<T> Head = null; private Node<T> Tail = null; private int size = 0; //default constructor public ourArrayList() { Head = Tail = null; size = 0; } public int size() { return size; } public boolean isEmpty() { return (size == 0); } //implement the method add, that adds to the back of the list public void add(T e) { //HW TODO and TEST //create a node and assign e to the data of that node. Node<T> N = new Node<T>();//N.mData is null and N.next is null as well N.setsData(e); //chain the new node to the list //check if the list is empty, then deal with the special case if(this.isEmpty()) { //head and tail refer to N this.Head = this.Tail = N; size++; //return we are done.…arrow_forwardJAVA programming languagearrow_forward
- Draw a UML class diagram for the following code: class Node: def __init__(self, value): self.value = value self.next = None class Stack: def __init__(self): self.top = None def isEmpty(self): return self.top is None def push(self, item): new_node = Node(item) new_node.next = self.top self.top = new_node def pop(self): if self.isEmpty(): raise Exception("Stack is empty") popped_item = self.top.value self.top = self.top.next return popped_item def popAll(self): items = [] while not self.isEmpty(): items.append(self.pop()) return items[::-1] def peek(self): if self.isEmpty(): raise Exception("Stack is empty") return self.top.value # Verificationstack = Stack()print("Is stack empty?", stack.isEmpty()) stack.push(10)stack.push(20)stack.push(30)print("Top item:", stack.peek()) print("Popped item:", stack.pop())print("Popped…arrow_forward/** * TODO: file header */ import java.util.*; public class BSTManual { /** * TODO * @author TODO * @since TODO */ // No style for this file. public static ArrayList<String> insertElements() { ArrayList<String> answer_pr1 = new ArrayList<>(11); /* * make sure you add your answers in the following format: * * answer_pr1.add("1"); --> level 1 (root level) of the output BST * answer_pr1.add("2, X"); --> level 2 of the output BST * answer_pr1.add("3, X, X, X"); --> level 3 of the output BST * * the above example is the same as the second pictoral example on your * worksheet */ //TODO: add strings that represent the BST after insertion. return answer_pr1; } public static ArrayList<String> deleteElements() { ArrayList<String> answer_pr2 = new ArrayList<>(11); /* * Please refer to the example in insertElements() if you lose track * of how to properly enter your answers */ //TODO: add strings that represent the…arrow_forwardThe C++ Vertex class represents a vertex in a graph. The class's only data member is _____ Ⓒlabel 1000 O weight O framEdges O toEdges Question 36 The C++ Graph class's fromEdges member is a(n) _________ O string Ⓒdouble O vector O unordered_map Question 37 The C++ Graph class's AddVertex() function's return type is _____ void O Edge+ Overtex) O vectorarrow_forward
- Run the program to tell me there is an error, BSTChecker.java:3: error: duplicate class: Node class Node { ^ BSTChecker.java:63: error: class LabProgram is public, should be declared in a file named LabProgram.java public class LabProgram { ^ 2 errors This is my program, please fix it. import java.util.*; class Node { int key; Node left, right; public Node(int key) { this.key = key; left = right = null; } } class BSTChecker { public static Node checkBSTValidity(Node root) { return checkBSTValidityHelper(root, null, null); } private static Node checkBSTValidityHelper(Node node, Integer min, Integer max) { if (node == null) { return null; } if ((min != null && node.key <= min) || (max != null && node.key >= max)) { return node; } Node leftResult = checkBSTValidityHelper(node.left, min, node.key); if (leftResult != null) { return leftResult; } Node rightResult = checkBSTValidityHelper(node.right, node.key, max); if (rightResult != null) { return rightResult; }…arrow_forwardInterval Difference: Please help me with this assertion errorarrow_forwardComputer science JAVA programming question i need help with this entire question pleasearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





