Homework 4

Due: Thursday November 29 at the beginning of class.

Reading: Chapters 21 and 34 (15 and 16 to read ahead)


1. Show the final data structure and give the answers to the FIND-SET operations for the following sequence of operations using the implementations in Section 21.2. (When two lists of the same length are combined by a UNION operation assume the head with the smaller key becomes the new head.)

   for i=1 to 20
      do MAKE-SET(i)
   for i=1 to 11 by 2
      do UNION(i+1,i)
   for i=1 to 6
      do UNION(i+12,2i)
   UNION(19,13)
   UNION(20,18)
   for i=1 to 9 by 4
      do UNION(i+3,i)
   FIND-SET(16)
   FIND-SET(20)
   UNION(10,14)
   FIND-SET(17)
   FIND-SET(20)
2. Repeat the previous problem using the implementations from Section 21.3. (Note that in the pseudo-code for LINK when two sets whose roots have the same rank are combined the root of the second set becomes the new root.)
3. Page 509 21.3-2
4. Page 509 21.3-3
5. Page 978 34.1-1
6. Page 978 34.1-5
7. Page 982 34.2-1
8. Page 983 34.2-3
9. Page 994 34.3-1
10. Page 994 34.3-3
11. Page 1002 34.4-3
12. Page 1002 34.4-4 (You may use the result of exercise 34.3-7.)
13. Page 1002 34.4-6
14. Page 1017 34.5-1
15. Page 1017 34.5-5
16. Page 1017 34.5-6
17. Page 1018 34.1ab

Solutions (pdf)
Access to Solutions


The CMPS201 Web:
Copyright 2007; Department of Computer Engineering, University of California, Santa Cruz.
martine@cse.ucsc.edu