Norvig algorithm implementation