Basic implementation for space saving algorithm.