# Algorithm design: Internet data sessions are randomly started on a mobile node

Internet data sessions are randomly started on a mobile node.
Let S1, S2,…, Sn be the arrival/starting times of the data sessions on the mobile node.
The starting times of the sessions are sorted in an ascending order.
Let E1, E2,…, En be the ending times of the sessions.
The ending times do not follow any order. Each session can be of any random duration. The mobile node stays in a cell for a random duration of time before moving to another cell.
Let H1, H2,…, Hm be the handover (leaving one cell to join another cell) times of the mobile node. The handover times are sorted in an ascending order.
Assume that Sn < Hm.
As an example, let’s suppose that the mobile node starts three sessions during its stay in cell C1. The mobile node then moves
to another cell C2. Let’s suppose that 2 out of the 3 sessions are still alive at the handover time (time of leaving C1 to join C2).
For the still alive sessions, a tunnel is established between cell C1 and the cell where the mobile node is currently present. The
tunnel is removed as soon as all the alive sessions (which were started in C1) are terminated. Assume that the mobile node
never moves to an already visited cell.
You are required to write the most efficient algorithm (in pseudocode form) to calculate the average tunnel time. The average
tunnel time can be calculated by adding the times of all tunnels and then dividing the total time by the total number of tunnels
which are created. The time complexity of your algorithm must not be more than O(n+m).