build algorithm from scratch example