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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:28+00:00 2026-06-03T02:53:28+00:00

This algorithm solves Hamiltonian path problem. G is a unoriented graph, v starting vertex,

  • 0

This algorithm solves Hamiltonian path problem. G is a unoriented graph, v starting vertex,
G.size() size of the graph, G.get(v).gV all the neighbor verices of the current vertex.

static private void dfs(HashMap<Integer, Virsune> G, int v) {
    path.push(v);
    // add v to the current path
    onPath[v] = true;

    if (path.size() == G.size()) {
        System.out.println(path);

        Integer[] tmp = new Integer[G.size()];
        System.arraycopy(path.toArray(), 0, tmp, 0, path.size());
        hamPaths.add(tmp);
    }

    for (int w : G.get(v).gV) {
        if (!onPath[w]) {
            dfs(G, w);
        }
    }

    path.pop();
    onPath[v] = false;

} 
   // main method
   dfs(G,0);

Can I just say that complexity of this algorithm is O(n!) ?

  • 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-03T02:53:29+00:00Added an answer on June 3, 2026 at 2:53 am

    This is algorithm is enumerating all the paths of the graph.

    If you’re enumerating all the paths in a graph, this should give you a hint at the runtime. In a complete graph, there are indeed n! paths, so this is a lower bound. I’ll leave it to you to say if it’s an upper bound as well.

    FWIW – the problem is solvable in O(2^n)

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

Sidebar

Related Questions

What would be the best algorithm to solve this problem? I spent a couple
I saw this algorithm that will take numbers or words and find all possible
This question solves half of my problem because my sliding window can move outside
I'm stuck with this little problem and my algorithm to solve this doesn't hold
I found an answer that almost solves my problem: https://stackoverflow.com/a/5717191/1065546 This answer demonstrates how
I need to solve this algorithm problem. In the diagram, there are many rows
What's a good algorithm to solve this problem? I have three groups of people
I would like to know if there exist algorithms that solves this issue. It
I have this algorithm in Java to store passwords in database. I'd like to
I have this algorithm that I want to implement on VB6. Sub Main() dim

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.