Skip to content

Commit 781a00c

Browse files
authored
Add README for Trees (TheAlgorithms#2422)
1 parent d9f97fd commit 781a00c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

DataStructures/Trees/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Tree
2+
### Description
3+
4+
Tree is a data structure where the data is organized in a hierarchial structure. There should be one root node (which does not have any parent) and all subsequent nodes are represented as children of the root node and its children. If a node has at least one child, it is called `internal` node and nodes with no children are called `leaf` nodes.
5+
6+
### Basic Structure
7+
8+
```
9+
class Tree<E>{
10+
E value;
11+
Tree left;
12+
Tree right;
13+
}
14+
```
15+
16+
This basic structure is for a binary tree where each internal tree has at least one and at most two children. `left` and `right` represent the two children and `value` is the placeholder for data.
17+
18+
19+
### Properties
20+
1. Tree data structure gives the facility to organize data in a hierarchial structure
21+
2. Tree nodes can be inserted in a sorted order which can be used for searching and inserting data in O(logN) time where N is the number of nodes.
22+
23+
### Types of Trees
24+
1. **Binary Search Tree:** A binary tree where the elements are inserted in asorted order. Here the searching can be done in O(logN) time in (depending on the structure)
25+
2. **AVL Tree and Red-Black Tree:** Binary search trees where the height is balanced. Here, searching is guaranteed to be in O(logN) time.
26+
3. **Traversal algorithms:** <br>
27+
a. **BFS:** Breadth-first-search where all the children at each level are traversed at once. <br>
28+
b. **DFS:** Depth-first-search where the first discovered child is traversed first.
29+
4. **MultiWay Search Tree:** Tree in sorted order, but more than two children in each internal node.
30+
5. **Trie:** A character based multiway search tree where words can be retrieved based on their prefix. Useful for implementing prefix based search algorithm.

0 commit comments

Comments
 (0)