You are on page 1of 1

All codes must be commented and justified

You get points if your solution is correct


In order to have all the points, you must respect the complexity specifications

1. Implement a data structure supporting the following operation:


- bool empty(): returns 1 if there is no element stored in the structure
- void add(int v): adds a new element equal to v in the structure
- int next(): returns and removes from the structure the middle element (i.e.,
half of the elements got inserted after the element returned)
All the operations should run in O(1) time /5

2. You are given the pre-order of a binary tree (missing children are indicated by the
symbol null). Example: 4 1 null 3 null null 7 6 null null null
Decide whether this is a binary search tree. The running time should be in O(n) /5

You might also like