TAILIEUCHUNG - Lecture Data Structures: Lesson 42

Lecture Data Structures: Lesson 42 provide students with knowledge about example hash functions; collision; find something to do with the second and subsequent values that hash to this same location; solution for handling collisions; open addressing and closed hashing; . | Lecture Data Structures Dr. Sohail Aslam Example Hash Functions If the keys are integers then key T is generally a good hash function unless the data has some undesirable features. For example if T 10 and all keys end in zeros then key T 0 for all keys. In general to avoid situations like this T should be a prime number. Collision Suppose our hash function gave us 0 kiwi the following values 1 hash quot apple quot 5 hash quot watermelon quot 3 2 banana hash quot grapes quot 8 3 watermelon hash quot cantaloupe quot 7 4 hash quot kiwi quot 0 hash quot strawberry quot 9 5 apple hash quot mango quot 6 hash quot banana quot 2 6 mango 7 cantaloupe hash quot honeydew quot 6 8 grapes 9 strawberry Now what Collision When two values hash to the same array location this is called a collision Collisions are normally treated as first come first served the first value that hashes to the location gets it We have to find something to do with the second and subsequent values that hash to this same location. Solution for Handling collisions Solution 1 Search from there for an empty location Can stop searching when we find the value or an empty location. Search must be wrap-around at the end. Solution for Handling collisions Solution 2 Use a second hash function .and a third and a fourth and a fifth . Solution for Handling collisions Solution 3 Use the array location as the header of a linked list of values that hash to this location Solution 1 Open Addressing This approach of handling collisions is called open addressing it is also known as closed hashing. More formally cells at h0 x h1 x h2 x are tried in succession where hi x hash x f i mod TableSize with f 0 0. The function f is the collision resolution strategy. Linear Probing We use f i i . f is a linear function of i. Thus location x hash x i mod TableSize The collision resolution strategy is called linear probing because it scans the array sequentially with wrap around in search of an empty cell. Linear Probing .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.