Implemented all three algorithms