STEM · Computer Science · Foundational Concepts/Principles
SaveGraphs and Graph Algorithms
Significance: Graphs model relationships: social networks, transportation, web pages, dependencies, state spaces. Fundamental algorithms: traversal (DFS, BFS), shortest paths (Dijkstra, Bellman-Ford, Floyd-Warshall), minimum spanning trees (Kruskal, Prim), network flow, topological sort. Many problems reduce to graph problems.
Questions to think through
- explain
Apply Dijkstra's algorithm: Find shortest path from A in weighted graph. Dijkstra maintains distances to each node, repeatedly selecting unvisited node with minimum distance. Trace algorithm on example graph. Why does greedy selection work (optimal substructure)? What's time complexity: O((V+E) log V) with binary heap. Why doesn't it work with negative edges (violates greedy assumption)?
- explain
Design graph algorithm: Detect cycle in directed graph. DFS approach: maintain states (unvisited, visiting, visited). When visiting node, explore neighbors. If neighbor is "visiting" (in current path), cycle exists. If "visited" (completed subtree), no cycle via that path. Explain why this works. What's time complexity O(V+E)? Convert this to detect strongly connected components (Kosaraju or Tarjan's algorithm).
