Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce traverseInOrder time complexity and space complexity #470

Open

Conversation

@stephenkingsley
Copy link

stephenkingsley commented Mar 16, 2020

In this case traverseInOrder use Recursive Approach. We can reduce the time complexity and the space complexity by using Stack.

Recursive Approach

Complexity Analysis

  • Time complexity : O(n). The time complexity is O(n) because the recursive function is T(n)=2⋅T(n/2)+1.
  • Space complexity : The worst case space required is O(n), and in the average case it's O(logn) where n is number of nodes.

Iterating method using Stack

Complexity Analysis

  • Time complexity : O(n).
  • Space complexity : O(n).
…e time complexity and space complexity
@codecov
Copy link

codecov bot commented Mar 16, 2020

Codecov Report

Merging #470 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #470   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          149       149           
  Lines         2612      2616    +4     
  Branches       434       433    -1     
=========================================
+ Hits          2612      2616    +4     
Impacted Files Coverage Δ
src/data-structures/tree/BinaryTreeNode.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba2d8dc...501e537. Read the comment docs.

@stephenkingsley
Copy link
Author

stephenkingsley commented Apr 14, 2020

@trekhleb CC! And could you please give my some advises?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.