How does worst-fit memory allocation react when encountering contiguous empty memory blocks? So I have a problem understanding how the worst-fit protocol for memory allocation reacts to contiguous blocks of empty memory.  None of the examples I have found address this possibility.

For example, say you have the following blocks (where 'O' stands for occupied block and 'E' stands for empty block) and are to allocate 10 MB via the worst-fit algorithm:

------------------------------------------------------------
|10 MB O | 40 MB E | 10 MB O | 20 MB E | 30 MB E | 10 MB O |
------------------------------------------------------------
----0---------1---------2---------3---------4---------5-----


My question is does the worst-fit algorithm select block one leaving behind a 30 MB hole in block 1, or does it select block 3 leaving behind a cumulative 40 MB hole between blocks 3 and 4?
You have to assume that the blocks are what they are; if they can be coalesced into larger blocks, then this has already happened (ergo, perhaps the blocks that you have before you are not in fact adjacent in memory; they are an abstract list!) So, in short, there is no cumulative hole which spans multiple blocks.

So worst fit just walks the list of free blocks that it knows about and finds the largest block and takes from there.