0% found this document useful (0 votes)
2K views2 pages

To Implement Least Frequently Used (LFU) Page Replacement Algorithm

The document describes an implementation of the Least Frequently Used (LFU) page replacement algorithm in C code. It takes the number of blocks as input, then the page sequence length and values. It initializes variables to track the pages, blocks, and reference counts. It iterates through the sequence, tracking references by incrementing the count for hits or adding new pages/blocks. On a miss if blocks are available it adds the new page, else it replaces the least frequently used page by finding the minimum reference count. It outputs the final block values.

Uploaded by

Rishav Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views2 pages

To Implement Least Frequently Used (LFU) Page Replacement Algorithm

The document describes an implementation of the Least Frequently Used (LFU) page replacement algorithm in C code. It takes the number of blocks as input, then the page sequence length and values. It initializes variables to track the pages, blocks, and reference counts. It iterates through the sequence, tracking references by incrementing the count for hits or adding new pages/blocks. On a miss if blocks are available it adds the new page, else it replaces the least frequently used page by finding the minimum reference count. It outputs the final block values.

Uploaded by

Rishav Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim: To implement Least frequently Used(LFU) page replacement algorithm.

Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,k,l,lc,bf,bn=0,c=0,flag=0,n,st[10],b[10],r[10];
clrscr();
for(i=0;i<10;i++)
{ st[i]=0;b[i]=0;r[i]=0;
}
printf("enter the no. of blocks\n");
scanf("%d",&bf);
printf("\n enter the length of page sequence: ");
scanf("%d",&n);
printf("\n enter the page sequence: ");
for(i=0;i<n;i++)
scanf("%d",&st[i]);
for(i=0;i<n;i++)
printf("
%d",st[i]);
for(i=0;i<n;i++)
{ flag=0;
printf("\n i= %d
",st[i]);
for(k=0;k<bn;k++)
if(st[i]==b[k])
{ r[k]=r[k]+1;flag=1;break; }
if(flag==0)
{ if(bn<bf)
{ b[bn]=st[i];
r[bn]=r[bn]+1;
bn++; }
else
{
l=n;
for(k=0;k<bf;k++)
if(r[k]<l) { l=r[k];
b[lc]=st[i];
c=0;
for(k=0;k<=i;k++)
if(st[i]==st[k])
c=c+1;
r[lc]=c;
}
}
printf("\n");
for (k=0;k<bf;k++) printf("
}
getch();
}

lc=k;

%d",b[k]);

out put

enter no. of blocks: 3


enter length of page sequence :9
enter the page sequence : 1
2
3
1
4
2
1
5
6
1
2
3
1
4
1
1
1
1
1
1
1
1
1

0
2
2
2
4
2
2
2
2

0
0
3
3
3
3
3
5
6

Varible List:
Variable
Name
St[10]
B[10]
R[10]
Lc
Bf
Bn
C
Flag

Data
Type
int
int
int
int
Int
Int
Int
Int

Initial
Values
0
0
0

You might also like