Git Product home page Git Product logo

yerra sowjanya's Projects

assignment-in-c-hash icon assignment-in-c-hash

// C# Program for Bankers Algorithm using System; using System.Collections.Generic; class GFG { static int n = 5; // Number of processes static int m = 3; // Number of resources int [,]need = new int[n, m]; int [,]max; int [,]alloc; int []avail; int []safeSequence = new int[n]; void initializeValues() { // P0, P1, P2, P3, P4 are the Process // names here Allocation Matrix alloc = new int[,] {{ 0, 1, 0 }, //P0 { 2, 0, 0 }, //P1 { 3, 0, 2 }, //P2 { 2, 1, 1 }, //P3 { 0, 0, 2 }};//P4 // MAX Matrix max = new int[,] {{ 7, 5, 3 }, //P0 { 3, 2, 2 }, //P1 { 9, 0, 2 }, //P2 { 2, 2, 2 }, //P3 { 4, 3, 3 }};//P4 // Available Resources avail = new int[] { 3, 3, 2 }; } void isSafe() { int count = 0; // visited array to find the // already allocated process Boolean []visited = new Boolean[n]; for (int i = 0; i < n; i++) { visited[i] = false; } // work array to store the copy of // available resources int []work = new int[m]; for (int i = 0; i < m; i++) { work[i] = avail[i]; } while (count<n) { Boolean flag = false; for (int i = 0; i < n; i++) { if (visited[i] == false) { int j; for (j = 0; j < m; j++) { if (need[i, j] > work[j]) break; } if (j == m) { safeSequence[count++] = i; visited[i] = true; flag = true; for (j = 0; j < m; j++) { work[j] = work[j] + alloc[i, j]; } } } } if (flag == false) { break; } } if (count < n) { Console.WriteLine("The System is UnSafe!"); } else { //System.out.println("The given System is Safe"); Console.WriteLine("Following is the SAFE Sequence"); for (int i = 0; i < n; i++) { Console.Write("P" + safeSequence[i]); if (i != n - 1) Console.Write(" -> "); } } } void calculateNeed() { for (int i = 0;i < n; i++) { for (int j = 0;j < m; j++) { need[i, j] = max[i, j] - alloc[i, j]; } } } // Driver Code public static void Main(String[] args) { GFG gfg = new GFG(); gfg.initializeValues(); // Calculate the Need Matrix gfg.calculateNeed(); // Check whether system is in // safe state or not gfg.isSafe(); } }

bankers-algorithm-in-c icon bankers-algorithm-in-c

// Banker's Algorithm #include <stdio.h> int main() { // P0, P1, P2, P3, P4 are the Process names here int n, m, i, j, k; n = 5; // Number of processes m = 3; // Number of resources int alloc[5][3] = { { 0, 1, 0 }, // P0 // Allocation Matrix { 2, 0, 0 }, // P1 { 3, 0, 2 }, // P2 { 2, 1, 1 }, // P3 { 0, 0, 2 } }; // P4 int max[5][3] = { { 7, 5, 3 }, // P0 // MAX Matrix { 3, 2, 2 }, // P1 { 9, 0, 2 }, // P2 { 2, 2, 2 }, // P3 { 4, 3, 3 } }; // P4 int avail[3] = { 3, 3, 2 }; // Available Resources int f[n], ans[n], ind = 0; for (k = 0; k < n; k++) { f[k] = 0; } int need[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) need[i][j] = max[i][j] - alloc[i][j]; } int y = 0; for (k = 0; k < 5; k++) { for (i = 0; i < n; i++) { if (f[i] == 0) { int flag = 0; for (j = 0; j < m; j++) { if (need[i][j] > avail[j]){ flag = 1; break; } } if (flag == 0) { ans[ind++] = i; for (y = 0; y < m; y++) avail[y] += alloc[i][y]; f[i] = 1; } } } } printf("Following is the SAFE Sequence\n"); for (i = 0; i < n - 1; i++) printf(" P%d ->", ans[i]); printf(" P%d", ans[n - 1]); return (0); // This code is contributed by Deep Baldha (CandyZack) }

healthbot icon healthbot

A helpful chatbot for providing medical diagnosis solutions to it's users.

os icon os

os assignment bankers algorithm

os-repository icon os-repository

The algorithm was developed in the design process for the THE operating system and originally described (in Dutch) in EWD108.[1] When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time.

os1 icon os1

The algorithm was developed in the design process for the THE operating system and originally described (in Dutch) in EWD108.[1] When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time.

sowji icon sowji

// C# Program for Bankers Algorithm using System; using System.Collections.Generic; class GFG { static int n = 5; // Number of processes static int m = 3; // Number of resources int [,]need = new int[n, m]; int [,]max; int [,]alloc; int []avail; int []safeSequence = new int[n]; void initializeValues() { // P0, P1, P2, P3, P4 are the Process // names here Allocation Matrix alloc = new int[,] {{ 0, 1, 0 }, //P0 { 2, 0, 0 }, //P1 { 3, 0, 2 }, //P2 { 2, 1, 1 }, //P3 { 0, 0, 2 }};//P4 // MAX Matrix max = new int[,] {{ 7, 5, 3 }, //P0 { 3, 2, 2 }, //P1 { 9, 0, 2 }, //P2 { 2, 2, 2 }, //P3 { 4, 3, 3 }};//P4 // Available Resources avail = new int[] { 3, 3, 2 }; } void isSafe() { int count = 0; // visited array to find the // already allocated process Boolean []visited = new Boolean[n]; for (int i = 0; i < n; i++) { visited[i] = false; } // work array to store the copy of // available resources int []work = new int[m]; f

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.