I have a recursive algorithm with two nested for loops. I'm trying to figure out what the Big-O time complexity will be.
public Set<Person> getDistinctCombinedPersons(Collection<Person> persons) {
return permutatePersons(new ArrayList(persons), new HashSet<>(persons));
}
private Set<Person> permutatePersons(List<Person> personList, Set<Person> personSet) {
if(personList.isEmpty() {
return personSet;
}
Set<Person> deepCopyPersonSet = new HashSet<>(personSet);
for(Person lPerson : personList) {
for(Person sPerson : deepCopyPersonSet) {
Person uniquePerson = CombinePeople.combine(lPerson, sPerson);
personSet.add(uniquePerson);
}
}
personList.remove(personList.size()-1);
return permutatePersons(personList, personSet);
}
O(n^ n+2).