Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tree topics in javascript #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions trees/Example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tree Examples

## 1. Binary Tree

### Example
1
/ \
2 3
/\5
4
107 changes: 107 additions & 0 deletions trees/Operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

### Operations
- **Inorder Traversal**: 4, 2, 5, 1, 3
- **Preorder Traversal**: 1, 2, 4, 5, 3
- **Postorder Traversal**: 4, 5, 2, 3, 1

## 2. Binary Search Tree (BST)

### Example
10
/ \
5 15
/\
7
3 \
20


### Operations
- **Insertion**: Adding 6 to the BST
- **Search**: Finding 7 in the BST
- **Deletion**: Removing 15 from the BST


### Operations
- **Insertion**: Adding the word "cat" to the Trie
- **Search**: Checking if "rat" exists in the Trie
- **Deletion**: Removing the word "cat"

## 8. Segment Trees
- **Definition**: A binary tree used for storing intervals or segments and allows querying the intervals efficiently.
- **Operations**:
- **Query**: Finding information over a range of indices.
- **Update**: Modifying elements in the array.

### Example (Range Minimum Query)
- **Array**: [2, 3, 1, 4, 5]
- **Segment Tree**:

[1]
/ \
[1] [4]
/ \ / \
[2] [1] [4] [5]



### Operations
- **Query**: Minimum value in range [1, 3]
- **Update**: Change value at index 2 to 6

## 9. Fenwick Trees (Binary Indexed Trees)
- **Definition**: A data structure that provides efficient methods for cumulative frequency tables.
- **Operations**:
- **Update**: Adding a value to an element.
- **Query**: Calculating prefix sums.

### Example
- **Array**: [3, 2, 4, 5, 1]
- **Fenwick Tree**:
[3]
/ \
[5] [4]
/ \ / \
[3] [4] [5] [1]


### Operations
- **Update**: Add 3 to the value at index 2
- **Query**: Sum of elements from index 1 to 3

## 10. N-ary Trees
- **Definition**: A tree in which a node can have at most N children.
- **Properties**: Generalizes binary trees.

### Example
1
/|\
2 3 4
/ \
5 6

### Operations
- **Traversal**: Depth-First Search (DFS)
- **Traversal**: Breadth-First Search (BFS)

## 11. Tree Traversal Algorithms
- **Depth-First Search (DFS)**:
- **Inorder**: Traverses left subtree, visits node, traverses right subtree.
- **Preorder**: Visits node, traverses left subtree, traverses right subtree.
- **Postorder**: Traverses left subtree, traverses right subtree, visits node.
- **Breadth-First Search (BFS)**: Traverses level by level from the root.

## 12. Applications of Trees
- **Expression Trees**: Used in compilers to parse mathematical expressions.
- **Syntax Trees**: Represents the structure of a program or expression.
- **Decision Trees**: Used in machine learning for classification and regression.

## 13. Advanced Topics
- **Suffix Trees**: Used for efficient string matching and substring search.
- **Generalized Trees**: Extensions of traditional tree structures.
- **Tree Isomorphism**: Determining if two trees are structurally identical.

## 14. Complexity Analysis
- **Time Complexity**: Measures the time required for operations in terms of input size.
- **Space Complexity**: Measures the memory used by the tree data structure.

96 changes: 96 additions & 0 deletions trees/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Trees in Data Structures

## 1. Introduction to Trees
- Definition and Terminology
- Types of Trees

## 2. Binary Trees
- Definition
- Properties
- Types of Binary Trees
- Full Binary Tree
- Complete Binary Tree
- Perfect Binary Tree
- Balanced Binary Tree
- Degenerate (or pathological) Tree

## 3. Binary Search Trees (BST)
- Definition
- Properties
- Operations
- Insertion
- Deletion
- Search
- Traversal (Inorder, Preorder, Postorder)

## 4. AVL Trees
- Definition
- Rotations
- Single Rotation
- Double Rotation
- Insertion
- Deletion
- Balancing

## 5. Red-Black Trees
- Definition
- Properties
- Rotations
- Left Rotation
- Right Rotation
- Insertion
- Deletion
- Balancing

## 6. B-Trees
- Definition
- Properties
- Operations
- Insertion
- Deletion
- Search

## 7. Trie (Prefix Tree)
- Definition
- Operations
- Insertion
- Search
- Deletion

## 8. Segment Trees
- Definition
- Operations
- Query
- Update

## 9. Fenwick Trees (Binary Indexed Trees)
- Definition
- Operations
- Update
- Query

## 10. N-ary Trees
- Definition
- Properties
- Traversal Methods

## 11. Tree Traversal Algorithms
- Depth-First Search (DFS)
- Inorder
- Preorder
- Postorder
- Breadth-First Search (BFS)

## 12. Applications of Trees
- Expression Trees
- Syntax Trees
- Decision Trees

## 13. Advanced Topics
- Suffix Trees
- Generalized Trees
- Tree Isomorphism

## 14. Complexity Analysis
- Time Complexity
- Space Complexity