data comparison recursive function