Skip to content

Add Binary Search Tree implementation in Python#229

Merged
Pradeepsingh61 merged 1 commit intomainfrom
add-python-binary-tree
Oct 1, 2025
Merged

Add Binary Search Tree implementation in Python#229
Pradeepsingh61 merged 1 commit intomainfrom
add-python-binary-tree

Conversation

@Karanjot786
Copy link
Copy Markdown
Collaborator

📝 Description

This PR adds a complete Binary Search Tree (BST) implementation in Python with comprehensive operations and traversal
methods.

📂 Files Added

  • Python/data_structures/trees/binary_search_tree.py

✨ Features

  • TreeNode class: Node structure with value, left, and right pointers
  • Insert operation: Add values to BST maintaining BST property
  • Search operation: Find values efficiently using BST properties
  • Three traversal methods:
    • Inorder (Left → Root → Right) - returns sorted order
    • Preorder (Root → Left → Right)
    • Postorder (Left → Right → Root)
  • Min/Max operations: Find minimum and maximum values
  • Height calculation: Compute tree height
  • Comprehensive test cases: Multiple scenarios demonstrating all operations

📊 Complexity Analysis

  • Insert: O(log n) average, O(n) worst case (unbalanced tree)
  • Search: O(log n) average, O(n) worst case (unbalanced tree)
  • Traversals: O(n) - visit all nodes
  • Space: O(n) for storing n nodes, O(h) recursion stack where h = height

🔑 Key Concepts

  • Binary Search Tree property: left subtree < root < right subtree
  • Recursive insertion and search
  • Tree traversal algorithms
  • Height and min/max operations

✅ Testing

All test cases run successfully demonstrating:

  • Multiple value insertions
  • All three traversal methods
  • Search for existing and non-existing values
  • Min/Max finding
  • Height calculation
  • Multiple BST instances

🎃 Hacktoberfest 2025

This contribution is part of Hacktoberfest 2025. The code follows the repository's structure (Language/Topic/FileName) and
includes proper documentation.

📋 Checklist

  • Code follows repository structure (Python/data_structures/trees/)
  • Proper documentation and comments added
  • Test cases included
  • Time and space complexity documented
  • No user input required (tests run automatically)
  • Code is well-formatted and readable

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 1, 2025

🎉 Welcome to Hacktoberfest 2025, @Karanjot786! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 1, 2025

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

@Pradeepsingh61 Pradeepsingh61 merged commit 9363ed2 into main Oct 1, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants