contents: rearrange algo layout structure

This commit is contained in:
Yangshun
2022-04-06 09:47:25 +08:00
parent 0acd6749ca
commit 73dd64f96d
16 changed files with 151 additions and 147 deletions

View File

@ -15,9 +15,19 @@ Graphs are commonly used to model relationship between unordered entities, such
Be familiar with the various graph representations, graph search algorithms and their time and space complexities.
**Graph representations**
## Learning resources
You can be given a list of edges and tasked to build your own graph from the edges to perform a traversal on. The common graph representations are:
- Readings
- [From Theory To Practice: Representing Graphs](https://medium.com/basecs/from-theory-to-practice-representing-graphs-cfd782c5be38), basecs
- [Deep Dive Through A Graph: DFS Traversal](https://medium.com/basecs/deep-dive-through-a-graph-dfs-traversal-8177df5d0f13), basecs
- [Going Broad In A Graph: BFS Traversal](https://medium.com/basecs/going-broad-in-a-graph-bfs-traversal-959bd1a09255), basecs
- Additional (only if you have time)
- [Finding The Shortest Path, With A Little Help From Dijkstra](https://medium.com/basecs/finding-the-shortest-path-with-a-little-help-from-dijkstra-613149fbdc8e), basecs
- [Spinning Around In Cycles With Directed Acyclic Graphs](https://medium.com/basecs/spinning-around-in-cycles-with-directed-acyclic-graphs-a233496d4688), basecs
## Graph representations
You can be given a list of edges and you have to build your own graph from the edges so that you can perform a traversal on. them The common graph representations are:
- Adjacency matrix
- Adjacency list
@ -37,15 +47,10 @@ In algorithm interviews, graphs are commonly given in the input as 2D matrices w
| Breadth-first search | O(|V| + O|E|) |
| Topological sort | O(|V| + O|E|) |
## Learning resources
## Things to look out for during interviews
- Readings
- [From Theory To Practice: Representing Graphs](https://medium.com/basecs/from-theory-to-practice-representing-graphs-cfd782c5be38), basecs
- [Deep Dive Through A Graph: DFS Traversal](https://medium.com/basecs/deep-dive-through-a-graph-dfs-traversal-8177df5d0f13), basecs
- [Going Broad In A Graph: BFS Traversal](https://medium.com/basecs/going-broad-in-a-graph-bfs-traversal-959bd1a09255), basecs
- Additional (only if you have time)
- [Finding The Shortest Path, With A Little Help From Dijkstra](https://medium.com/basecs/finding-the-shortest-path-with-a-little-help-from-dijkstra-613149fbdc8e), basecs
- [Spinning Around In Cycles With Directed Acyclic Graphs](https://medium.com/basecs/spinning-around-in-cycles-with-directed-acyclic-graphs-a233496d4688), basecs
- A tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. In that case you will have to handle cycles and keep a set of visited nodes when traversing.
- Ensure you are correctly keeping track of visited nodes and not visiting each node more than once. Otherwise your code could end up in an infinite loop.
## Corner cases
@ -54,11 +59,6 @@ In algorithm interviews, graphs are commonly given in the input as 2D matrices w
- Disjoint graphs
- Graph with cycles
## Things to look out for during interviews
- A tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. In that case you will have to handle cycles and keep a set of visited nodes when traversing.
- Ensure you are correctly keeping track of visited nodes and not visiting each node more than once. Otherwise your code could end up in an infinite loop.
## Graph search algorithms
- **Common** - Breadth-first Search, Depth-first Search