Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

57 Occupational injury and illness compensation and programs.

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago