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

feat: Morris Traversal for In-Order Traversal #626

Open
asmit27rai opened this issue Mar 11, 2025 · 2 comments
Open

feat: Morris Traversal for In-Order Traversal #626

asmit27rai opened this issue Mar 11, 2025 · 2 comments

Comments

@asmit27rai
Copy link

Implement Morris Traversal for In-Order Traversal

Description

Morris Traversal is a space-efficient algorithm for performing in-order traversal of a binary tree without using recursion or a stack. It achieves O(1) space complexity by temporarily modifying the tree structure using threaded binary trees.

Tasks

  1. Implement Morris Traversal for in-order traversal.
  2. Add unit tests to verify the correctness of the implementation.

References

@AkshitMital
Copy link

Hi @asmit27rai ,

I'm currently integrating Morris in-order traversal into our binary trees module. Given that Morris traversal is essentially a DFS variant with O(1) space, I’m debating the best design approach. Should I integrate it as an option within the existing depth_first_search method (for example, by adding an order prop value like "morris_inorder") so that it shares the DFS interface, or would it be preferable to implement it as a standalone function with separate test cases?

I'd appreciate your guidance on which approach better fits our code design and testing conventions.

@asmit27rai
Copy link
Author

Hi @asmit27rai ,

I'm currently integrating Morris in-order traversal into our binary trees module. Given that Morris traversal is essentially a DFS variant with O(1) space, I’m debating the best design approach. Should I integrate it as an option within the existing depth_first_search method (for example, by adding an order prop value like "morris_inorder") so that it shares the DFS interface, or would it be preferable to implement it as a standalone function with separate test cases?

I'd appreciate your guidance on which approach better fits our code design and testing conventions.

Morris in-order traversal should be standalone to keep DFS clean, avoid modifying trees within shared logic, and allow targeted testing. Its unique threading mechanism makes separate implementation more readable and maintainable.

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

No branches or pull requests

2 participants