Inside the Mind of Machines: Induction Heads, Grokking, and Memorization