yerrasowjanya Goto Github PK
Name: yerra sowjanya
Type: User
Company: college
Bio: pursuing btech cse
Location: punjab jalandhar
Name: yerra sowjanya
Type: User
Company: college
Bio: pursuing btech cse
Location: punjab jalandhar
bankers algorithm in c#
// 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(); } }
// 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) }
bankers algorithm in c++
A helpful chatbot for providing medical diagnosis solutions to it's users.
AI project on Healthcare-chatbot
Ai project on Healthcare-chatbot
os assignment bankers algorithm
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.
os repository in java
os repository java
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.
// 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.