code written for leaning Algorithm