Skip to content

Commit 5d697a3

Browse files
authored
Update brain_teasers.md
1 parent ac156ce commit 5d697a3

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

notes/brain_teasers.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -240,41 +240,16 @@ Mastering algorithms is crucial for solving complex programming problems efficie
240240

241241
### Graph Algorithms
242242

243-
- **Breadth-First Search (BFS)**:
244-
245-
- **Uses**: Finding the shortest path in unweighted graphs, level-order traversal.
246-
247-
- **Implementation**: Use a queue to process nodes in a FIFO manner.
248-
249-
- **Depth-First Search (DFS)**:
250-
251-
- **Uses**: Topological sorting, cycle detection, path finding.
252-
253-
- **Implementation**: Use recursion or a stack to explore as deep as possible before backtracking.
254-
255-
- **Dijkstra's Algorithm**:
256-
257-
- **Uses**: Shortest path in weighted graphs with non-negative weights.
258-
259-
- **Implementation**: Use a min-heap to select the next node with the smallest tentative distance.
260-
261-
- **Bellman-Ford Algorithm**:
262-
263-
- **Uses**: Shortest path in graphs with negative weights, detecting negative cycles.
264-
265-
- **Implementation**: Relax all edges \( |V| - 1 \) times, where \( |V| \) is the number of vertices.
266-
267-
- **Floyd-Warshall Algorithm**:
268-
269-
- **Uses**: All pairs shortest paths.
270-
271-
- **Implementation**: Use a 2D matrix to store distances, update distances considering each vertex as an intermediate point.
272-
273-
- **Union-Find Data Structure**:
274-
275-
- **Uses**: Keeping track of disjoint sets, cycle detection in Kruskal's algorithm.
276-
277-
- **Implementation**: Optimize with path compression and union by rank.
243+
Below is a detailed comparison of commonly used graph algorithms:
244+
245+
| **Algorithm/Technique** | **Uses** | **Implementation** |
246+
|---------------------------------|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
247+
| **Breadth-First Search (BFS)** | Finding the shortest path in unweighted graphs, level-order traversal. | Use a queue to process nodes in a First In, First Out (FIFO) manner. |
248+
| **Depth-First Search (DFS)** | Topological sorting, cycle detection, pathfinding. | Use recursion or a stack to explore as deep as possible before backtracking. |
249+
| **Dijkstra's Algorithm** | Shortest path in weighted graphs with non-negative weights. | Use a min-heap (priority queue) to select the next node with the smallest tentative distance. |
250+
| **Bellman-Ford Algorithm** | Shortest path in graphs with negative weights, detecting negative cycles. | Relax all edges V-1 times, where V is the number of vertices. |
251+
| **Floyd-Warshall Algorithm** | All pairs shortest paths. | Use a 2D matrix to store distances, updating distances by considering each vertex as an intermediate point. |
252+
| **Union-Find Data Structure** | Keeping track of disjoint sets, cycle detection in Kruskal's algorithm. | Optimize with path compression and union by rank for efficient merging of sets and lookups. |
278253

279254
## Sorting Algorithms
280255

0 commit comments

Comments
 (0)