Graph
So yea, this day I learned about graph. There are two types of graphs:
- Directed Graph: or we can say they have arrows or edges pointing to each other,
- Weighted Graph: if the edges have weights,
Thennn.. to store the graph, there are 2 ways:
- Adjacency Matrix: easy to implement (they said, but I haven’t tried it haha), efficient to query, space occupied.
- Adjacency List: imo it’s also easy to implement (but the others said it’s difficult to implement), less efficient to query, better space efficiency.
I think adjacency list is more often used.. and then for traversing the graph we know that there are two ways: DFS and BFS. Actually, the difference only lies in the stack (used in DFS) and queue (used in BFS).
related link :