https://github.com/astrapi69/tree-api
Provide an api for trees
https://github.com/astrapi69/tree-api
Last synced: 4 days ago
JSON representation
Provide an api for trees
- Host: GitHub
- URL: https://github.com/astrapi69/tree-api
- Owner: astrapi69
- License: mit
- Created: 2022-12-23T12:58:53.000Z (about 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-27T16:30:16.000Z (over 1 year ago)
- Last Synced: 2024-10-12T11:14:34.019Z (over 1 year ago)
- Language: Java
- Size: 135 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Overview
[](https://github.com/astrapi69/tree-api/actions/workflows/gradle.yml)
[](https://github.com/astrapi69/tree-api/issues)
[](https://maven-badges.herokuapp.com/maven-central/io.github.astrapi69/tree-api)
[](http://www.javadoc.io/doc/io.github.astrapi69/tree-api)
[](http://opensource.org/licenses/MIT)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8)
[](https://hitsofcode.com/github/astrapi69/tree-api/view?branch=develop)
[](https://github.com/astrapi69/tree-api)
## Tree Data Structure Overview
A **tree** is a hierarchical data structure made up of nodes, starting from a root node and branching out into subnodes.
Each node contains a value and can have multiple children, with the rule that no child points back to the root or shares
any duplicate connections. This structure forms a recursive, non-linear representation of data, ideal for modeling
hierarchical relationships.
**Key Terminology:**
* **Node**: A single element in the tree.
* **Edge**: A connection between two nodes.
* **Root**: The topmost node with no parent.
* **Parent**: A node connected to one or more successors.
* **Child**: A successor node connected to its parent.
* **Leaf**: A node without children.
* **Path**: The sequence of nodes connecting one node to another.
* **Height**: The number of edges between a node and its furthest descendant.
* **Depth**: The number of edges between the root and a specific node.
* **Sibling**: Nodes that share the same parent.
* **Subtree**: A node and all of its descendants.
**Tree Traversal Methods:**
* **Pre-order**: Visit the current node, then recursively traverse its subtrees from left to right.
* **Post-order**: Recursively traverse each subtree from left to right, visiting the current node last.
**Tree Representation Methods:**
1. **Array-of-Pointers**: Each node holds an array of references to its children. This allows quick access to any child
but can be inefficient if many pointers are null.
2. **Leftmost-Child—Right-Sibling**: Each node points to its leftmost child and right sibling, providing an efficient
way to traverse through siblings.
**Expression Trees:**
Expression trees represent mathematical expressions in a structured way, where operators and operands are arranged to
clarify precedence. Traversing this tree using pre-order or post-order traversal helps evaluate or transform the
expressions into infix, prefix, or postfix forms.
**Structural Induction:**
A method for proving the correctness of tree-related algorithms. It involves proving a base case (a tree with a single
node) and then showing the correctness of the recursive case (a tree with subtrees).
## ITree Interface Overview
The `ITree` interface provides a generic structure for representing trees where each node can hold a value of type
`V` and have children of type `T`. This flexible design allows for building complex hierarchical models while keeping
the structure modular and reusable.
### Key Features of the ITree Interface:
* **Node Management**: Add, remove, and manage children of a node.
* **Tree Traversal**: Traverse nodes in pre-order and post-order, ensuring each node is visited systematically.
* **Sibling Navigation**: Access sibling nodes in relation to their parent node.
* **Parent-Child Relationships**: Easily navigate between parent and child nodes, and determine the depth and level of
nodes in the tree.
> Please support this project by simply putting a Github
> Star ⭐
>
> Share this library with friends on Twitter and everywhere else you can
>
> If you love this project
> [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8)
## Note
No animals were harmed in the making of this library.
## License
The source code comes under the liberal MIT License, making tree-api great for all types of applications.
## gradle dependency
Replace the variable ${latestVersion} with the current latest version: [](https://maven-badges.herokuapp.com/maven-central/io.github.astrapi69/tree-api)
You can first define the version in the ext section and add than the following gradle dependency to
your project `build.gradle` if you want to import the core functionality of tree-api:
define version in file gradle.properties
```
treeApiVersion=${latestVersion}
```
or in build.gradle ext area
```
treeApiVersion = "${latestVersion}"
```
then add the dependency to the dependencies area
```
implementation("io.github.astrapi69:tree-api:$treeApiVersion")
```
## Maven dependency
Maven dependency is now on sonatype.
Check out [sonatype repository](https://oss.sonatype.org/index.html#nexus-search;gav~io.github.astrapi69~tree-api~~~) for latest snapshots and releases.
Add the following maven dependency to your project `pom.xml` if you want to import the core
functionality of tree-api:
Then you can add the dependency to your dependencies:
...
${latestVersion}
...
...
...
io.github.astrapi69
tree-api
${tree-api.version}
...
# Donations
This project is kept as an open source product and relies on contributions to remain being
developed. If you like this library, please consider a donation
over paypal:
or over bitcoin(BTC) with this address:
bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy

or over FIO with this address:
FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop

or over Ethereum(ETH) with:
0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D

or over Ethereum Classic(ETC) with:
0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD

or over Dogecoin(DOGE) with:
D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1

or over Monero(XMR) with:
49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw

or over flattr:
or over the donation buttons at the top.
## Semantic Versioning
The versions of tree-api are maintained with the Semantic Versioning guidelines.
Release version numbers will be incremented in the following format:
`..`
For detailed information on versioning you can visit the [wiki page](https://github.com/lightblueseas/mvn-parent-projects/wiki/Semantic-Versioning).
## What can i do to support this project
You can donate or contribute solve issues or pull request. Every support are welcome.
## Want to Help and improve it? ###
The source code for tree-api are on GitHub. Please feel free to fork and send pull requests!
Create your own fork of [astrapi69/tree-api/fork](https://github.com/astrapi69/tree-api/fork)
To share your changes, [submit a pull request](https://github.com/astrapi69/tree-api/pull/new/develop).
Don't forget to add new units tests on your changes.
## Contacting the Developers
Do not hesitate to contact the tree-api developers with your questions, concerns, comments, bug reports, or feature requests.
- Feature requests, questions and bug reports can be reported at the [issues page](https://github.com/astrapi69/tree-api/issues).
## Similar projects
## Credits