Skip to content

Conversation

@wangjoc
Copy link

@wangjoc wangjoc commented Sep 1, 2020

No description provided.

@wangjoc wangjoc changed the title added in methods Time - Jocelyn Sep 1, 2020
Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done. Take a look at my minor comments, but otherwise excellent work.

Comment on lines +19 to +21
# Time Complexity: O(n)
# Space Complexity: O(1)
def add_help(current, new_node)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 However since you are using recursion the space complexity is O(log n) if the tree is balanced (time as well) and O(n) if the tree is unbalanced.

Comment on lines +36 to +38
# Time Complexity: log(n)
# Space Complexity: O(1)
def help_find(current, key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 However since you are using recursion the space complexity is O(log n) if the tree is balanced (time as well) and O(n) if the tree is unbalanced.

Comment on lines +56 to +58
# Time Complexity: O(n)
# Space Complexity: O(1)
def help_inorder(current)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 However since you are using recursion the space complexity is O(log n) if the tree is balanced and O(n) if the tree is unbalanced.

Comment on lines +71 to +73
# Time Complexity: log(n)
# Space Complexity: O(1)
def help_preorder(current)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 However since you are using recursion the space complexity is O(log n) if the tree is balanced and O(n) if the tree is unbalanced.

Comment on lines +86 to +88
# Time Complexity: log(n)
# Space Complexity: O(1)
def help_postorder(current)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 However since you are using recursion the space complexity is O(log n) if the tree is balanced and O(n) if the tree is unbalanced.

return 0 if current.nil?
left += height_helper(current.left)
right += height_helper(current.right)
num += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just set num to 1 in line 104?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants