Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Assignment # 1

(CS-319 Applied Programming – Spring-2021)


Due Date and Time: 3rd April, 2021 (At the start of the class) Weight: 3%

Instructions:
 Late assignment (after 10 minutes of the start of the class) will not be accepted.
 Only hand written solutions will be accepted.
 Your solution will be evaluated in comparison with the best solution.
 Follow the guidelines of writing a pseudocode whenever you are required to do so.

Problem 1: [Weight: 1.5%]


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).

Problem 2: [Weight: 1.5%]


Suppose that a user starts/terminates “n” Internet data sessions. Consider the following requirements:
 The arrival and termination processes of the data sessions are random.
 The arrival/termination of a data session is not dependent on the arrival/termination of other data sessions. Due to
this condition, it is possible to have some overlapping data sessions for some periods of time. It is also possible that for
some time durations, there is no active data session.
 The arrival/termination timings are real valued random variables.
Write an algorithm (in pseudocode form) that calculates the total idle time of the user between 0 and the last terminated
session (which can be any session out of the “n” sessions that terminates in the end). The running time of your algorithm must
not be more than O(n). The extra storage complexity must not be more than O(1).
Assume that the start times of the “n” sessions is available in an array of size “n” whose name is
Array_start_times_of_sessions. Also, assume that the end times of the “n” sessions are available in another array of size “n”
whose name is Array_end_times_of_sessions. Following is just an example. Your solution must work on all inputs and for all
values of “n” (and not just on the example where n=10). Note that the arrival times’ sequence follows a timeline and hence, it
is always a sorted sequence in ascending order (as shown in the example).
Example:
Array_start_times_of_sessions
2.1 5.0 8.3 14.1 16.5 24.2 28.1 40.6 42.3 45.4
Array_end_times_of_sessions
4.0 10.0 9.3 18.1 26.5 25.3 36.6 60.6 44.3 55.4
Total idle time = 2.1 + (5.0-4.0) + (14.1-10.0) + (28.1-26.5) + (40.6-36.6) = 12.8 units

You might also like