Generic Algorithm Implementation