```
🔷 LINEAR PROBING VISUALIZER
Hashing • Collision Resolution • Step-by-Step Animation
```
```
📥 Hash Table Configuration
```
```
```
🗂️ Hash Table
🔵 Current Probe
🟡 Collision
🟢 Found
🔴 Deleted
```
📈 Live Statistics
Operation
-
Hash Index
-
Current Index
-
Collisions
0
Probes
0
Enter a value and choose an operation.
```
```
```
📝 Step-by-Step Explanation
1
Linear Probing resolves a collision by checking
the next available position sequentially.
```
🧮 Mathematical Concept
Hash Function:
h(k) = k mod m
If collision occurs:
hi(k) = (h(k) + i) mod m
where:
k = key
m = hash table size
i = probe number
h(k) = k mod m
If collision occurs:
hi(k) = (h(k) + i) mod m
where:
k = key
m = hash table size
i = probe number
```
Example:
Key = 25
Table Size = 10
h(25) = 25 mod 10 = 5
First position = Index 5
If Index 5 is occupied:
Probe 1: (5 + 1) mod 10 = 6
Probe 2: (5 + 2) mod 10 = 7
Probe 3: (5 + 3) mod 10 = 8 ```
```
h(25) = 25 mod 10 = 5
First position = Index 5
If Index 5 is occupied:
Probe 1: (5 + 1) mod 10 = 6
Probe 2: (5 + 2) mod 10 = 7
Probe 3: (5 + 3) mod 10 = 8 ```
```
```
💡 How Linear Probing Works
1
Calculate the hash index using
key mod table size.
2
Check the calculated position.
3
If the position is empty, insert the value.
4
If the position is occupied, a
collision occurs.
5
Move to the next position:
(index + 1) mod table size.
6
Continue until an appropriate position is found.
```
🔢 Worked Example
Table Size = 10
Insert 25:
25 mod 10 = 5
Store 25 at Index 5.
Insert 35:
35 mod 10 = 5
Index 5 is occupied → Collision!
Next index:
(5 + 1) mod 10 = 6
Store 35 at Index 6.
```
Insert 25:
25 mod 10 = 5
Store 25 at Index 5.
Insert 35:
35 mod 10 = 5
Index 5 is occupied → Collision!
Next index:
(5 + 1) mod 10 = 6
Store 35 at Index 6.
```
```
⚖️ Advantages & Disadvantages
+
Advantages:
Simple to implement, requires no linked lists, and provides good cache performance because elements are stored in consecutive locations.
Simple to implement, requires no linked lists, and provides good cache performance because elements are stored in consecutive locations.
−
Disadvantages:
Clustering can occur. As the table becomes full, the number of probes can increase significantly.
Clustering can occur. As the table becomes full, the number of probes can increase significantly.
```
```
⏱️ Complexity
Average Search
O(1)
Average Insert
O(1)
Worst Case
O(n)
No comments:
Post a Comment