Parent array in BFS Shortest path

Why a parent array is created in graph bfs. What benefit do we get from it??

Hey Radha,

It is just a way of representing a graph. There is no such benifit except that graph can be represented by a single array.

Some use the “parent-child” method where a pair of numbers define an edge from the parent node to child node. Example 4 5 represents an edge between node 4 and node 5.

In “Parent array” method, pair of numbers is not needed since the index of the array represents the parent of the node i.e. an edge exists between the index and the number at the index.