Given flat data like this:
01001, Butter, salted
01002, Butter, whipped, with salt
01145, Butter, without salt
04601, Butter, light, stick, with salt
04602, Butter, light, stick, without salt
What's the best approach to convert into this:
Butter (01001, 01002, 01145, 04601, 04602) -> salted (01001)
-> whipped (01002) -> with salt (01002)
-> without salt (01145)
-> light (04601, 04602) -> stick (04601, 04602) -> with salt (04601)
-> without salt (04602)
I was thinking of recursive sorting first, but I realized there may be a lot of string comparisons to be efficient.