Bp algorithm (written in c#)