Implementing various algorithms