Amazon Interview Question

How does grep work internally?