Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
breadth_first_ffor_each
  • Loading branch information
Hunter315 committed Jan 25, 2019
commit 73a2aeb05741ee2774ee0584862af844e29324a3
8 changes: 4 additions & 4 deletions Data_Structures_Answers.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Add your answers to the questions below.

1. What is the runtime complexity of your `depth_first_for_each` method?

O(n) , it runs through each node
2. What is the space complexity of your `depth_first_for_each` function?

O(n)
3. What is the runtime complexity of your `breadth_first_for_each` method?

O(n)
4. What is the space complexity of your `breadth_first_for_each` method?

O(n)

5. What is the runtime complexity of the provided code in `names.py`?

Expand Down
10 changes: 9 additions & 1 deletion search/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ def depth_first_for_each(self, cb):


def breadth_first_for_each(self, cb):
pass
nodes = [self]
while len(nodes) > 0:
current = nodes.pop(0)
cb(current.value)
if current.left != None:
nodes.append(current.left)
if current.right != None:
nodes.append(current.right)


def insert(self, value):
new_tree = BinarySearchTree(value)
Expand Down