Discovering Frequent Episodes : Fast Algorithms, Connections With HMMs And Generalizations