Program for Shortest Job First (SJF) CPU Scheduling | Greedy | Love Babbar DSA Sheet | IMP | Amazon🔥

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

Комментарии • 18

  • @decostarkumar2562
    @decostarkumar2562 3 года назад +5

    There can be one error . After by incrementing current time then also it does not match start time of other interval. In that case all the inputs wil not come in our answer.

  • @stith_pragya
    @stith_pragya Год назад +1

    Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @snahashiskanrar2126
    @snahashiskanrar2126 Год назад

    Simplest Approach:
    class Solution {
    public:
    long long solve(vector& bt) {
    // code here
    int count = bt.size();
    sort(bt.begin(), bt.end());
    int waitTime = 0;
    int sum = 0;
    for(int i = 1; i < count; i++){
    waitTime += bt[i - 1];
    sum += waitTime;
    }
    return sum/count;
    }
    };

  • @chanderveersinghrathore970
    @chanderveersinghrathore970 3 года назад +3

    what if the arrival time of second job is less then current_time (IG we also need to increment current_time)

  • @nikkimittal9329
    @nikkimittal9329 3 года назад +4

    bhaiya plz operating system ki bhi ek series bana dijiye

  • @mohammadesah7123
    @mohammadesah7123 3 года назад +7

    theres a small bug
    the code shown only works if the least arrival time is 0.
    to fix this initialize current_time to the least arrival time

    • @decostarkumar2562
      @decostarkumar2562 3 года назад

      Also if least arrival time is not zero than the current tine will be the least time + it's execution time.

  • @rahatsshowcase8614
    @rahatsshowcase8614 2 года назад

    Nicee

  • @chitej7373
    @chitej7373 3 года назад +1

    Great video brother keep up the good work

  • @dharsan.s7937
    @dharsan.s7937 3 года назад

    Where did u learnt DSA?

  • @Srm0912
    @Srm0912 3 года назад

    Please make on k centres problem

  • @Realxopythhchgcvn
    @Realxopythhchgcvn 2 года назад +1

    bro you should improve you teaching experience i am not understand with u

    • @jatinsachdeva7488
      @jatinsachdeva7488 2 года назад +2

      yes i agree u total , what you say

    • @akshatjain5684
      @akshatjain5684 2 года назад

      @@jatinsachdeva7488 not could agree more

    • @ashb8552
      @ashb8552 11 месяцев назад

      Video like i the 😂

  • @abhinavagrawal6148
    @abhinavagrawal6148 3 года назад

    Sjf revise ho gya

  • @jatinbhatoya8420
    @jatinbhatoya8420 3 года назад

    code for java users
    public static class Pair implements Comparable {
    int id;
    int arvl;
    int brst;
    public Pair(int id, int arvl, int brst) {
    this.id = id;
    this.arvl = arvl;
    this.brst = brst;
    }
    public int compareTo(Pair o) {
    if (this.arvl < o.arvl) {
    return 1;
    }
    if (this.arvl > o.arvl) {
    return -1;
    } else {
    if (this.brst < o.brst) {
    return 1;
    }
    if (this.brst > o.brst) {
    return -1;
    } else {
    if (this.id < o.id) {
    return 1;
    }
    if (this.id > o.id) {
    return -1;
    } else {
    return 0;
    }
    }
    }
    }
    }
    public static class Pair1 implements Comparable {
    int id;
    int arvl;
    int brst;
    public Pair1(int id, int arvl, int brst) {
    this.id = id;
    this.arvl = arvl;
    this.brst = brst;
    }
    public int compareTo(Pair1 o) {
    if (this.brst < o.brst) {
    return 1;
    }
    if (this.brst > o.brst) {
    return -1;
    } else {
    if (this.arvl < o.arvl) {
    return 1;
    }
    if (this.arvl > o.arvl) {
    return -1;
    } else {
    if (this.id < o.id) {
    return 1;
    }
    if (this.id > o.id) {
    return -1;
    } else {
    return 0;
    }
    }
    }
    }
    }
    public static ArrayList solver(int id[], int arrival[], int burst[]) {
    int time = 0;
    ArrayList arr = new ArrayList();
    PriorityQueue pq = new PriorityQueue(Collections.reverseOrder());
    for (int i = 0; i < id.length; i++) {
    pq.add(new Pair(id[i], arrival[i], burst[i]));
    }
    // while(!pq.isEmpty()){
    // Pair p=pq.poll();
    // System.out.println(p.id+" "+p.arvl+" "+p.brst);
    // }
    PriorityQueue p_q = new PriorityQueue(Collections.reverseOrder());
    while (!pq.isEmpty()) {
    while (!pq.isEmpty() && pq.peek().arvl