Hashing With Linear Probing
What is the output when the following program is executed?
public class HashTest {
public static void main(String[] args) {
int[] table = new int[5];
int[] keys = {7, 12, 17, 22};
// Simple hash function with linear probing for collisions: index = key % 5
for (int key : keys) {
int hash = key % 5;
while (table[hash] != 0) {
hash = (hash + 1) % 5;
}
table[hash] = key;
}
for(int i = 0; i < table.length; i++){
System.out.print(table[i] + " ");
}
}
}
A
0 22 7 12 17
B
22 7 12 17 0
C
22 7 12 0 17
D
22 0 7 12 17
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | upadhgau000 | 0 | 1 | - | -10 |
| #2 | angelajxi11 | 0 | 1 | - | -10 |
| #3 | test1111 | 0 | 1 | 0m 03s | -13 |
Items per page:
10
1 – 3 of 3
