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

Hi All, could you please help me with this project I want to know how to write a

ID: 3774947 • Letter: H

Question

Hi All, could you please help me with this project I want to know how to write a binary tree and insert element into and search for these elemnt? (Python )

Input

You will be given, in standard input, two arrays of integers. The first array will be your data. The second array will contain integers that may or may not be in the first.

The first line of input will contain two integers separated by a space. The first integer, n, will be the size of the data array. The second integer, m, will be the size of the query array. The next n lines will contain a single integer that corresponds to a value in the data array. Immediately following these will be m more lines containing the elements of the query array. A small sample set of input may look like this:

52 89 4 12 7 102 92 89

This will correspond to the two arrays:

- Data: [4 7 12 89 102]

- Query: [92 89]

Output

You will write a basic binary tree which only needs to insert and search for elements. Your prep time in this example will be the time it takes to add every element to the binary tree. You will only run one query per item in the query array, which will be a tree search to find the element. The output will be similar to before:

Prep time: 450ms

false:0ms 92

true:0ms 89

Explanation / Answer

class Node: def __init__(self, val): self.l_child = None self.r_child = None self.data = val def binary_insert(root, node): if root is None: root = node else: if root.data > node.data: if root.l_child is None: root.l_child = node else: binary_insert(root.l_child, node) else: if root.r_child is None: root.r_child = node else: binary_insert(root.r_child, node) def in_order_print(root): if not root: return in_order_print(root.l_child) print root.data in_order_print(root.r_child) def pre_order_print(root): if not root: return print root.data pre_order_print(root.l_child) pre_order_print(root.r_child) r = Node(3) binary_insert(r, Node(7)) binary_insert(r, Node(1)) binary_insert(r, Node(5))