For a simple XML doc, how to find number of possible arrangements of elements (i.e open and close tags) when given maximum number of tags ?
Let me rephrase the question by example, we have a set T{O,C} (*assume O: open tag, C: close tag). The grammar is same as for any Well formed XML Doc, for every 'O' (open tag) there must be a C (close tag) and it must not appear before its corresponding open tag.
Given maximum number of tags is 6. The possible arrangements could be
- O,O,O,C,C,C
- O,O,C,C,O,C
- O,C,O,C,O,C
- O,C,O,O,C,C etc.
So
- How I can find the number of such possible arrangements for a given length of String/tags n.
- How I can find the number of such possible arrangements, when a sub-string is given for string of length n.
example n = 6, sub-string : OO
- O,O,O,C,C,C
- O,O,O,C,C,C ( 1 & 2 can be counted as one arrangement)
- O,O,C,C,O,C
- O,C,O,O,C,C etc.
(* OCOCOC cannot be counted here as it doesn't have substring OO)
Thanks in advance.
Edit: The question might be better understood by taking open and close brackets. OOCC => (()) OCOCOC => ()()()