The diffraction grating sorts light by frequency, with violet light (the highest frequency of visible light) at one end of the spectrum and red light (the lowest frequency of visible light) at the other.