Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

image text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago