CS 481: Assignment #4

due Thursday, April 4

First problem: Problem 14 in Chapter 10 (p. 427 of the text).

Second problem: Buddy allocation systems work on a very general principle -- they are not limited to powers of two. The fundamental idea is a recurrence relation: if you cannot find a block of the appropriate size, you grab a larger block, then cut it into smaller pieces and recursively attempt to allocate from one of the smaller pieces. The binary buddy system takes a piece and cuts it into two equal subpieces; a ternary buddy could cut the large piece into three equal subpieces and thus would have sizes that would grow as powers of 3. More complex buddy systems in common use cut a large piece into unequal pieces; the most common is the Fibonacci buddy system: given a block on ``shelf'' n, it cuts it into two blocks, one for shelf n-1 and one for shelf n-2. The result is that its pieces have sizes that are powers of the golden ratio (approximately 1.62); the Fibonacci buddy system thus offers a larger selection of sizes than the binary buddy system.

For a buddy system that cuts a piece into two (not necessarily equal) pieces, the general recurrence describing block sizes is f(n)=f(n-1)+f(n-k), where k is a strictly positive integer.

  • Why is the first term always f(n-1)?
  • The larger k is, the more pronounced the difference in sizes between the two pieces; why is k=2 a common choice, yet larger values are never used?
  • Discuss how you would implement the Fibonacci buddy system (k=2); the main point is how you would decide which blocks to merge when they are freed.
  • Back to CS 481 home page