Question

In: Computer Science

We mentioned the first fit and best fit as applied to finding parking spaces at a...

We mentioned the first fit and best fit as applied to finding parking spaces at a mall.

a.) Write a first-fit car parking algorithm

b.) Write a best-fit car parking algorithm

c.) In your own words, explain why first fit might be a better algorithm on average to minimize the time to get to the door of the mall.

This has to be programmed within Python. Please and thank you.

Solutions

Expert Solution

def firstFit(blockSize, m, processSize, n):

     

    # Stores block id of the

    # block allocated to a process

    allocation = [-1] * n

    # Initially no block is assigned to any process

    # pick each process and find suitable blocks

    # according to its size ad assign to it

    for i in range(n):

        for j in range(m):

            if blockSize[j] >= processSize[i]:

                 

                # allocate block j to p[i] process

                allocation[i] = j

                # Reduce available memory in this block.

                blockSize[j] -= processSize[i]

                break

    print(" Process No. Process Size      Block no.")

    for i in range(n):

        print(" ", i + 1, "         ", processSize[i],

                          "         ", end = " ")

        if allocation[i] != -1:

            print(allocation[i] + 1)

        else:

            print("Not Allocated")

# Driver code

if __name__ == '__main__':

    blockSize = [100, 500, 200, 300, 600]

    processSize = [212, 417, 112, 426]

    m = len(blockSize)

    n = len(processSize)

    firstFit(blockSize, m, processSize, n)

     

def bestFit(blockSize, m, processSize, n):
  
# Stores block id of the block
# allocated to a process
allocation = [-1] * n
  
# pick each process and find suitable
# blocks according to its size ad
# assign to it
for i in range(n):
  
# Find the best fit block for
# current process
bestIdx = -1
for j in range(m):
if blockSize[j] >= processSize[i]:
if bestIdx == -1:
bestIdx = j
elif blockSize[bestIdx] > blockSize[j]:
bestIdx = j
  
# If we could find a block for
# current process
if bestIdx != -1:
  
# allocate block j to p[i] process
allocation[i] = bestIdx
  
# Reduce available memory in this block.
blockSize[bestIdx] -= processSize[i]
  
print("Process No. Process Size Block no.")
for i in range(n):
print(i + 1, " ", processSize[i],
end = " ")
if allocation[i] != -1:
print(allocation[i] + 1)
else:
print("Not Allocated")
  
# Driver code
if __name__ == '__main__':
blockSize = [100, 500, 200, 300, 600]
processSize = [212, 417, 112, 426]
m = len(blockSize)
n = len(processSize)
  
bestFit(blockSize, m, processSize, n)


Related Solutions

If there were no parking meters and fees, how do you think the available parking spaces...
If there were no parking meters and fees, how do you think the available parking spaces would be allocated? Would that allocation system be better? For whom? Without parking fees, do you think people would perceive that there is more or less of a "parking problem"? If parking fees are to be used, should they vary by location? Time of day? Time of year?
The administration at GSU wants to estimate the number of parking spaces they will need next...
The administration at GSU wants to estimate the number of parking spaces they will need next year. They survey 80 students; 75 of the students in the sample drive to campus by themselves each day. Which of the following is a reason the administration should not calculate a confidence interval for the proportion of all students who drive to campus? Check all that apply. The sample needs to be random but we don’t know if it is. The actual count...
Based on the limited amount of available student parking spaces on the GSU campus, students are...
Based on the limited amount of available student parking spaces on the GSU campus, students are being encouraged to ride their bikes (when appropriate). The administration conducted a survey to determine the proportion of students who ride a bike to campus. Of the 123 students surveyed 5 rides a bike to campus. Which of the following is a reason the administration should not calculate a confidence interval to estimate the proportion of all students who ride a bike to campus?...
City of Jonesboro hosts events at the historic drive-in theatre and uses the parking spaces for...
City of Jonesboro hosts events at the historic drive-in theatre and uses the parking spaces for parking for downtown patrons. Currently it is set up as an enterprise fund and has no long-term debt. Machinery and equipment are the only capital assets recorded by the drive-in theatre. The building is used for rental space for local business owners and all operation and maintenance services are provided by the city. Your company was hired to complete the audit for the City...
An Oxxo has a small parking lot with three spaces reserved for customers. If the store...
An Oxxo has a small parking lot with three spaces reserved for customers. If the store is open cars arrive and use a space with an average rate of 2 per hour. For n = 0, 1, 2, 3, the probability P n of that there are exactly n spaces occupied is P 0 = 0.1, P 1 = 0.2, P 2 = 0.4, P 3 = 0.3. a) Describe the interpretation of this parking lot as a queuing system,...
Suppose the elasticity of demand for your parking lot spaces, which are located in a downtown...
Suppose the elasticity of demand for your parking lot spaces, which are located in a downtown business district, is –1.8, and the price of parking is $11 per day. Additionally, suppose that your MC is zero, and your capacity has been 80% full at 9 AM each day over the last month. Since demand is ( ELASTIC, INELASTIC, OR UNIT ELASTIC)  , and the lot is below capacity, (INCREASED, DECREASED, OR UNCHANGED)   is the optimal pricing strategy.
On game days, homeowners near a college football stadium used to rent parking spaces in their...
On game days, homeowners near a college football stadium used to rent parking spaces in their driveways to fans at a market rate of $11 (4,000 spaces available) Upon hearing rumors that homeowners were unfairly increasing parking prices for certain "high demand" games, the local town council issued a new town ordinance setting the maximum parking fee at $7. How will homeowners react? How will football fans react? What is the outcome of their actions?
Compare logical to physical organization. Compare fixed to dynamic partitioning. Describe the Best-, First-, and Next-fit...
Compare logical to physical organization. Compare fixed to dynamic partitioning. Describe the Best-, First-, and Next-fit algorithms. Describe page tables.
The Business School at State University currently has three parking lots, each containing 155 spaces. Two...
The Business School at State University currently has three parking lots, each containing 155 spaces. Two hundred faculty members have been assigned to each lot. On a peak day, an average of 70% of all lot 1 parking sticker holders show up, an average of 72% of all lot 2 parking sticker holders show up, and an average of 74% of all lot 3 parking sticker holders show up. a. Given the current situation, estimate the probability that on a...
a) Briefly describe each of the following memory allocation algorithms: i. Best fit ii. Next fit...
a) Briefly describe each of the following memory allocation algorithms: i. Best fit ii. Next fit b) Given fixed memory partitions of 200 KB, 100 KB, 400 KB, 300 KB, and 400 KB (in order), how would each of the algorithms from (a) place processes in memory if they required 187 KB, 228 KB, 126 KB, 306 KB (in order)? c) A system has five page frames. The time of loading, time of last access, and the Referenced and Modified...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT