expence algoritm