The adoption of hierarchial teaching mode brings a new challege to course scheduling and course elective. In this paper, an algorithm for automatic grouping of hierarchical teaching based on PBIL is proposed. The design of gene structure and the relationships between the optimal function and automatic grouping class constraint is emphasized. Experimental tests on real data show that the proposed algorithm of automatic grouping class can successfully solve the course scheduling problem in the hierarchical teaching mode. The practical application of it has good results.