We represent the masses in a spectrum as a sequence Spectrum of integers $\textit{s}_\text{1}, \ldots, \textit{s}_\textit{m}$ in increasing order, where $\textit{s}_\text{1}$ is zero and $\textit{s}_\textit{m}$ is the total mass of the (unknown) peptide. We define a labeled graph Graph(Spectrum) by forming a node for each element of Spectrum, then connecting nodes $s_i$ and $s_j$ by a directed edge labeled by an amino acid $a$ if $s_j - s_i$ is equal to the mass of $a$. As we assumed when sequencing antibiotics, we do not distinguish between amino acids having the same integer masses (i.e., the pairs K/Q and I/L).
Spectrum Graph Construction
Construct the graph of a spectrum.
Given: A space-delimited list of integers Spectrum.
Return:Graph(Spectrum).
Note: In this chapter, all dataset problems implicitly use the standard integer-valued mass table for the regular twenty amino acids. Examples sometimes use imaginary amino acids X and Z having respective integer masses 4 and 5.