Graph Algorithms Visualization

Explore fundamental graph algorithms through interactive visualizations

Graph Algorithms

Breadth-First Search

Level-order traversal algorithm

Depth-First Search

Recursive traversal algorithm

Dijkstra's Algorithm

Shortest path in weighted graphs

Prim's Algorithm

Minimum spanning tree

Kruskal's Algorithm

Minimum spanning forest

Controls

Graph Type

Breadth-First Search Visualization

Time: O(V + E)
Space: O(V)
A B C D E F

Current Step

Visiting node C. Adding its unvisited neighbors D and F to the queue.

BFS Queue

D
F
Empty
Empty

Pseudocode

BFS(graph, start):
    queue = [start]
    visited = set([start])
    
    while queue:
        node = queue.pop(0)
        process(node)
        
        for neighbor in graph[node]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append(neighbor)

Mathematical Analysis

\( \text{Time Complexity: } O(V + E) \)

BFS visits each vertex exactly once and examines each edge exactly twice (once from each endpoint in undirected graphs). Therefore, the time complexity is proportional to the sum of vertices and edges.

\( \text{Space Complexity: } O(V) \)

The space complexity is determined by the maximum size of the queue, which can contain at most \( V-1 \) vertices in the worst case (when all but one vertex are at the same level of the BFS tree).