Exercise enhances cognitive function and memory by increasing blood flow to the brain, promoting neurogenesis, and improving synaptic plasticity, which supports better learning and memory retention.