In this paper, a novel frame-based algorithm called recursive alignment(RA) for query-by-humming(QBH) application is presented. Compared with other approaches, RA optimizes melody alignment problems in a top-down fashion which is more capable of capturing longdistance information in human singing. Three RA variations which run much faster at the expense of less accuracy are presented, and they can be used as filters of QBH systems. A QBH system built upon RA and its variations is also described briefly. The experiment results show that the proposed algorithm compares favorably with other methods we have implemented.