It on the algorithm and the data to be compressed as well, especially in case of lossy compression. The use of "frequent values" is just the technique used only in some, often most primitive algorithms, such as
run-length encoding (
https://en.wikipedia.org/wiki/Run-length_encoding[
^]). The "values" in this case could be any arrays of consecutive bytes of any length, and the lengths are usually limited.
Many algorithms of compression don't use this approach at all. For example, typical audio and video compression algorithms use
wavelet-based approach:
https://en.wikipedia.org/wiki/Wavelet[
^].
A very interesting compression method is based on
fractals:
https://en.wikipedia.org/wiki/Fractal_compression[
^],
https://en.wikipedia.org/wiki/Fractal[
^].
Needless to say, these compression algorithms are quite far from your idea of using of "the frequent values from a file".
This topic is too big and complicated to cover in a Quick Answer. You can start with this overview article:
https://en.wikipedia.org/wiki/Data_compression[
^].
—SA