Cognitive flexibility is the ability to shift between different thoughts, ideas, or mental sets in response to changing situational demands. It allows individuals to adapt their thinking and behavior to novel or unpredictable circumstances, rather than being stuck in a single, rigid mindset.