Saint Louis University |
Computer Science 3100
|
Dept. of Computer Science |
Topics: review
Related Reading: Chapters 1, 2, 3, 8, and 10 of CLRS
Due:
10:00am, Wednesday, September 7, 2016
You must adhere to the policies on academic integrity, paying particular attention to the limits on collaboration.
Problem 2-1 (starting on page 39 of CLRS)
Problem 8-6 (on page 208 of CLRS)
Exercise 10.3-4 (on page 245 of CLRS). To be sufficiently rigorous, your solution should include complete pseudocode, using the style of that chapter, and an explanation regarding the correctness and efficiency of your solution. Although not stated in the book's problem, it is important that both of your operations still run in O(1) time. I'd also like to note that I find the book's hint about an "array implementation of a stack" to be more misleading that it is useful. I suggest ignoring that entirely.
Finally, please note that you are not responsible for reimplementing the linked-list operations LIST-INSERT and LIST-DELETE from section 10.2. You are just responsbile for designing the FREE and ALLOCATE methods that might be used by those routines for proper memory management.
As an example, if a linked list had contents S-A-M-P-L-E (assuming character data), a representation might be the following:
index: 1 2 3 4 5 6 next: 6 5 1 2 - 4 key: A L S P E M prev: 3 4 - 6 2 1if the letter L were removed from the list, the LIST-DELETE code would make the linked list changes to splice the neighboring P and E together, while no longer using node 2, resulting in
index: 1 2 3 4 5 6 next: 6 - 1 5 - 4 key: A - S P E M prev: 3 - - 6 4 1At this point that code should call FREE(x) where x is the newly unused node stored at index 2. Your job is to decide how to implement FREE( ) in such a scenario so that by the time you finish, the representation is compact (and the user's linked list remains valid).
In similar regard, if a user wished to add another node to their list, your job with ALLOCATE( ) is to return the location of the new node; you do not need to concern yourself with how that new node becomes encorporated in the list after it is allocated.
Exercise 10.2-8 (on page 241 of CLRS). To be sufficiently rigorous, your solution should include complete pseudocode, using the style of that chapter, and an explanation regarding the correctness and efficiency of your solution.
Assume that we have a sequence of n numbers containing all the integers from 0 to n except one, in arbitrary order. The goal is to efficiently determine which number is missing. However, the numbers are represented in binary. For example, the input for n=5 might be modeled as:
1 | 0 | 1 |
0 | 1 | 1 |
0 | 1 | 0 |
0 | 0 | 0 |
0 | 0 | 1 |
In solving the problem, you will be charged for each bit of the input that is examined. Therefore, at the beginning of the process for a given n, the unknown input might be viewed as follows:
? | ? | ? |
? | ? | ? |
? | ? | ? |
? | ? | ? |
? | ? | ? |
Problem 4-5 (starting on page 109 of CLRS)