There were a few inspirations for this approach, including the music of They Might Be Giants and Tom Lehrer. In particular
There Are No Electrons by Kenn Amdahl was a major inspiration in terms showing of how complex technical subjects could be explained through amusing stories. The book explains the details of electronics as though little green men are running through the wires.
As for my own writing, I started writing short stories in my high school chemistry class and giving them to other students. They were fables that tried to explain concepts such as bonds, orbitals, etc. The other students liked them and even requested the occasional story for specific concepts. Years later I started writing these stories for computer science, putting them on the Computational Fairy Tales blog (
http://computationaltales.blogspot.com). Eventually I compiled these into books: Computational Fairy Tales and Best Practices of Spell Design. The CS Detective is an evolution of this work, starting with a specific set of concepts (search algorithms) and a single overall story.