C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
GATE question on best fit and first fitFrom the GATE point of view, Numerical on best fit and first fit are being asked frequently in 1 mark. Let's have a look on the one given as below. Q. Process requests are given as;25 K , 50 K , 100 K , 75 K Determine the algorithm which can optimally satisfy this requirement.
In the question, there are five partitions in the memory. 3 partitions are having processes inside them and two partitions are holes. Our task is to check the algorithm which can satisfy the request optimally. Using First Fit algorithmLet's see, how first fit algorithm works on this problem. 1. 25 K requirementThe algorithm scans the list until it gets first hole which should be big enough to satisfy the request of 25 K. it gets the space in the second partition which is free hence it allocates 25 K out of 75 K to the process and the remaining 50 K is produced as hole. 2. 50 K requirementThe 50 K requirement can be fulfilled by allocating the third partition which is 50 K in size to the process. No free space is produced as free space. 3. 100 K requirement100 K requirement can be fulfilled by using the fifth partition of 175 K size. Out of 175 K, 100 K will be allocated and remaining 75 K will be there as a hole. 4. 75 K requirementSince we are having a 75 K free partition hence we can allocate that much space to the process which is demanding just 75 K space. Using first fit algorithm, we have fulfilled the entire request optimally and no useless space is remaining. Let's see, How Best Fit algorithm performs for the problem. Using Best Fit Algorithm1. 25 K requirementTo allocate 25 K space using best fit approach, need to scan the whole list and then we find that a 75 K partition is free and the smallest among all, which can accommodate the need of the process. Therefore 25 K out of those 75 K free partition is allocated to the process and the remaining 5o K is produced as a hole. 2. 50 K requirementTo satisfy this need, we will again scan the whole list and then find the 50 K space is free which the exact match of the need is. Therefore, it will be allocated for the process. 3. 100 K requirement100 K need is close enough to the 175 K space. The algorithm scans the whole list and then allocates 100 K out of 175 K from the 5th free partition. 4. 75 K requirement75 K requirement will get the space of 75 K from the 6th free partition but the algorithm will scan the whole list in the process of taking this decision. By following both of the algorithms, we have noticed that both the algorithms perform similar to most of the extant in this case. Both can satisfy the need of the processes but however, the best fit algorithm scans the list again and again which takes lot of time. Therefore, if you ask me that which algorithm performs in more optimal way then it will be First Fit algorithm for sure. Therefore, the answer in this case is A.
Next TopicNeed for Paging
|