Algorithm and pseudo code written.