Dhaka Power Distribution Company Limited
Post: Technical (Computer technology)
Subject code: 155; Mark: 80
#include
int main() {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
printf(" ");
}
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
The hash function is given as h(k)=k mod 13.
The table size is 13, meaning we have indices from 0 to 12.
Step-by-Step Insertion Process
Key: 10
Hash value: h(10) = 10 mod 13 = 10. Insert 10 at index 10.
Key: 3
Hash value: h(3) = 3 mod 13 = 3. Insert 3 at index 3.
Key: 6
Hash value: h(6) = 6 mod 13 = 6. Insert 6 at index 6.
Key: 16
Hash value: h(16) = 16 mod 13 = 3. Index 3 is occupied. Use linear probing and insert 16 at index 4.
Key: 17
Hash value: h(17) = 17 mod 13 = 4. Index 4 is occupied. Use linear probing and insert 17 at index 5.
Key: 19
Hash value: h(19) = 19 mod 13 = 6. Index 6 is occupied. Use linear probing and insert 19 at index 7.
Final Hash Table
| Index | Value |
|---|---|
| 0 | – |
| 1 | – |
| 2 | – |
| 3 | 3 |
| 4 | 16 |
| 5 | 17 |
| 6 | 6 |
| 7 | 19 |
| 8 | – |
| 9 | – |
| 10 | 10 |
| 11 | – |
| 12 | – |
Summary
The final hash table after inserting all keys using linear probing is as follows:
