The computer algorithm for generating all the possible structural patterns of mechanisms with given degrees of freedom, number of general constraints and number of loops has been developed. First, basic graphs composed of links with three or more kinematic pairs, which represent shapes of loops, are determined and the kinematic graphs are obtained by allocating binary links to some edges of each basic graph. The number of cases to be considered when allocating binary links to the edges decreases by grouping the edges of basic graphs with the same characteristics and consequently, the computation time is well reduced.