0401 A day with a bit of thought
🖥️ Implemented the Depth-First Search Algorithm
def dfs(matrix, node):
stack = [node]
visited = []
while stack:
current = stack.pop()
if current not in visited:
visited.append(current)
for i, val in enumerate(matrix[current]):
if val == 1:
stack.append(i)
return visited
🖥️ Implemented the N-Queens Algorithm
def dfs_n_queens(n):
if n < 1:
return []
solutions = []
stack = [[]]
while stack:
current = stack.pop(0)
if len(current) == n:
solutions.append(current)
else:
for col in range(n):
if is_valid(current, col):
stack.append(current + [col])
return solutions
def is_valid(current, col):
for row, c in enumerate(current):
if col == c or abs(col - c) == abs(len(current) - row):
return False
return True
📖 Started reading Wonder
🖥️ Finished Graphs and Trees Review and Graphs and Trees Quiz 【18/20】
🖱️ Did some work
🏄♀️ Read some blog posts