Open In App

Scheduling without deadline

What is scheduling ?
Scheduling is another popular problem in computer science domain. A scheduling problem is a problem of scheduling resources effectively for a given request. In operating systems, often a single processor of a computer system may encounter many jobs or user programs. One can visualize the scheduling problem as an optimal ordering of jobs such that job turnaround time is minimized. In short, aim is to schedule jobs in an optimal order so as to execute jobs faster.

Let’s visualize scenario of scheduling :
In a library there is only one librarian who is assigned the issues for that day and there are several students who are in a queue to register their issues for books, so the librarian thought of a problem to make it a bit reordering that might help satisfying all students and reduces the issue time. so in this case what would be optimal order? 



Obviously, the student with less number of books in the queue will take less time to an issue than the student with a larger number of books. It makes sense to process the student with less number of books, so as to minimize the collective waiting time of students.

Scheduling of Jobs without Deadline :
So, what is the scheduling of jobs without a deadline?



To understand this concept, let’s take an example. 
Let us assume the jobs that are connected to scheduling have no deadlines, i.e.  the jobs do not have any upper limit of execution time. Trying to solve it with a greedy approach ;
Let us assume that the service time is associated with the following three tasks :

For scheduling these tasks, let us first find optimal ordering by listing out all possible orderings made in the table below. Since there are three tasks, the tasks can be ordered in 3! ways, which equals 6. In general, for N jobs, there would be N! possible orders.

Schedule 

Total time in system  

 Average time  

[1, 2, 3] 2 + (2 + 7 ) + ( 2 + 7 + 4 ) = 24 8
[1, 3, 2] 2 + (2 + 4 ) + ( 2 + 4 + 7 ) = 21 7
[2, 1, 3] 7 + (7 + 2 ) + ( 7 + 2 + 4 ) = 29 9.6
[2, 3, 1] 7 + (7 + 4 ) + ( 7 + 4 + 2 ) = 31 10.3
[3, 1, 2] 4 + (4 + 2 ) + ( 4 + 2 + 7 ) = 23 7.9
[3, 2, 1] 4 + (4 + 7 ) + ( 4 + 7 + 2 ) = 28 9.3

The average time of a job is obtained by dividing total time in system by number of jobs, i.e. 24/3=8. 
Computations for the remaining jobs are shown in the table above.

The greedy algorithm informally for this problem can be written as follows :

Step 1 – Sort the jobs by service time in non-decreasing order.
Step 2 – Schedule next job of the sorted job list. Including this in the solution set.
Step 3 – If all instances of a sorted job list are solved, then return solution set.

The formal algorithm is given as follows :
Input – An array J with a set of jobs 1 to n along with service time
Output – An optimal schedule

Begin
    S = {sorted array of jobs in J based on service time }
    i = 1
    Schedule = ∅
    while (i < = n ) do                 //for all jobs do
        select the next job i from S    //Selection procedure selects from sorted list
        solution = schedule U jobs i
        i = i+1
    
    End while
    return(Solution)
End

Complexity Analysis :
It can be observed that the core principle of the aforementioned scheduling algorithm is the sorting of tasks
The complexity of sorting is O(n log n) time. All the remaining tasks of that scheduling algorithm would take only O(n) time. 
Therefore, the resultant complexity of the scheduling algorithm is max{n log n, n } = n log n time.

Article Tags :