1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 25 - Maria Litvin, Gary Litvin

23 37 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 23
Dung lượng 420,27 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 25 - Lookup tables and hashing. After you have mastered the material in this chapter, you will be able to: Learn about lookup tables, learn about hashing, review java.util.HashSet and java.util.HashMap.

Trang 1

Lookup Tables and Hashing

 

Hash Function

Danger  Keep Out 

25 Chapter

Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing All

rights reserved.

Java Methods

Object-Oriented Programming

and Data Structures

Maria Litvin ● Gary Litvin

2nd AP edition with GridWorld

Trang 2

Objectives:

java.util.HashMap

Trang 3

Lookup Tables

data very quickly

(or some values)

an array index using a simple formula

Trang 4

Lookup Tables (cont’d)

particular index (no collisions).

Trang 6

Lookup Tables: Example 2

private static final int [ ] n_thPowerOf3 =

{ 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683 }; .

Trang 7

Lookup Tables: Example 3

256 colors used

in a particular image; each of the palette entries corresponds to a triplet of RGB values

Trang 9

Hash Tables

the valid range

onto the same array index — this situation is

Trang 10

Hash Tables (cont’d)

the array indices randomly and uniformly

minimize the number of collisions

resolving collisions: chaining and probing.

Trang 11

Danger  Keep Out 

Trang 12

Danger  Keep Out 

computed using a certain probing formula

Trang 13

using hash tables (with chaining)

Trang 14

small

Load factor =  Total number of items

Number of buckets

Trang 15

iterations over the whole set

the table is automatically rehashed into a

larger table; if possible this should be

avoided

Trang 16

helps calculate the hashing function

range of indices in a particular hash table

Trang 18

should agree with each other:

x.equals (y) x.compareTo (y) == 0

x.equals (y) x.hashCode( ) == y.hashCode( )

Trang 19

Never mind

Trang 20

25­20

Trang 21

Review:

table and a hash table?

Trang 22

Review (cont’d):

the load factor is too high? Too low?

when the load factor exceeds the specified

limit?

capacity to 16 and the load factor limit to

0.75 How many values can be stored in this table before it is rehashed?

Trang 23

Review (cont’d):

method?

Ngày đăng: 04/11/2020, 23:19

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN