I’m having trouble finding a formula that explains the size requirement of my data model.
I will have a list of tags. In the example the tags are simply numbers.
Tags are always sorted and duplicates does not exist.
All possible tag combinations for 3 numbers:
1:2:3
1:2
1:3
2:3
1
2
3
4 numbers:
1:2:3:4
1:2:3
1:2:4
1:3:4
2:3:4
1:2
1:3
1:4
2:3
2:4
3:4
1
2
3
4
Some values I calculated:
1=>1
2=>3
3=>7
4=>15
5=>29
6=>70
How many rows will there be at most (as above) for n tags?
This is a combinatorics problem: you want the sum of the number of ways of choosing ‘1 item from N’ + ‘2 items from N’ + ‘3 items from N’ + … up to ‘N items from N’.
The sum of possible combinations of N from N is 2^N, so the rows in your database will be 2^N-1 (since the empty combination isn’t a valid row).
For a longer explanation of sum of combinations see this post.
You can also think of this in terms of sets — you want the number of subsets of a set of N items (excluding the empty set).