Is there always a way to alphabetically name something so that it is ordered between two given places in the list?

What I mean ... Let's say you have files named 4A, 4B and 4C. If I want to make a file that, if sorted alphabetically, will fit between 4A and 4B?

+3


source to share


1 answer


The critical word in the question is "always". This means (I assume) "for any set of filenames (strings)". Not just two-letter ones.

I answered yes at first, because it seems like you can always add a letter to create a line between any two given lines.

However, the answer is actually no.

In this "alphanumeric" sequence, there is indeed a "next item" for each item, and you cannot put something between the item and its next item.

For example, the next item after "4a" is "4a0"

No letters in alphabetical order between "4a" and "4a0"




Addition:

The question assumes that the alphabet for file names is "alphanumeric", which means [0..9a..zA..Z], and the sorting must be alphanumeric (as usually defined). In this case, the answer (as stated above) is "No".

However, as described at https://math.stackexchange.com/questions/978970/is-there-a-sequence-of-strings-where-there-is-always-an-element-between-any-two/978980 # 978980 , if you control how the strings are sorted (filenames), you can define a sorting method that ensures that there is always a string that can go between the other two.

If, in addition, you manipulate the alphabet (so that you can only select filenames with [0..9] in the name, for example), then it becomes quite simple.

+4


source







All Articles