Binary Search Trees/ADT: Difference between revisions
From charlesreid1
(Created page with "See Trees/ADT or Binary Trees/ADT") |
m (Replacing charlesreid1.com:3000 with git.charlesreid1.com) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
See [[Trees/ADT]] or [[Binary Trees/ADT]] | This page covers an abstract data type (or, a generic interface for a data container) for binary search trees. These are trees (directed acyclic graphs) that follow a particular convention or interface, and provide certain basic functions. See [[Trees/ADT]] or [[Binary Trees/ADT]] for other, related tree-based abstract data types. | ||
See also BinarySearchTree class here: https://git.charlesreid1.com/cs/java/src/master/trees/search-trees/Weiss.java | |||
or LinkedBinTree here: https://git.charlesreid1.com/cs/java/src/master/trees/LinkedBinTree.java | |||
==Trees== | |||
Binary trees should follow the basic tree ADT and implement: | |||
* size | |||
* isempty | |||
Further: | |||
* iterable | |||
* depth | |||
* height | |||
Utility methods (confusing, b/c using Tree, but checking Node...) | |||
* isInternal | |||
* isExternal | |||
* isLeaf | |||
* isRoot | |||
* parent | |||
* children | |||
* numberOfChildren | |||
Trees: | |||
* allPositions | |||
* iterator | |||
Some of these can be left out, particularly in a trimmed-down binary tree. | |||
==Binary Trees== | |||
The binary tree implementation can replace the children functionality with a left and right. See [[Binary_Trees/ADT]], which we follow here. | |||
Node class provides two methods to access two children: | |||
* left/getLeft | |||
* right/getRight | |||
Additional: | |||
* sibling | |||
* parent | |||
Support iteration: | |||
* positions() should return all positions in tree | |||
* iter() should make it iterable | |||
==Trimming Down== | |||
To really trim things down, our binary search tree only implements a few methods, so we can focus on the actual search tree organization. | |||
The minimal methods for a binary search tree are: | |||
* insert | |||
* remove | |||
* contains/find | |||
Optionally: | |||
* findMin/findMax | |||
These are "easiest" to implement recursively (and usually, easiest to handle the empty case separately.) | |||
==Flags== | |||
{{TreesFlag}} | |||
[[Category:Trees]] | |||
[[Category:ADT]] | |||
[[Category:Binary Trees]] | |||
Latest revision as of 03:18, 9 October 2019
This page covers an abstract data type (or, a generic interface for a data container) for binary search trees. These are trees (directed acyclic graphs) that follow a particular convention or interface, and provide certain basic functions. See Trees/ADT or Binary Trees/ADT for other, related tree-based abstract data types.
See also BinarySearchTree class here: https://git.charlesreid1.com/cs/java/src/master/trees/search-trees/Weiss.java
or LinkedBinTree here: https://git.charlesreid1.com/cs/java/src/master/trees/LinkedBinTree.java
Trees
Binary trees should follow the basic tree ADT and implement:
- size
- isempty
Further:
- iterable
- depth
- height
Utility methods (confusing, b/c using Tree, but checking Node...)
- isInternal
- isExternal
- isLeaf
- isRoot
- parent
- children
- numberOfChildren
Trees:
- allPositions
- iterator
Some of these can be left out, particularly in a trimmed-down binary tree.
Binary Trees
The binary tree implementation can replace the children functionality with a left and right. See Binary_Trees/ADT, which we follow here.
Node class provides two methods to access two children:
- left/getLeft
- right/getRight
Additional:
- sibling
- parent
Support iteration:
- positions() should return all positions in tree
- iter() should make it iterable
Trimming Down
To really trim things down, our binary search tree only implements a few methods, so we can focus on the actual search tree organization.
The minimal methods for a binary search tree are:
- insert
- remove
- contains/find
Optionally:
- findMin/findMax
These are "easiest" to implement recursively (and usually, easiest to handle the empty case separately.)
Flags
| Trees Part of Computer Science Notes
Series on Data Structures Abstract data type: Trees/ADT Concrete implementations: Trees/LinkedTree · Trees/ArrayTree · SimpleTree
Tree Traversal Preorder traversal: Trees/Preorder Postorder traversal: Trees/Postorder In-Order traversal: Binary Trees/Inorder Breadth-First Search: BFS Breadth-First Traversal: BFT Depth-First Search: DFS Depth-First Traversal: DFT OOP Principles for Traversal: Tree Traversal/OOP · Tree Traversal/Traversal Method Template Tree operations: Trees/Operations Performance · Trees/Removal
Tree Applications Finding Minimum in Log N Time: Tree/LogN Min Search
Abstract data type: Binary Trees/ADT Concrete implementations: Binary Trees/LinkedBinTree · Binary Trees/ArrayBinTree Binary Trees/Cheat Sheet · Binary Trees/OOP · Binary Trees/Implementation Notes
|