Objective
Create a Python program that builds a binary search tree (BST) and queries it. In a BST, values smaller than a node go to its left and greater ones to its right.
Instructions
- The first line contains the integers to insert, in that order and separated by spaces (duplicates are ignored). The second line contains the integers to search for.
- Use a
Nodeclass withleftandright, and recursive functions to insert and traverse. - Show
Inorder: ...(in-order traversal, which comes out sorted),Height: h(number of levels; a single node has height 1),Minimum: mandMaximum: M. - Then, for each value to search, show
X: yesorX: no.
50 30 70 20 40 60 80 30
40 55 80
Inorder: 20 30 40 50 60 70 80
Height: 3
Minimum: 20
Maximum: 80
40: yes
55: no
80: yes
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise