1. A method of compressing a sequence of n coefficients by determining a cost-determined sequence of n coefficient indices represented by a cost-determined sequence of (run, index derivative) pairs under a given quantization table and run-index derivative coding distribution, wherein each sequence of (run, index derivative) pairs defines a corresponding sequence of coefficient indices such that each index in the corresponding sequence of coefficient indices is a digital number, the corresponding sequence of coefficient indices includes a plurality of values including a special value, and each (run, index derivative) pair defines a run value representing a number of consecutive indices of the special value, and an index-based value derived from a value of the index following the number of consecutive indices of the special value, the method comprising: (a) using the given quantization table and run-index derivative coding distribution to formulate a cost function for a plurality of possible sequences of (run, index derivative) pairs, wherein the plurality of possible sequences of (run, index derivative) pairs comprises at least one possible sequence of (run, index derivative) pairs wherein the value of at least one index in the corresponding sequence of coefficient indices defined by the at least one possible sequence of (run, index derivative) pairs is neither the value of the corresponding at least one index resulting from quantizing the sequence of n coefficients using the given quantization table nor the special value; (b) applying the cost function to each possible sequence in the plurality of possible sequences of (run, index derivative) pairs to determine an associated cost of each of the plurality of possible sequences of (run, index derivative) pairs; (c) selecting the cost-determined sequence of (run, index derivative) pairs from the plurality of possible sequences of (run, index derivative) pairs based on the associated cost of each of the plurality of possible sequences of (run, index derivative) pairs; and, (d) encoding the cost-determined sequence of (run, index derivative) pairs using entropy coding based on the given run-index derivative coding distribution.