Higher order associative memories and their optical implementations