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: Add Morris In-Order Traversal to BinaryTreeTraversal #627

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

asmit27rai
Copy link

Description

This PR adds the Morris In-Order Traversal algorithm to the BinaryTreeTraversal class. 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.

Changes

  1. C++ Backend:

    • Implemented the morris_in_order_traversal method in the C++ backend.
    • Exposed the method to Python using PyMethodDef.
  2. Python Binding:

    • Updated the Python binding to include the morris_in_order_traversal method.
  3. Unit Tests:

    • Added unit tests for Morris Traversal in the test suite.
    • Verified compatibility with both Python and C++ backends.

- Implemented `morris_in_order_traversal` method in the C++ backend.
- Exposed the method to Python via `PyMethodDef`.
- Added unit tests for Morris Traversal in the test suite.
- Verified compatibility with both Python and C++ backends.
predecessor_node->right = node;
current = PyLong_AsLong(current_node->left);
} else {
// Revert the changes made to the tree
Copy link
Member

Choose a reason for hiding this comment

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

Add a test to make sure that the tree as it is after performing Morris in order traversal.

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