Skip to content

Instantly share code, notes, and snippets.

@GEEGABYTE1
Created July 21, 2021 03:43
Show Gist options
  • Save GEEGABYTE1/ad9454719aea5f936112c5049916a487 to your computer and use it in GitHub Desktop.
Save GEEGABYTE1/ad9454719aea5f936112c5049916a487 to your computer and use it in GitHub Desktop.
Max-Depth Solution
from Tree import Tree
from collections import deque
def bfs(root, count=0):
path_queue = deque()
initial_path = [root]
path_queue.appendleft(initial_path)
while path_queue:
if count == 0 or len(path_queue) == 2:
count += 1
current_path = path_queue.pop()
current_node = current_path[-1]
print('Traversing Node with Value: {}'.format(current_node.value))
for child in current_node.children:
new_path = current_path[:]
new_path.append(child)
path_queue.appendleft(new_path)
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment