Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class FIFO: def __init__(self, block_size): self.block_size = block_size self.blocks = [] self.hit_count = 0 def add(self, number): for block in self.blocks: if number == block:

class FIFO:

def __init__(self, block_size):

self.block_size = block_size

self.blocks = []

self.hit_count = 0

def add(self, number):

for block in self.blocks:

if number == block:

self.hit_count += 1

return

if len(self.blocks) == block_size:

self.blocks.pop()

self.blocks.append(number)

def get_hit_count(self):

return self.hit_count

block_size = int(input('Block size: '))

fifo = FIFO(block_size)

with open("random_1.txt", "r") as f:

lines = len(f.readlines())

f.seek(0)

for i in range(lines):

number = int(f.readline().split(' ')[0])

fifo.add(number)

print(fifo.get_hit_count())

#Random number generation

import random

values = [str(random.randint(0, 999)) for _ in range(1000)]

with open("random_1.txt", "w") as f:

f.writelines(" ".join(values))

Draw a flowchart for this FIFO algorithm implementation by determining the hit count.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions