Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewjh271/binary_search_tree
https://github.com/andrewjh271/binary_search_tree
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/andrewjh271/binary_search_tree
- Owner: andrewjh271
- Created: 2020-06-01T21:37:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-04T03:34:14.000Z (over 4 years ago)
- Last Synced: 2024-12-09T09:54:22.587Z (27 days ago)
- Language: Ruby
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Binary Search Tree
Created as part of The Odin Project Curriculum.
### Functionality
- On instantiation of Tree class, `build_tree` creates a balanced binary search tree from an ordered array
- Duplicate values are not allowed — they will be removed during instantiation and `insert` will not accept them
- `display` can display a tree of up to 5 levels
- Basic operations: `insert`, `delete`, `find`
- Traversals: `level_order`, `preorder`, `inorder`, `postorder`
- `depth` returns the number of levels below a given node, or below root if no argument is given
- Other methods: `balanced?`, `rebalance`### Thoughts
After finishing the initial functionality, I made a real effort to refactor my code. Most notably, I was able to make my recursive methods much more succinct, and I felt it was very valuable going through that process.
I learned a bit about allowing blocks inside my methods. I first used `yield`, but this isn't possible inside `define_method`, so switched to using `block.call`.
One "secret" I had to uncover for `define_method` was using `self` to recursively call the method being defined.
-Andrew Hayhurst