Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume you have the following backtracking algorithm for finding a way to a desired location in a city organized in a grid as represented by
Assume you have the following backtracking algorithm for finding a way to a desired location in a city organized in a grid as represented by the image. What is the problem with this proposed algorithm? Bool SearchCity(currentLocation, desiredLocation, stepstolocation) i If('currentLocation == desiredLocation) i Return true; 1 potentialSteps = new Stack0: if (NotBlocked(RightLocation)) ( /location to the right of where I am facing potentialSteps.Push(RightLocation); ] If (NotBlocked(ForwardLocation )) \& / Location forward of where I am facing potentialSteps.Push(forwardLocation) ] If (NotBlocked(LeftLocation)) f / Location to the left of where I am facing potentialSteps.Push(leftLocation) ] While(NotEmpty(potentialSteps)) i nextlocation = potentialSteps.Pop(); stepsToLocation.Add(nextlocation) if(SearchCity(nextlocation, desiredLocation, stepsToLocation) == true) i return true; 1 stepsToLocation.RemoveLast() ] Return false; ] It will never take the right path It does not check if a direction is blocked It does not retum to previous locations after a dead end It can be caught in an infinite loop by always going right first. It will always go forward What is a potential solution to the problem in the previous question? Check if the current location is the destination Add the backwards location to the stack of locations to visit Replace the stack with a Queue Do not visit a location contained in stepsiolocation Only add elther the left or right destinations as candidates Question 15 1 pts Assuming the above algorithm is fixed, which of the following would improve its performance in finding a desired location? Randomly selecting from the next possible locations Always checking the forward direction first before the other directions Choosing candidate locations that are closest to the destination first Checking if the next location is the destination before making the recursive call Rotating which direction is to be searched first in a fixed order
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started