Algorithm works