Search in a BST Z11868


Statement
 

pdf   zip   tar

thehtml

A binary search tree (BST) is a binary tree such that for each node n in the tree the elements in the left subtree of the tree rooted at n are less than the element at node n, and the elements of the right subtree of the tree rooted at n are greater than the element at the node n.

Write a program that first reads a binary tree of integer numbers in pre-order. The input binary tree will be always a BST. Then, the program reads a sequence of integer numbers, and for each number in the sequence determines whether the number is or not in the input BST.

Public test cases
  • Input

    180 155 60 -1 80 -1 -1 170 -1 -1 300
    240 -1 -1 400 310 -1 340 -1 -1 -1
    
    60
    180
    400
    310
    160
    0
    500

    Output

    60 1
    180 1
    400 1
    310 1
    160 0
    0 0
    500 0
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python