#K11896. Binary Tree Query Processing
Binary Tree Query Processing
Binary Tree Query Processing
You are given a series of queries to be processed on a binary tree. Initially, the tree is empty. The tree supports the following operations:
- 1 x: Insert an integer \(x\) into the tree.
- 2 x: Delete the integer \(x\) from the tree if it exists.
- 3 x: Search for integer \(x\) in the tree. Print
YES
if \(x\) is found andNO
otherwise. - 4: Print the minimum value present in the tree. If the tree is empty, output \(-1\).
- 5: Print the maximum value present in the tree. If the tree is empty, output \(-1\).
Process all the queries in the given order and output the result for each query that produces an output (i.e. queries of type 3, 4, and 5).
inputFormat
The first line contains a single integer \(Q\) denoting the number of queries. Each of the next \(Q\) lines describes a query in one of the following formats:
1 x
2 x
3 x
4
5
outputFormat
For every query that produces output (queries of type 3, 4, or 5), print the output on a separate line in the order the queries are processed.
## sample8
1 10
1 20
3 10
4
5
2 10
3 10
4
YES
10
20
NO
20
</p>