Amazon interview question

How does grep work internally?