I’m solving Big O runtimes but do not feel as though I understand the problem thoroughly enough to answer on my own.
I need to calculate the Big-O runtime for this queens ‘bruteforce’ function, but I’m not sure I have solved it correctly. I thought it could be simply O(n^2) but I am not sure and not confident enough with my current understanding to say that is the correct answer. I’m just looking for some guidance and correction.
def bruteforce(self, row):
if row == self.n:
return self.is_valid(row)
for col in range(self.n):
self.queens[row] = col
if self.bruteforce(row + 1):
return True
self.queens[row] = -1
return False