Write an implementation of the Banker's Algorithm in PYTHON. If the input state is not a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write an implementation of the Banker's Algorithm in PYTHON. If the input state is not a "safe state", your algorithm should say this. If it is a safe state, your algorithm should print a "safe sequence" of processes that we can execute, going from safe state to safe state, until all the processes have terminated. The input to your program should be the data we discussed in lectures - the matrices C, A, R and F. C and A are (n x m) while R and F are (1x m). Cij is the total amount of resource j that is needed by process i. Aij is the amount of resource j that is currently allocated to process i. Ri is the total amount of resource i in the system, while Fi is the amount of resource i that is free/available. You can assume all the numbers in C, A, R, F are non-negative integers. Please read in the data from the user: C and A can be read in as a "list of lists" while R and F are read in each as a list. Test your program, and report your result on the states defined by the following two sets of data: 1. R = [6,4,7,5], F = [3,1,1,1], C = [[3,3,2,2], [1,2,3,4],[1,3,5,0]], A = [[1,2,2,1],[1,0,3,3],[1,2,1,0]]. 2. R = [3,13,11], F = [1,5,2], C = [[0,0,1], [1,7,5], [2,3,5], [0,6,5]], A = [[0,0,1],[1,0,0],[1,3,5],[0,6,3]]. Write an implementation of the Banker's Algorithm in PYTHON. If the input state is not a "safe state", your algorithm should say this. If it is a safe state, your algorithm should print a "safe sequence" of processes that we can execute, going from safe state to safe state, until all the processes have terminated. The input to your program should be the data we discussed in lectures - the matrices C, A, R and F. C and A are (n x m) while R and F are (1x m). Cij is the total amount of resource j that is needed by process i. Aij is the amount of resource j that is currently allocated to process i. Ri is the total amount of resource i in the system, while Fi is the amount of resource i that is free/available. You can assume all the numbers in C, A, R, F are non-negative integers. Please read in the data from the user: C and A can be read in as a "list of lists" while R and F are read in each as a list. Test your program, and report your result on the states defined by the following two sets of data: 1. R = [6,4,7,5], F = [3,1,1,1], C = [[3,3,2,2], [1,2,3,4],[1,3,5,0]], A = [[1,2,2,1],[1,0,3,3],[1,2,1,0]]. 2. R = [3,13,11], F = [1,5,2], C = [[0,0,1], [1,7,5], [2,3,5], [0,6,5]], A = [[0,0,1],[1,0,0],[1,3,5],[0,6,3]].
Expert Answer:
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these operating system questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
As manager of a local pizza parlor, you want to develop a balanced scorecard so you can more effectively monitor the restaurants performance. Required a. Propose at least two goals for each...
-
Does a corporation pay the AMT in addition to or instead of the regular tax? Briefly explain.
-
Fallon Company, a toy manufacturer that also operates several retail outlets, is preparing its December 31, 2013, financial statements. It has identified the following legal situations that may...
-
1. Multi-National Marriott Hotels Could Face Consumer Backlash and up to $1 Billion in Regulatory Fines and Litigation Costs for Massive Data Breach Marriott had sustained several cyberattacks prior...
-
The tax credit for rehabilitation expenditures is available to help offset the costs related to substantially rehabilitating certain buildings. The credit is calculated on the rehabilitation...
-
Appraise if the following examples would be regarded as discrimination in hiring advertisements. Comment if they will be regarded as discriminative according to the Tripartite Alliances on Fair and...
-
Sketchy Shoe is a subsidiary of Pacific Brands. Pacific routinely sells merchandise to Sketchy at a 25% markup on cost. Information on intercompany merchandise transactions is below (in thousands):...
-
Suppose that the US, a large country decides to rapidly reduce its current account deficit by restricting its trade of goods and services with the rest of the world. Assume that this policy brings...
-
In chronological order, please answer the following questions truthfully using the reference . Define Micro Economics and Macro Economics---answer--- What is opportunity cost?---answer--- What is...
-
Which technological invention of the 1980s revolutionized DNA data collection by allowing scientists to amplify millions of copies of DNA from a very small amount of template DNA?
-
What technology would you use to assure consistent delivery of the training message in every restaurant every time it is given, and why. Assume the maximum training time per topic is 10 minutes and...
-
Molnupiravir was the novel drug to show effectiveness against SARS-CoV-2. Molnupiravir disrupts the virus from making copies of itself. The structure of the drug is shown at right. a) What process in...
-
1. Contemporary situational leadership theories (Connect, Perform) Type the leadership term that best describes each situation. Use each term only once. Vertical dyads Follower readiness Telling...
-
1. Following are information about Alhadaf Co. Cost incurred Inventory Purchases Sales Adverting expense Salary Expense Depreciation Beginning Inventory Ending Inventory Amount 118,000 350.000 90,000...
-
The isEmpty routine for quadratic probing has not been written. Can you implement it by returning the expression currentSize==0?
-
For the tree in Figure 4.70: a. Which node is the root? b. Which nodes are leaves?
-
Using the quicksort implementation in this chapter, determine the running time of quicksort for a. Sorted input b. Reverse-ordered input c. Random input
-
Steam at 8 bar pressure and dryness fraction of 0.9 expands at constant pressure until the temperature is \(200^{\circ} \mathrm{C}\). Calculate the work input and heat supplied per \(\mathrm{kg}\) of...
-
Find the enthalpy and internal energy of steam at a pressure of 10 bar and temperature \(200^{\circ} \mathrm{C}\). Assume \(c_{p s}=2.1 \mathrm{~kJ} / \mathrm{kg}\).K for superheated steam.
-
The steam is generated at 8 bar from water at \(32^{\circ} \mathrm{C}\). Find the heat required to produce \(1 \mathrm{~kg}\) of steam. (a) When the steam at dryness \(=0.9\). (b) When the steam is...
Study smarter with the SolutionInn App