Giter VIP home page Giter VIP logo

job-scheduler's Introduction

Job Scheduler

Given a list of jobs you accept a subset of the jobs, rejecting all others, so that the accepted jobs do not overlap in time.

More formally, there will be n jobs labeled 1...n with each job, j, specifying a start time Sj and a finish time Tj. Naturally we have Sj < Tj for all j. Two jobs j and j1 are compatible if the requested intervals do not overlap; that is, either job j is for an earlier time interval than job j1 (Tj <= Sj1), or job j is for a later time than job j1 (Tj1 <= Sj). More generally, that a subset A of jobs is compatible if all pairs of jobs j,j1 within A, j != j1 are compatible. The goal is to select a compatible subset of jobs of maximum possible size. To illustrate, for the following jobs the single compatible set of size 4 is the largest compatible set.

Task 1: Select the largest subset from the given jobs such that no jobs overlap in time.

  • Greedy approach
  • First sort the collection of given jobs by their finish time - O(nlogn)
  • Select the first job, then iteratively search through the sorted collection and select the job which doesn't overlap with previously selected job. - O(n)

Final Runtime: O(nlogn)

Task 2: Now each input job has a cost associated with it. Select the maximum total-cost subset of non-overlapping jobs. Now we do not maximize for number of jobs, we want maximum cost subset

  • Greedy approach doesn't work.
  • Dynamically memoize cost associated with each job such that it doesn't include the cost of overlapping jobs preceding it.
  • Backtrack to get the subset.
  • First sort the collection of given jobs by their finish time - O(nlogn)
  • Find the latest compatible job for each input job - O(n^2)
  • Build memoized array of costs - O(n)
  • Backtrack recursively to get the subset - O(n)

Final Runtime: O(n^2)

job-scheduler's People

Contributors

davemrunal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.