Professional Documents
Culture Documents
A collection of vertices V
A collection of edges E
The index of the array represents a vertex and each element in its linked list
represents the other vertices that form an edge with the vertex
Rubik’s Cube is seen as searching for a path to convert it from a full mess of colors to a
single color
1. Start by putting any one of the graph’s vertices at the back of the queue
2. Now take the front item of the queue and add it to the visited list
3. Create a list of that vertex's adjacent nodes. Add those which are not
within the visited list to the rear of the queue
4. Keep continuing steps two and three till the queue is empty
while Q is non-empty
01234
A, B, C, D, E, F
2, 3, 0, 1
or
2, 0, 3, 1
R, S, V, W, T, X, U, Y
The only purpose of this algorithm is to visit all the vertex of the
graph avoiding cycles
01243
12453
01352476
or
02475136
or
02475361
Starting node: 0
DR. SHWETA SHARMA, DEPT. OF CSE, PEC CHANDIGARH 47
Question 4 on DFS Traversal
Ans: 0231
Starting node: 0
DR. SHWETA SHARMA, DEPT. OF CSE, PEC CHANDIGARH 48
Question 4 on DFS Traversal
Starting node: H
DR. SHWETA SHARMA, DEPT. OF CSE, PEC CHANDIGARH 49
Thank you!