Graph Search Algorithms

aygerim
justontime
Published in
1 min readMay 21, 2018

Graph is pair of vertices and edges. The vertices are nodes and edges represent each vertex’s neighboring vertices.

Adjacency matrix and hybrid adjacency list are two ways to represent graph. Adjacency matrix is a valid solution with constant insert, delete and look-up. However space complexity is 2|V| which could be optimized with this trade-off: increasing runtime complexity for look-up to O(d) where d is the degree of the vertex, O(|V|-1) worst case and decrease the space complexity to O(|V|).

I have implemented Graph class from scratch with methods: addVertex, addEdges, removeVertex, removeEdge and two search algorithms: BFS (queue) and DFS (stack and recursion).

--

--