How many ways can an $n$-length string containing $k$ groups be ordered s.t. no adjacent same-group objects occur?

25 Views Asked by At

The string consists of $n$ objects categorized into $k$ attributes such that no two objects yielding the same defined attribute are positioned next to eachother. I am interested both in terminal strings and circuits (loops to itself) and possible generalizations to higher dimensions with and without looping, and also in cases allowing objects to yield more than one attribute (if this would change the final number of variations one way or the other).

For the simple case of a string of 5 objects in 3 distinct categories that don't loop, I count five (simply moving placement of the lesser-enumerated category): ⟨a,b,c,a,b⟩, ⟨a,b,a,c,b⟩, ⟨a,b,a,b,c⟩, ⟨c,a,b,a,b⟩, ⟨a,c,b,a,b⟩, so $f(5,3)=5$. If instead only 2 distinct categories, then just one: ⟨a,b,a,b,a⟩ (not counting ⟨b,a,b,a,b⟩ for $k=2$ for same reason not counting ⟨c,b,a,c,b⟩ for $k=3$ under odd $n$: isomorphic to canonical alphabetical version). Notice that if the odd-lengthed string looped then the there must be at least 3 categories, and with further restriction on confining the cardinality of each category to within 1 of eachother then it would maybe be.. at least equal to or greater than half (though not evident till higher $n$)?

What would the formula be for function $f(n,k)$ under simple rules (distinct categorization of objects, non-permutative, one category per object, non-looping, no restrictions on minimal number of objects to an extant category)? What about variations (mostly I think reducing the maximal count, except if permuting such that isomorphisms are considered distinct)?