grid algorithms