Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8269001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:35+00:00 2026-06-08T06:04:35+00:00

I need an algorithm for a robot to explore an n*n grid with obstacles

  • 0

I need an algorithm for a robot to explore an n*n grid with obstacles (a maze if you wish). The goal is to explore all the squares without obstacles in them an avoid the squares with obstacles. The trick is that an obstacle forces the robot to change its path causing it to miss the possible free squares behind the obstacle. I can lazily increment/decrement the robot’s x/y coordinates to have the robot move in any of the four directions in case there are no obstacles and the robot can traverse a pre-seen path (if needed) in order to reach other free squares. The algorithm should terminate when ALL the free squares were met at least once.

Any simple lazy/efficient way to do this? a pseudo-code will be greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:04:36+00:00Added an answer on June 8, 2026 at 6:04 am

    I believe the problem is reduceable from Traveling Salesman Problem, and thus is NP – Hard, so you are unlikely to find a polynomial solution that solves the problem optimally and efficiently.

    However, You might want to adopt some of the heuristics and approximations for TSP, I believe they can be adjusted to this problem as well, since the problem seems very closed to TSP in the first place

    EDIT:

    If finding the shortest path is not a requirement, and you want any path, a simple DFS with maintaining a visited set can do. In the step in DFS you come back from the recursion – you move to the previous squares, this way the robot is ensured to explore all squares, if there is a path to all of them.

    pseudo code for DFS:

    search(path,visited,current):
       visited.add(current) 
       for each square s adjacent to current:
          if (s is an obstacle): //cannot go to a square which is an obstacle
             continue
          if (s is not in visited): //no point to go to a node that was already visited
             path.add(s) //go to s
             search(path,visited,current) //recursively visit all squares accesable form s
             //step back from s to current, so you can visit the next neighbor of current.
             path.add(current)
    

    invoke with search([source],{},source)

    Note that optimization heuristics can be used before the for each step – the heuristic will just be to reorder the iteration order of the nodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to program an algorithm to navigate a robot through a maze (a
I need an algorithm to find all of the subsets of a set where
I need an efficient algorithm to generate all the subtrees expanded from the root
I need an algorithm which given a list L and a number N ,
I need the algorithm to animate the arrow based on 2 parameters, angle while
I need effective algorithm to keep only ten latest files on disk in particular
I need an algorithm to store a key/value pair, where the key is an
I need an algorithm to convert a closed bezier curve (perhaps self-crossing) to a
I need help regarding DDA algorithm , i'm confused by the tutorial which i
I need help designing an algorithm for recommendations on movies. Every user in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.