| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- Class
- C++
- Deep Learning
- assignment operator
- vscode
- 백준
- pointer
- Object Oriented Programming
- 파이썬
- 함수
- 반복문
- predictive analysis
- Pre-processing
- Python
- Data Science
- function
- string
- 문자열
- 오블완
- 포인터
- array
- baekjoon
- 알고리즘
- OOP
- pass by reference
- 티스토리챌린지
- programming
- 배열
- raw data
- const
- Today
- Total
Channi Studies
[Data Structure] Hash Table - 4 | Hash Table Resizing 본문
[Data Structure] Hash Table - 4 | Hash Table Resizing
Chan Lee 2025. 4. 10. 03:10Resize Operation
A hash table resize opeartion increases the number of buckets, while preserving all existing items.
A hash table with N buckets is commonly resized to the next prime number ≥ N * 2.
A new array is allocated, and all items from the old array are re-insrted into the new array, making the resize opeartion's time complexity O(N).
Let's take a look into an example of hash table resizing.
Suppose the hash table below is resized. The hash function used both before and after resizing is: hash(key) = key % N, where N is the table size.

1) What is the most likely allocated size for the resized hash table?
→ Current size = 7 → Next prime = 17
2) How many elements are in the hash table after resizing?
→ Currently existing elements in the table should be copied to the resized table, so there are same number of elements. = 4
3) At what index does 99 reside in the resized table?
→ New size = 17 → 99 % 17 = 14
But when do we actually have to resize a hash table?
Resize Operation
A hash table's load factor is the number of items in the hash table divided by the number of buckets.
Ex. A hash table with 18 items and 31 buckets has a load factor of 18/31 = 0.58.
This load factor may be used to decide when to resize the hash table.
An implementation may choose to resize the hash table when one or more of the following values exceeds a certain thrshold:
- Load factor
- When using open-addressing, the number of collisions during an insertion
- When using chaining, the size of bucket's linked-list



'Data Science > Data Structure & Algorithm' 카테고리의 다른 글
| [Data Structure] Hash Table - 6 | Python Implementation (0) | 2025.04.10 |
|---|---|
| [Data Structure] Hash Table 5 - Common Hash Functions (0) | 2025.04.10 |
| [Data Structure] Hash Table - 3 | Double Hashing (0) | 2025.04.09 |
| [Data Structure] Hash Table - 2 | Linear Probing & Quadratic Probing (0) | 2025.04.09 |
| [Data Structure] Hash Table - 1 | Basic Operations & Chaining Collision Handling Technique (0) | 2025.04.09 |