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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:10:23+00:00 2026-05-13T08:10:23+00:00

From this Wikipedia article: http://en.wikipedia.org/wiki/Hamiltonian_path_problem A randomized algorithm for Hamiltonian path that is fast

  • 0

From this Wikipedia article:

http://en.wikipedia.org/wiki/Hamiltonian_path_problem

A randomized algorithm for Hamiltonian
path that is fast on most graphs is
the following: Start from a random
vertex, and continue if there is a
neighbor not visited. If there are no
more unvisited neighbors, and the path
formed isn’t Hamiltonian, pick a
neighbor uniformly at random, and
rotate using that neighbor as a pivot.
(That is, add an edge to that
neighbor, and remove one of the
existing edges from that neighbor so
as not to form a loop.) Then, continue
the algorithm at the new end of the
path.

I don’t quite understand how this pivoting process is supposed to work. Can someone explain this algorithm in more detail? Perhaps we can eventually update the Wiki article with a more clear description.

Edit 1: I think I understand the algorithm now, but it seems like it only works for undirected graphs. Can anyone confirm that?

Here’s why I think it only works for undirected graphs:

alt text http://www.michaelfogleman.com/static/images/graph.png

Pretend the vertices are numbered like so:

123
456
789

Let’s say my path so far is: 9, 5, 4, 7, 8. 8’s neighbors have all been visited. Let’s say I choose 5 to remove an edge from. If I remove (9, 5), I just end up creating a cycle: 5, 4, 7, 8, 5, so it seems I have to remove (5, 4) and create (8, 5). If the graph is undirected, that’s fine and now my path is 9, 5, 8, 7, 4. But if you imagine those edges being directed, that’s not necessarily a valid path, since (8, 5) is an edge but (5, 8) might not be.

Edit 2: I guess for a directed graph I could create the (8, 5) connection and then let the new path be just 4, 7, 8, 5, but that seems counter productive since I have to chop off everything that previously led up to vertex 5.

  • 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-05-13T08:10:23+00:00Added an answer on May 13, 2026 at 8:10 am

    Basically, once your random selection of nodes has construct a graph in such a way that the last vertex A has no unvisited neighboring vertices you need to make a vertex available to continue on.

    To do this: select a neighboring vertex at random, remove one of its existing edges (in a Hamiltonian path there can be only two edges from any single vertex), then draw a new edge from your current vertex to this now available randomly selected one. You then trace from the randomly selected vertex to the end of the graph (the first vertex that has only a single edge leaving it) and continue the algorithm.

    In all sorts of horrific psuedo-code:

      Graph graph;
      Vertex current;
      Path path;
    
      while(!IsHamiltonian(path))
      {
        if(HasUnvisitedNeighbor(current, path))
        {
          Vertex next = SelectRandomUnvisited(current, path);
          DrawEdgeTo(next, current, path);
          current= next;
        }
        else
        {
           Vertex next = SelectRandomNeighbor(current, path);
           RemoveRandomEdgeFrom(next, path);
           DrawEdgeTo(next, current, path);
           path = FindEnd(next, current, path);  //Finds the end of the path, starting from next, without passing through current
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 450k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The code will be less error prone, and clearer to… May 15, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer The simplest way would be to avoid using each() and… May 15, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer Use the getDescription() method on the element, something like: <?php… May 15, 2026 at 8:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.