generalized algorithm to determine the topics