Question: (Python) I need help understanding the time/space complexity for my code. The question is to implement a algorithm to achieve [ [1,2,3], [4,5,6] ] given

 (Python) I need help understanding the time/space complexity for my code.

(Python) I need help understanding the time/space complexity for my code. The question is to implement a algorithm to achieve [ [1,2,3], [4,5,6] ] given a random set numbers. The input will always be a 2x rows 3x columns 2d array. Here I used bfs, however I am not exactly sure what the time/space, any input will be much appreciated!

# board game / sliding puzzle # want to do BFS def slidingPuzzle (board): target[1,2,3], [4,5,011 [(x,y)] [x,y) for x in range ( 2 ) for y in range (3) # q deque ([(board , 0 , x,y)]) q((board,0,x,y)]) # keep track of the boards seen visitedset (tuple (map (tuple, board))) if board [x][y]=:0] # find 0 loc while q board, steps, x, yq.pop (0) boardlist (map(list,board)) if boardtarget: return steps for direction in [[1,01, [0,1], [-1,0], [0,-111: temp-x, temp-y = x + direction [0], y + direction [1] print (temp_x, temp_y) # make dont go out of bound if 0tempx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!