Skip to content

Commit 375c84e

Browse files
authored
Create Readme.md
1 parent 67f694c commit 375c84e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Hash/Linear Probing/Readme.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Linear Probing in Hashing
2+
3+
Linear Probing is a collision resolution technique used in open addressing to resolve hash collisions. When a collision occurs, linear probing checks the next available slot in a sequential manner (i.e., it moves linearly through the hash table until an empty slot is found).
4+
5+
<p align="center">
6+
<img src="https://media.geeksforgeeks.org/wp-content/uploads/Linear-Probing-1-1.jpg" alt="Linear Probing in Hashing">
7+
</p>
8+
9+
### Time and Space Complexity
10+
11+
| **Operation** | **Average Case** | **Worst Case** |
12+
|--------------------|------------------|----------------|
13+
| **Search** | O(1) | O(n) |
14+
| **Insert** | O(1) | O(n) |
15+
| **Delete** | O(1) | O(n) |
16+
17+
### Explanation
18+
19+
- **Search**: In linear probing, the search operation can be very efficient if the load factor is low. However, if many slots are occupied, it might take longer, resulting in O(n) time complexity in the worst case.
20+
21+
- **Insert**: Insertions are generally efficient with linear probing, but in cases where the hash table is nearing its capacity, insertions might degrade to O(n) as the algorithm will need to probe multiple slots to find an available one.
22+
23+
- **Delete**: Deletion works similarly to insertion. In cases of full tables or long chains of collisions, the time complexity may degrade to O(n).
24+
25+
### Space Complexity
26+
27+
The space complexity of linear probing is O(n), where n is the number of elements in the hash table. This is because the space is determined by the size of the hash table itself, and additional space is not required beyond the table.

0 commit comments

Comments
 (0)