Find a cycle in a linked list

How would you find a cycle in a linked list? Optimize for speed.

2 Comments

  1. techie007 says:

    1. Start with 2 pointers P and Q
    2. Move P 2 pointers and Q one pointer every time
    3. Check if P is same as Q
    4. If at any point P = Q then we have a cycle

    The logic is if P has double speed of Q and there exists a cycle P will overtake Q and will overlapse once both are in the cycle.

  2. KEITH says:


    CheapTabletsOnline.com. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. High quality drugs. Buy drugs online

    Buy:Petcam (Metacam) Oral Suspension.Prednisolone.Accutane.Actos.Zovirax.Lumigan.Valtrex.Prevacid.Retin-A.Zyban.Arimidex.Human Growth Hormone.Mega Hoodia.100% Pure Okinawan Coral Calcium.Nexium.Synthroid….

Leave a Reply