SECTION 22 / 31

Use a customer-by-customer table for all 15 pairs

1 min read
Six customers give 6×5/2=15 unordered pairs. Compare only row index i < column index j.
Six customers give 6×5/2=15 unordered pairs. Compare only row index i < column index j.
REAL COURSE DATA · KEYS, COUNTS AND CONNECTIONS

Enumerate the 15 pairs and their distances

Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next key, whether it already exists, and the value that will be stored.

Use indices only as local labels: 1 Abhinav, 2 Akshaya, 3 Ahmed, 4 Srivatsan, 5 Advaith, 6 Vignesh. These are not bill numbers or permanent customer IDs. Hold one row fixed and advance the column; then move to the next row. Rows and columns now represent the SAME customer set, unlike the customer-by-category profile table.

Row / column123456
1—720131016
2——17121719
3———131822
4————1519
5—————10
6——————

Only the upper triangle is stored here. A dash means “not stored in this triangular representation”, not zero distance and not missing source data. The omitted diagonal would be zero; the lower triangle would mirror the upper triangle. The lecturing discussion contains some spoken table slips; these entries are recomputed from the original five-category profiles.

foreach i in [1,2,3,4,5,6] {
    foreach j in [1,2,3,4,5,6] {
        if (i < j) {
            record(i,j,distance(profile[i],profile[j]))
        }
    }
}

Try it yourself

Why is the count 15 rather than 30?

Show explained answer

The 30 ordered non-self comparisons include both A–B and B–A. Each unordered pair is kept once.

Try it yourself

Why exclude i=j?

Show explained answer

It compares a customer with themselves and adds no information about similarity between distinct customers.

Try it yourself

What does the entry row 2, column 4 mean?

Show explained answer

Akshaya versus Srivatsan has Manhattan distance 12 in this five-category row-count representation.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑