Two ways to handle a collision
Both tables have 7 slots and pick a slot the same way: i = hash(k) % 7. For a small whole number, hash(k) is k itself. So key 15 goes to slot 1, because 15 % 7 = 1. No clash yet.
22 % 7 = 1 as well: two keys want slot 1. That is a collision. Chaining simply appends 22 to slot 1's list. Probing finds slot 1 taken, steps right to slot 2 and stores 22 there: 2 probes.
Clusters
3 % 7 = 3, and slot 3 is free in both tables: 1 probe. But in the probing table, slots 1, 2 and 3 are now full side by side. A row of full slots like this is called a cluster.
8 % 7 = 1 again. Chaining adds a third key to slot 1's list. Probing must walk the whole cluster: slots 1, 2 and 3 are full, so 8 lands in slot 4 after 4 probes. The cluster grew.
5 % 7 = 5: free in both tables, 1 probe. All five keys are in. Chaining has lists of 3, 1 and 1. Probing has one cluster, slots 1 to 5, with only slots 0 and 6 still empty.
A new key with hash 1, 2, 3, 4, 5 or 6 ends up in slot 6: try 9, which walks from slot 2. That is 6 chances in 7. Slot 0 catches only hash 0. Long clusters grow fastest: primary clustering.
Expected cost
Finding a stored key repeats its insert. Chaining compares 1, 2, 1, 3, 1 times: 8/5 = 1.6 on average. Probing takes 1, 2, 1, 4, 1 probes: 9/5 = 1.8. Finding 8 walks slots 1 to 4 again.
Search for 29, which is missing (29 % 7 = 1). Chaining checks slot 1's 3 keys and stops. Probing walks to an empty slot: 6 probes. Over all 7 start slots: 5/7 ≈ 0.71 compares against 22/7 ≈ 3.14 probes.
Load factor α = keys ÷ slots, here 5/7. A chaining miss costs about α compares. A linear-probing miss costs about ½(1 + 1/(1 − α)²) probes: 2.5 at α = ½ but 50.5 at α = 0.9. So probing tables resize before half full.
What happens
;; step 1/9 · two-tables m = 7 slots, h(k) = hash(k) % 7 hash(15) = 15, 15 % 7 = 1 chaining: slot 1 list = [15] probing: slot 1 = 15 (1 probe)
The averages 1/2(1 + 1/(1 − α)) for a hit and 1/2(1 + 1/(1 − α)²) for a miss are Sedgewick and Wayne's Proposition M for linear probing in a large table, assuming the hash spreads keys evenly and independently (uniform hashing). Chaining's miss cost of about α compares, Θ(1 + α) with the hashing, is CLRS chapter 11. A 7-slot table is far too small for these limits, so the figure counts its own exact numbers instead. The code is real Python 3: chaining uses t = [[] for _ in range(7)], probing uses t = [None] * 7. The probing put assumes at least one slot is empty, or the while loop would never end.