Data Structures and Algorithms: CHAPTER 12: Memory Management
12.3There are sequences of requests a1, a2, . . . , an whose sum is less
than 16, such that the last request cannot be satisfied. For example, consider the sequence 5, 5, 5. The first request causes the initial block of size 16 to be split into two blocks of size 8 and one of them is used to satisfy the request. The remaining free block of size 8 satisfies the second request, and there is no free space to satisfy the third request.
Find a sequence a1, a2, . . . , an of (not necessarily identical) integers between 1 and 16, whose sum is as small as possible, such that, treated as a sequence of requests for blocks of size a1, a2, . . . , an, the last request cannot be satisfied. Explain why your sequence of requests cannot be satisfied, but any sequence whose sum is smaller can be satisfied.
Consider compacting memory while managing equal-sized blocks. Assume each block consists of a data field and a pointer field, and that we have marked every block currently in use. The blocks are currently
12.4
located between memory locations a and b. We wish to relocate all active blocks so that they occupy contiguous memory starting at a. In relocating a block remember that the pointer field of any block pointing to the relocated block must be updated. Design an algorithm for compacting the blocks.
Consider an array of size n. Design an algorithm to shift all items in the array k places cyclically counterclockwise with only constant additional
12.5memory independent of k and n. Hint. Consider what happens if we reverse the first k elements, the last n-k elements, and then finally the entire array.
Design an algorithm to replace a substring y of a string xyz by another
12.6substring y' using as little additional memory as possible. What is the time and space complexity of your algorithm?
12.7
Write a program to make a copy of a given list. What is the time and space complexity of your program?
12.8
Write a program to determine whether two lists are identical. What is the time and space complexity of your program?
12.9Implement Morris' heap compaction algorithm of Section 12.6.