We don’t fully understand exactly how memories are stored in the brain, nor how exactly something like the formation of an organ (liver, brain) is “encoded” in the DNA, but in theory, the answer to your question is a memory (the instinct) is hard-encoded in the brain of the animal, and all their offspring have DNA to re-build the animal’s neurons / brain to INCLUDE that memory / instinct.
Like, we have portions of the brain and spinal cord that deal with reflexes, emotions, and things like flight or fight response. These would be what I call the “hard coded” brain regions.
Latest Answers