Pattern Extraction Algorithm