Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afa-farkhod/binary-search-tree
Binary Search Tree, AVL Tree, test and visualize
https://github.com/afa-farkhod/binary-search-tree
avl-tree binary-search-tree java javafx javafx-application
Last synced: about 1 month ago
JSON representation
Binary Search Tree, AVL Tree, test and visualize
- Host: GitHub
- URL: https://github.com/afa-farkhod/binary-search-tree
- Owner: afa-farkhod
- License: mit
- Created: 2023-04-17T04:38:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-01T08:52:56.000Z (over 1 year ago)
- Last Synced: 2024-04-24T11:08:02.550Z (9 months ago)
- Topics: avl-tree, binary-search-tree, java, javafx, javafx-application
- Language: Java
- Homepage: https://en.wikipedia.org/wiki/Binary_search_tree
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Binary-Search-Tree](https://en.wikipedia.org/wiki/Binary_search_tree)
### Binary Search Tree, AVL Tree, test and visualizeFollowing repo first builds the Binary Search Tree `BST.java` which includes `AbstractTree.java`, `Tree.interface`. Then in the `TestBST.java` checks the previously given classes.
- A tree is a classic data structure with many important applications. A tree provides a hierarchical organization in which data are stored in the nodes. A binary search tree can be implemented using a linked structure. Recall that lists, stacks, and queues are linear structures that consist of a sequence of elements. A binary tree is a hierarchical structure. It either is empty or consists of an element, called the root, and two distinct binary trees, called the left subtree and right subtree, either or both of which may be empty.
- The `length` of a path is the number of the edges in the path. The `depth` of a node is the length of the path from the root to the node. The set of all nodes at a given depth is sometimes called a `level` of the tree. `Siblings` are nodes that share the same parent node. The root of a left (right) subtree of a node is called a `left(right) child` of the node.
- A node without children is called a `leaf`. The height of a nonempty tree is the length of the path from the root node to its furthest leaf. The `height` of a tree that contains a single node is 0. Conventionally, the height of an empty tree is —1. The length of the path from node 60 to 45 is 2. The depth of node 60 is 0, the depth of node 55 is 1, and the depth of node 45 is 2. The height of the tree is 2. Nodes 45 and 57 are siblings. Nodes 45, 57, 67, and 107 are at the same level.
- A special type of binary tree called a `binary search tree` (BST) is often useful. A BST (with no duplicate elements) has the property that for every node in the tree, the value of any node in its left subtree is less than the value of the node, and the value of any node in its right subtree is greater than the value of the node.
- Following is the demo run of `TestBST.java`:
*[AVL Tree](https://en.wikipedia.org/wiki/AVL_tree)*
------------------- AVL Tree is a balanced binary search tree. The search, insertion, and deletion times for a binary tree depend on the height of the tree. In the worst case, the height is O(n). If a tree is perfectly balanced–i.e., a complete binary tree—its height is log n. To maintain a well-balanced tree, the heights of every node’s two subtrees should be the same. AVL trees are well balanced. AVL trees were invented in 1962 by two Russian computer scientists, G. M. Adelson-Velsky and E. M. Landis (hence the name AVL).
- In an AVL tree, the difference between the heights of every node’s two subtrees is 0 or 1. It is fact that the maximum height of an AVL tree is O(log n). The process for inserting or deleting an element in an AVL tree is the same as in a regular binary search tree, except that you may have to rebalance the tree after an insertion or deletion operation.
- The balance factor of a node is the height of its right subtree minus the height of its left subtree. A node is said to be balanced if its balance factor is -1, 0, or 1. A node is considered left-heavy if its balance factor is -1, and right-heavy if its balance factor is +1.
- Since an AVL tree is a binary search tree, AVLTree is designed as a subclass of BST. An AVL tree is a binary tree, so we can define the AVLTree class to extend the BST class, as shown in the following UML diagram:
- AVL Tree was implemented in `AVLTree.java` and was successfully tested in `TestAVLTree.java` source codes which are located in side the `BinarySearchTree` folder. Following is the test demo run: