I do not know the exact algorithm used for calculating CTOT's, but I can give you some background information about what information is used, and how pilots and air traffic controllers use CTOT's.
A CTOT, or calculated takeoff time, is a tool used within European air traffic flow and capacity management (ATFCM) to regulate the flow of air traffic through individual enroute sectors or airports.
The overall purpose of ATFCM is to prevent overload and ensure that capacity is utilised to the maximum extent possible and subsequently to ensure a fair distribution of delay.
Every area control sector and airport in Europe has a declared capacity, expressed as a maximum number of flight per hour. For enroute sectors, the capacity is determined by factors such as size of the sector, complexity of the route structure and military areas. For airports, the capacity depends on the runway and aerodrome layout, available approach types, weather etc.
For every IFR flight taking place within Europe, at least 3 hours before departure, a flightplan has to be submitted to the Integrated Initial Flight Plan Processing System (IFPS), which is based in Brussels and Paris. The system will check that the flightplan is in correct format, and that it complies with any restrictions that may have been published, affecting the flight (for example, a certain route may only be available in a certain range of levels due to military activity).
The IFPS will process all these flightplans, and based on this information calculate the number of flights in any given sector or any given airport in Europe. If the number of planned flights (demand) exceeds the declared capacity, IFPS will start issuing CTOT's. A CTOT is a precise departure time, at which the affected flight must depart in order to ensure that, when the flight reaches the overloaded sector or airport, the demand does not exceed the capacity. This has the advantage that flights will spend their inevitable delay on the ground at their departure airport, instead of in airborne holdings. The IFPS will distribute delay fairly between flights. If an airport can handle 44 flights per hour, and there are 46 flights planned during some hour, the system will issue small delays to many flights, instead of just giving large delays to two flights. In case CTOT's are issued to flights as a result of an overload during a single one hour period, CTOT's will also be issued to flights planned in one hour before and one hour after that time, to avoid simply pushing the problem forward one hour.
In order to calculate these CTOT's, the IFPS must have access to up to date information about all flights. When submitting a flightplan, the aircraft operator includes an estimated off block time (EOBT), which is the time at which the aircraft is planned to leave the gate at its departure airport. If a flight is ready to leave its gate more than 15 minutes before the original EOBT, or is delayed more than 15 minutes, the airline must submit a new EOBT to the system, since the new departure time might result in an overload somewhere along the route. This may or may not result in the issuance of a CTOT time. Similarily, if a flight has been given a CTOT, but is unable to depart within the CTOT tolerance, which is -5/+10 minutes, the airline or air traffic control must submit a delay message to the IFPS, and a new CTOT will be issued. Obviously, IFPS must also be informed of any cancelled flights.
IFPS must also be provided with information about average taxi time at airports. The taxi time is the time it takes from the aircraft leaves the gate (EOBT) until it is ready for takeoff at the runway. During winter time especially, where de-icing operations at airports may reuslt in a very long taxi time, updating the taxi time in IFPS is very important. This is done by ATC. IFPS must know the taxi time because for each flight is only knows the EOBT time. Obviously, the system should not issue CTOT's that are earlier than EOBT+taxi time, since the aircraft would not be ready for takeoff at that time.
Air traffic controllers must depart any flights that have received a CTOT within a tolerance windon of -5/+10 minutes. If a flight is ready to depart before its CTOT, ATC must either have the aircraft wait on its gate, or some other place at the airport. At many airports, aircraft cannot be allowed to wait at the gate, because other arriving aircraft need to use the gate. It is then up to ATC to figure out what to do with the CTOT restricted flights until they can depart.
If a flight misses its CTOT, ATC is not allowed to issue a takeoff clearance. A new CTOT must be requested through IFPS, and the flight will potentially be delayed.
When a flight has received a CTOT, it is not set in stone. IFPS may send a slot revision message (SRM) if, for some reason or the other, the system has calculated a new CTOT. This can be both a better (earlier) or worse (later) CTOT. IFPS may also send a slot cancellation message (SLC), in which case the flight may depart without delay. Flights that are ready to depart within a short period of time, but are subject to a CTOT delay, can ask ATC to send a ready message, indicating to IFPS that if an earlier CTOT becomes available, the flight will be ready for it. In addition, an airline can request to swap CTOT's between two of their own flights, if the airline finds it more important than one flight arrives on time compared to another.
Finally, some flights are exempted from ATFCM restrictions, meaning that no CTOT delays will be issued. Examples of such flights are ambulance, fire fighting and search and rescue flights, and flights carrying heads of state. Flights departing outside of Europe will not receive CTOT's either, because no global ATFM system exists (yet) - but of course IFPS still has information about these flights, and they will be included in the calculations.
I hope the above gives you a better understanding of how air traffic flow and capacity management works in Europe. See this related question for information about ATFM in the USA.