Implementation of liu algoritm