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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:04:28+00:00 2026-05-12T00:04:28+00:00

How can I find whether a singly linked list is circular/cyclic or not? I

  • 0

How can I find whether a singly linked list is circular/cyclic or not? I tried to search but couldn’t find a satisfactory solution. If possible, can you provide a pseudo-code or Java-implementation?

For instance:
1 → 3 → 5 → 71 → 45 → 7 → 5, where the second 5 is actually the third element of the list.

  • 1 1 Answer
  • 1 View
  • 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-12T00:04:29+00:00Added an answer on May 12, 2026 at 12:04 am

    The standard answer is to take two iterators at the beginning, increment the first one once, and the second one twice. Check to see if they point to the same object. Then repeat until the one that is incrementing twice either hits the first one or reaches the end.

    This algorithm finds any circular link in the list, not just that it’s a complete circle.

    Pseudo-code (not Java, untested — off the top of my head)

    bool hasCircle(List l)
    {
       Iterator i = l.begin(), j = l.begin();
       while (true) {
          // increment the iterators, if either is at the end, you're done, no circle
          if (i.hasNext())  i = i.next(); else return false;
    
          // second iterator is travelling twice as fast as first
          if (j.hasNext())  j = j.next(); else return false;
          if (j.hasNext())  j = j.next(); else return false;
    
          // this should be whatever test shows that the two
          // iterators are pointing at the same place
          if (i.getObject() == j.getObject()) { 
              return true;
          } 
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
I know Googling I can find an appropriate answer, but I prefer listening to
Anyone know where i can find a list of the columns for setting the
Does anyone know where I can find a library of common but difficult (out
How can I find whether a string is a data encoded with base64_encode() function
Can somebody give simple c-program to find whether my machine is 16-bit or 32-bit
I want to know whether we can find a tag in JEditorPane in java
I can find lots of information on how Long Polling works (For example, this
I can find a direct table foreign key in c# like: foreach (ForeignKey key
Everything I can find in linq for aggregation has a group by clause. How

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.