Professional Documents
Culture Documents
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
The only purpose of this algorithm is to visit all the vertex of the
graph avoiding cycles
u.visited = true
if v.visited == false
DFS(G,v)
init() {
For each u ∈ G
u.visited = false
For each u ∈ G
DFS(G, u)
01243
12453
01352476
or
02475136
or
02475361
Starting node: 0
DR. SHWETA SHARMA, PEC CHANDIGARH 42
Thank you!