CH 09
CH 09
Chapter 9
Searching and Hashing Algorithms
Search Algorithms
• Item key
– Unique member of the item
– Used in searching, sorting, insertion, deletion
• Number of key comparisons
– Comparing the key of the search item with the key of
an item in the list
• Can use class arrayListType (Chapter 3)
– Implements a list and basic operations in an array
• Array-based lists
– Covered in Chapter 3
• Linked lists
– Covered in Chapter 5
• Works the same for array-based lists and linked lists
• See code on page 499
• Overflow
– No longer a concern
• Data stored in linked lists
• Memory space to store data allocated dynamically
– Hash table size
• No longer needs to be greater than number of items
– Hash table less than the number of items
• Some linked lists contain more than one item
• Good hash function has average linked list length still
small (search is efficient)
• Advantages of chaining
– Item insertion and deletion: straightforward
– Efficient hash function
• Few keys hashed to same home position
• Short linked list (on average)
– Shorter search length
• If item size is large
– Saves a considerable amount of space