일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 백준
- 포인터
- Data Science
- 반복문
- 오블완
- C++
- 함수
- array
- Deep Learning
- vscode
- Pre-processing
- baekjoon
- 문자열
- pass by reference
- const
- pointer
- Object Oriented Programming
- Class
- Python
- 알고리즘
- function
- programming
- OOP
- 파이썬
- raw data
- string
- 티스토리챌린지
- assignment operator
- predictive analysis
- 배열
- Today
- Total
Channi Studies
[Data Structure] Hash Table - 2 | Linear Probing & Quadratic Probing 본문
[Data Structure] Hash Table - 2 | Linear Probing & Quadratic Probing
Chan Lee 2025. 4. 9. 08:27Linear Probing
A hash table with linear probing handles a collision by starting at the key's mapped bucket, and then linearly searches subsequent buckets until an empty bucket is found.


Item 124 should be inserted into bucket 4 since 124 % 10 = 4, but bucket 4 is already occupied, so it searched for next null (empty) bucket appearing linearly starting from the original bucket.
Since bucket 5 was empty, item 124 is inserted into bucket 5.
When searching for an item, it starts from the mapped bucket.
Then it linearly searches for the item until it finds the item and returns it, or encounters an empty (null) bucket and returns null.
Empty Bucket Types
Actually, linear probing distinguishes two types of empty buckets.
An empty-since-start bucket has been empty since the hash table was created.
An empty-after-removal bucket had an item removed that caused the bucket to now be empty.
The distinction will be important during searches, since searching only stops for empty-since-start, not for empty-after-removal.
Quadratic Probing
A hash table with quadratic probing handles a collision by starting at the key's mapped bucket, and then quadratically searches subsequent buckets until an empty bucket is found.
If an item's mapped bucket is H, the formula (H + cl * 𝑖 + c2 * 𝑖²) mod (tablesize) is used to determine the item's index in the hash table.
c1 and c2 are progammer-defined constants for quadratic probing.
Inserting a key uses the formula, starting with 𝑖 = 0, to repeatedly search the hash table until an empty bucket is found.
Each time an empty bucket is not found, 𝑖 is incremented by 1.
Iterating through sequential 𝑖 values to obtain the desired table index is called the probing sequence.
This is an example of inserting 3 items into a hash table with quadratic probing, using c1 = c2 = 1.

'Data Science > Data Structure & Algorithm' 카테고리의 다른 글
[Data Structure] Hash Table - 4 | Hash Table Resizing (0) | 2025.04.10 |
---|---|
[Data Structure] Hash Table - 3 | Double Hashing (0) | 2025.04.09 |
[Data Structure] Hash Table - 1 | Basic Operations & Chaining Collision Handling Technique (0) | 2025.04.09 |
[Data Structure] Deque (ADT) (0) | 2025.04.02 |
[Data Structure] Circular Queue (ADT) (0) | 2025.04.02 |