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 8752909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:19:31+00:00 2026-06-13T13:19:31+00:00

My homework is to determine if a maze is solvable of not using Queue.

  • 0

My homework is to determine if a maze is solvable of not using Queue. If it is, print the path. I can get Queue to get to the end but it says it’s unsolvable. When actually it is. If I change the Final check if Statement to:

if (queue.isEmpty())
    {
        System.out.println("The maze is solvable!");
    }
else
    {
        System.out.println("The maze is unsolvable!");
    }

Then it says it is solvable, but then when I try another maze that isn’t solvable it says it is solvable. Not sure where I’m going wrong.

I have a separate Point class that defines the Points and right, left, above and below positions. I have to use Point (0,0) to mark the start and Point (row-1,col-1) to mark the goal.

Let me know if you need more code. It is searching a char 2D array.

maze1.txt – (First Line Defines the # of Rows and Columns) – Is Solvable

7 12
..+.+.++++++
.++...++...+
..++.....+.+
+.+..++.+..+
+...++....++
+.+++..++..+
++++++++++..

Says it’s unsolvable

    QueueMaze
The maze is unsolvable!
p p + p + p + + + + + + 
p + + p p p + + p p p + 
p p + + p p p p p + p + 
+ p + p p + + p + p p + 
+ p p p + + p p p p + + 
+ p + + + p p + + p p + 
+ + + + + + + + + + p . 

mMethod for solving the Maze

public void queueMaze() {

char[][] storedMaze = copy(); 

LinkedList<Point> queue = new LinkedList<Point>();
    int count = 0;
    Point start = new Point(0,0);
    Point cur, end, above, right, left, below;

    Boolean solved = false;

queue.add(start); 

while (!queue.isEmpty())
    {
    //Store the first element position 0 in cur
        cur = queue.removeFirst();
        //System.out.println(cur.toString());

        //compare cur's points to the isEnd points
        //(row-1, col-1) if it is the end, break out
        //of the While
        if (isEnd(cur) && isSafe(cur))
        {
            //System.out.println("cur's final : " + cur.toString());
            end = cur;
            break;
        }

        //mark cur as visited with a P
    markVisited(cur, P);

        //check the position above cur to see if it is
        //
    right = cur.getRight(); 
    if (inBounds(right) && isSafe(right))
        {
            queue.add(right);
        }

        below = cur.getBelow(); 
    if (inBounds(below) && isSafe(below))
        {
            queue.add(below);
        }

        left = cur.getLeft(); 
    if (inBounds(left) && isSafe(left))
        {
            queue.add(left);
        }

        above = cur.getAbove(); 
    if (inBounds(above) && isSafe(above))
        {
            queue.add(above);
        }

}//while
//System.out.println("The queue size is: " + queue.size());

    if (!queue.isEmpty())
    {
        System.out.println("The maze is solvable!");
    }
else
    {
        System.out.println("The maze is unsolvable!");
    }

print();

returnMaze(storedMaze);
}
  • 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-13T13:19:33+00:00Added an answer on June 13, 2026 at 1:19 pm

    the queue being empty does not determine whether or not the maze is solved. the queue simply keeps track of which spaces still need to be checked. it is perfectly fine to come to the end of the maze with lots of spaces left to check in your queue.

    it looks like if your if (isEnd(cur) && isSafe(cur)) is triggered, then the maze is solveable.

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

Sidebar

Related Questions

I am working on my homework, but I am not sure how to calculate
Not new to Joomla, but new to 2.5, and am using Cook Component Builder
This is not homework . I am interested in setting up a simulation of
This is a homework question, but I think there's something missing from it. It
This IS NOT a Homework question! While building my current student database project I
I've been using LaTeX for a little while now to typeset my algorithms homework,
Okay, I know this is going to sound like homework; but here goes any
First off, this is part of an extra credit homework, so please do not
My homework assignment is telling me to declare a class inline, but I've only
I'm doing my homework on java I/O data, the problem is i'm not allowed

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.