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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:09:07+00:00 2026-06-18T00:09:07+00:00

I’m writing a program in Java where I must implement three search algorithms, among

  • 0

I’m writing a program in Java where I must implement three search algorithms, among the three is the depth first graph-search algorithm. My program traverses a connected graph represented internally by an adjacency matrix and uses a frontier and an explored set with each algorithm.

The frontier stores the unexplored child nodes of expanded parent nodes and the explored set stores those nodes which have actually been expanded. The purpose of the explored set is to avoid duplicates and thus avoid infinite loops.

My frontier is implemented using a linked blocking deque and my explored set using a linked hash set.

However, upon testing the initial version of this algorithm implementation I noticed that there were still a small number of duplicates, particularly when the goal node did not exist and the algorithm would surely have to visit every node in the graph. Eventually I realized that this is because when a node is expanded all of its child nodes are added to the frontier but only one of them is explored. Because the graph is a connected one then other paths may exist to the node and this may result in the node being encountered multiple times before it is ever expanded and thus added to the explored set.

This leads me to my question, do i fix it?

The depth first search is supposed to explore one side of the tree formed from the graph first and then backtrack, this means that even if it encounters a less optimal goal node on one side of the tree it should return that instead of a (more optimal) one previously encountered but not yet explored.

However, if I am implementing an explored set for the purpose of avoiding duplicates it seems contradictory that I allow them in certain instances.

I believe the real error may lie in a lack of thorough understanding of the algorithm and I am sincerely hoping for some assistance, thanks in advance.

  • 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-18T00:09:09+00:00Added an answer on June 18, 2026 at 12:09 am

    The algorithm commonly known as depth first search does not need a “frontier”, as you call it. This concept is used however with A* graph searches (it is usually called “open set” there).

    For standard depth first search, all you need is a stack of nodes: Push the initial node on the stack, then in each step pop one node from the stack, examine it and push all its neighbours(*) on top of the stack. Then, repeat.

    (*) remember to mark all nodes that you push on the stack as visited (I believe you call this “explored set” in your questions) and don’t push nodes that have already been visited.

    By using a stack, you avoid the problem you describe.

    If you actually want to maintain that frontier/open set, make sure that it never contains duplicates: use a data structure that does not allow duplicates (e.g. a set).

    (Sidenote: If your graph nodes have a natural numbering and you expect your DFS to visit the majority of notes, you may as well use an array/vector for your explored set/closed set.)

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.