Separate the tree data structure based on the gender
BabyName Tree implementation

recursive query for counting the matching names
iteratively inserting name