Skip to content

Commit b0d0de3

Browse files
committed
added graphs and trees in data structures
1 parent 1fa28e2 commit b0d0de3

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 5. Graphs
2+
A **Graph** is a collection of vertices (nodes) and edges (connections between nodes) representing networks.
3+
4+
### Key Characteristics
5+
- **Directed** vs **Undirected**: Directed graphs have edges with direction.
6+
- **Weighted** vs **Unweighted**: Weighted graphs assign values to edges.
7+
8+
### Common Representations
9+
- **Adjacency Matrix**: A 2D array where cells indicate edge presence.
10+
- Space Complexity: \(O(V^2)\)
11+
- **Adjacency List**: Each vertex has a list of adjacent vertices.
12+
- Space Complexity: \(O(V + E)\)
13+
14+
### Common Operations
15+
- **Traversal**:
16+
- **Breadth-First Search (BFS)**: Level-order traversal, useful for finding shortest paths in unweighted graphs.
17+
- **Depth-First Search (DFS)**: Visits nodes as deep as possible before backtracking, useful for pathfinding.
18+
- **Shortest Path Algorithms**:
19+
- **Dijkstra's Algorithm**: Finds shortest paths from a single source in a weighted graph.
20+
- **Floyd-Warshall**: All-pairs shortest paths.
21+
- **Minimum Spanning Tree (MST)**:
22+
- **Kruskal's and Prim's Algorithms**: Find the minimum cost to connect all nodes in a weighted graph.
23+
24+
### Applications
25+
- **Networks**: Routing algorithms in communication networks.
26+
- **Social Networks**: Representing and analyzing relationships.
27+
- **Web Crawling**: Link structure of websites.
28+
- **Pathfinding**: Navigation systems and game AI.
29+
- **Scheduling**: Task scheduling with dependencies.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## 4. Trees
2+
A **Tree** is a hierarchical data structure consisting of nodes with a parent-child relationship. It starts with a **root** node and expands into subtrees of children, representing various hierarchical levels.
3+
4+
### Key Characteristics
5+
- Each node has data and links to child nodes.
6+
- Commonly represented as a **rooted tree** with a single root node.
7+
8+
### Types of Trees
9+
- **Binary Tree**: Each node has at most two children.
10+
- **Binary Search Tree (BST)**: A binary tree with the left child <= root <= right child.
11+
- **Balanced Trees**: Trees like AVL, Red-Black Trees keep balance for efficient operations.
12+
- **Heap**: A complete binary tree used for priority queues.
13+
- **Trie**: A tree for storing strings, useful in search applications.
14+
- **B-Trees**: Balanced trees used in databases and filesystems.
15+
16+
### Common Operations
17+
- **Insertion**:
18+
- Adds nodes based on tree type (e.g., BST properties).
19+
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced.
20+
- **Deletion**:
21+
- Removes a node while maintaining tree properties.
22+
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced.
23+
- **Traversal**:
24+
- **In-order**: Left, Root, Right (BST sorted order).
25+
- **Pre-order**: Root, Left, Right (used for copying).
26+
- **Post-order**: Left, Right, Root (used for deletion).
27+
- Complexity: \(O(n)\)
28+
- **Searching**:
29+
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced.
30+
31+
### Applications
32+
- **Hierarchical Data Representation**: File systems, organizational structures.
33+
- **Binary Search Trees (BSTs)**: Efficient searching, insertion, and deletion.
34+
- **Priority Queues**: Implemented using heaps.
35+
- **Trie**: Used for autocomplete and dictionary implementations.
36+
- **Databases and Filesystems**: B-trees provide efficient data retrieval.
37+

0 commit comments

Comments
 (0)