Our brains generalise information, linking and associating related concepts. The process can help us improvise in exams – but only if we’ve had enough sleep