An Efficient and Simplest Algorithm for Generating Diagrams