How to write an algorithm in latex (2 methods)

Source: i.ytimg.com