-words-
It's called "instinct", not that it changes your argument much.
I think you would enjoy some reading on evolutionary biology, find some books by Ricard Dawkins, specifically I recommend The Ancestors Tale. Also, there are many interesting books on ants that will answer many of your questions, I were going to recommend a specific one but I forgot the name and it's probably to obscure for your local library to have anyway, but search around the net on "Eusocial behaviour" and you'll find loads of stuff!
I'll do that!
I'm a computer sciences person, so I've come up with an analogy I can understand for the "instinct" or "genetic memory" traits of organisms.
It's kind of like being able to understand the pieces of a computer, and having a rough idea of how to operate the thing, but having no idea how the operating system or software is put together. Imagine we had a totally "blank" brain - not even cloned from a human, but built up from scratch by people who have observed the physical structures of brains and wanted to make their own. But then... it doesn't do anything. It just sits there. Without some sort of default loadout, some sort of operating system or software to kick off the learning process, it doesn't do much at all. All animals are born with some sort of this biological software, some sort of pre-programming, and it's hard-coded into their very genetic structure in a way we don't comprehend. We can observe and learn, but imagine a non-computer literate society being given computers with no tools with which to create or deconstruct software... how long would it take them to reverse-engineer programming languages and operating systems to be able to create their own computers? Even given a perfect working model, it's virtually impossible.
That's the challenge we face with instinct... we can observe it, we see it happen, we can study it and make notes... but we're like a non-technological society trying to reverse-engineer a computer system. We'll probably figure it out eventually, but it's no easy thing.
I can see us, in the fairly near future, creating "custom" biological organisms with x arms and y legs and z eyes... but how to program the instincts we want? Custom-made creature memories, instincts, and behaviors that are not a result of whatever DNA we're mixing and matching, but specific to our own needs... it is a difficult proposition until we "crack the code" of biological hardcoding, of the "assembler language" of living beings....