What @Christine said is true: the probability of seeing a particular string of length x, in a string of length x that consists of random letters and digits, is 1 / (36 ^ x). This is true because, at each position in the string, there are 36 possible characters that could go there, so there will be 36 * ... * 36 = 36^x different strings, all equally likely, and we're just interested in one particular string.
But that doesn't fully answer the question you asked, which was, "What's the probability of seeing 'abcdefghij' in this random string?"
Clearly, if x < 10, then the probability of seeing 'abcdefghij' is zero, since you can't have a length-10 string appear in fewer than 10 characters.
If x = 10, then we're in the case discussed previously: the string we're interested in has the same length as the number of characters available, so the probability is 1 / 36^10.
If x > 10, then it gets a little bit trickier, since our magic substring 'abcdefghij' could start at any position where it has enough room. For example, with x = 11, it could start at either position 1 (and take up characters 1-10) or position 2 (and take up characters 2-11). With x = 12, it could start at positions 1, 2, or 3. In general, for x > 10, there are (x - 10 + 1) positions where the magic substring could start.
Let's consider the case x = 12 for a minute. The probability that the magic length-10 substring starts at a given position is still 1 / 36^10, and any character is allowed in the other positions, so for example, P(magic substring starts at position 1 in a length 12 string) = (1 / 36^10) * 1 * 1, where the 1s represent the fact that any character can appear in positions 11 and 12.
The event "magic substring occurs in a length-12 string", which is what we want the probability of, is the union of three events:
- "magic substring occurs and starts at position 1"
- "magic substring occurs and starts at position 2"
- "magic substring occurs and starts at position 3"
These are disjoint events (since, for example, the magic substring starting at position 1 means that "b" is in position 2, so "abcdefghij" can't start in position 2), and so the probability of the union, i.e. the probability of seeing our length-10 magic substring in a length-12 string of random characters, is the sum of the probabilities of those three events: 3 / 36^10.
For better or worse, this reasoning only holds while our magic substring has length < 2*x. Why? Because these events are no longer disjoint when you have at least twice as many characters in your random string as you do in the substring you're looking for. For example, if you have 20 or more random characters to work with, 'abcdefghij' can appear multiple times. But this becomes a pretty hard problem, and probably wasn't what your teacher was looking for...
Anthony J.
01/01/16