Skip to content

Add boundary traversal of binary tree #5639

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

Merged
merged 7 commits into from
Oct 9, 2024
Merged

Conversation

xuyang471
Copy link
Contributor

This PR implements the boundary traversal algorithm for a binary tree as requested in the related issue. The boundary traversal is performed in three parts:

Left Boundary: Traverses the left boundary of the tree, excluding leaf nodes.
Leaf Nodes: Collects all leaf nodes from left to right.
Right Boundary: Traverses the right boundary of the tree, excluding leaf nodes, and adds the nodes in reverse order to ensure correct boundary order.
Both time complexity and space complexity of this implementation are O(n), where n is the number of nodes in the binary tree.

The boundary traversal is performed both iteratively and recursively, and edge cases such as single-node trees and trees without left or right subtrees are handled appropriately.
All methods in the test class passed the test.

Both time complexity and space complexity are O(n)
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.58%. Comparing base (f170078) to head (46bdd25).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5639      +/-   ##
============================================
+ Coverage     59.42%   59.58%   +0.16%     
- Complexity     3808     3847      +39     
============================================
  Files           558      559       +1     
  Lines         15949    16015      +66     
  Branches       3048     3073      +25     
============================================
+ Hits           9477     9543      +66     
  Misses         6069     6069              
  Partials        403      403              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) October 9, 2024 19:48
@siriak siriak merged commit 48c65e4 into TheAlgorithms:master Oct 9, 2024
6 checks passed
Chiefpatwal pushed a commit to Chiefpatwal/Java_os that referenced this pull request Oct 18, 2024
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.

3 participants