Pattern-based algorithms for Explainable AI