Algorithms, implementation on C#