I have string which is composed of letters. I want to assign each letter a unique number (letters that repeats should have assigned same number as first unique letter occurrence) and plot those numbers on graph. X-axis will represent the particular letters of string (read from left to right) and y-axis will represent the particular value assigned to letter. The problem is that I want to have graph with minimum peaks. String can be long sequence with repeating letters. In other words I need to assign to letters such numbers that will cause that the plot change over time will be minimal.
So basically this is OK:
STRING
123456
But this not, because graph does not grows/decreases continuously and there are peaks e.g. between S-T, T-R, R-I and I-N (actually it fits criteria only for N-G)
STRING
162534
More complicated example: imagine string "STRINGS" and those two possibilities:
##############
# 1s example #
##############
Letter-Number mapping:
######################
STRINGS
6431256
Distances:
##########
S-T:2
T-R:1
R-I:2
I-N:1
N-G:3
G-S:1
Peak changes:
#############
2-1:T
1-2:T
2-1:T
1-3:T
3-1:T
###############
# 2nd example #
###############
Letter-Number mapping:
######################
STRINGS
1356421
Distances:
##########
S-T:2
T-R:2
R-I:1
I-N:2
N-G:2
G-S:1
Peak changes:
#############
2-2:F
2-1:T
1-2:T
2-2:F
2-1:T
Then the winner is 2nd example because it's maximum distance is less than the maximum distance in 1st example. I can imagine situations where both max distances can be same then the criteria should be the peak changes. In this case 2nd also beats 1st (F - does not change, T - change) because 1st is always changing and 2nd does not change in 2/5 cases
1st: TTTTT
vs
2nd: TFTFT
Is there any theory related to this? Is this even CS theory or some genetic algorithm or what problem set is this? Some library that already does this would be fine e.g. for python, perl etc.
PS: Sorry but I did not know which tags or what title describe this problem the best.