¸ñÂ÷/Â÷·Ê
1. Chapter 1: Introduction ...................................................................................................... 1
2. Chapter 2: Algorithm Analysis .......................................................................................... 4
3. Chapter 3: Lists, Stacks, and Queues ................................................................................. 8
4. Chapter 4: Trees ................................................................................................................. 12
5. Chapter 5: Hashing ............................................................................................................ 22
6. Chapter 6: Priority Queues (Heaps) ................................................................................... 27
7. Chapter 7: Sorting .............................................................................................................. 34
8. Chapter 8: The Disjoint Set ADT ...................................................
º»¹®/³»¿ë
Chapter 1: Introduction
1.4 The general way to do this is to write a procedure with heading void processFile( String ?leName ); which opens ?leName, does whatever processing is needed, and then closes it. If a line of the form #include SomeFile is detected, then the call processFile( SomeFile ); is made recursively. Self-referential includes can be detected by keeping a list of ?les for which a call to processFile has not yet terminated, and checking this list before making a new call to processFile. 1.5 The code is shown in Fig. 1.1. _ ______________________________________________________________________________ int ones( int n ) { if( n [ 2 ) return n; return n % 2 + ones( n / 2 ); } Fig. 1.1. _ ______________________________________________________________________________ 1.7 (a) The proof is by induction. The theorem is clearly true for 0 [ X ¡Â 1, since it is true for X ¡ë 1, and for X [ 1, log X is negative. It is also easy to see that the theorem holds for 1 [ X ¡Â 2, since it¡¦(»ý·«)