algorithms for C#