implemented Tries algorithm