{"id":473,"date":"2021-07-13T11:08:43","date_gmt":"2021-07-13T11:08:43","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=473"},"modified":"2021-09-16T12:32:43","modified_gmt":"2021-09-16T12:32:43","slug":"detect-loop-in-a-linked-list","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/","title":{"rendered":"Detect loop in a linked list ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"detect-loop-in-a-linked-list\" class=\"color-pink\">Detect loop in a linked list ?<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li>There are two ways to detect loop in linked list or not.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"ImageContent\">\n<div class=\"hddn\"><img decoding=\"async\" class=\"img-responsive center-block aligncenter\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png\" alt=\" Detect Loop in a Linked List\" \/><\/div>\n<\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"method-1\" class=\"color-blue\">Method 1:<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li>Traverse through each node till end , tracking visited node using Hash map.<\/li>\n<li>If you find node that is already visited, then there is a loop in LinkedList<\/li>\n<li>If you reach till end while traversing then there is no loop in LinkedList<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markdown code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markdown code-embed-code\">using namespace std; <br\/><br\/>struct Node <br\/>{ <br\/>\tint data; <br\/>\tstruct Node* next; <br\/>}; <br\/><br\/>void push(struct Node** head_ref, int new_data) <br\/>{ <br\/><br\/>\tstruct Node* new_node = new Node; <br\/><br\/>\t<br\/>\tnew_node->data = new_data; <br\/><br\/>\t\/* link the old list off the new node *\/<br\/>\tnew_node->next = (*head_ref); <br\/><br\/>\t\/* move the head to point to the new node *\/<br\/>\t(*head_ref) = new_node; <br\/>} <br\/><br\/>\/\/ Returns true if there is a loop in linked list <br\/>\/\/ else returns false. <br\/>bool detectLoop(struct Node *h) <br\/>{ <br\/>\tunordered_set<Node *> s; <br\/>\twhile (h != NULL) <br\/>\t{ <br\/>\t\t\/\/ If this node is already present <br\/>\t\t\/\/ in hashmap it means there is a cycle <br\/>\t\t\/\/ (Because you we encountering the <br\/>\t\t\/\/ node for the second time). <br\/>\t\tif (s.find(h) != s.end()) <br\/>\t\t\treturn true; <br\/><br\/>\t\t\/\/ If we are seeing the node for <br\/>\t\t\/\/ the first time, insert it in hash <br\/>\t\ts.insert(h); <br\/><br\/>\t\th = h->next; <br\/>\t} <br\/><br\/>\treturn false; <br\/>} <br\/><br\/>\/* Drier program to test above function*\/<br\/>int main() <br\/>{ <br\/>\t\/* Start with the empty list *\/<br\/>\tstruct Node* head = NULL; <br\/><br\/>\tpush(&head, 21); <br\/>\tpush(&head, 14); <br\/>\tpush(&head, 5); <br\/>\tpush(&head, 10); <br\/><br\/>\t\/* Create a loop for testing *\/<br\/>\thead->next->next->next->next = head; <br\/><br\/>\tif (detectLoop(head)) <br\/>\t\tcout << &quot;Loop found&quot;; <br\/>\telse<br\/>\t\tcout << &quot;No Loop&quot;; <br\/><br\/>\treturn 0; <br\/>} <\/code><\/pre> <\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"output\" class=\"color-blue\">Output:<\/h2>\n<p><code class=\"hljs\" data-lang=\"\"><span class=\"nt\">Loop found<\/span><\/code><\/p>\n<\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"method-2\" class=\"color-blue\">Method 2:<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li>Efficient approach for this problem would be Floyd\u2019s cycle detection algorithm, so steps for this algorithm would be:<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Use two pointer fastPtr and slowPtr and initialize both to head of linkedlist<\/li>\n<li>Move fastPtr by two nodes and slowPtr by one node in each iteration.<\/li>\n<li>If fastPtr and slowPtr meet at some iteration , then there is a loop in linkedlist.<\/li>\n<li>If fastPtr reaches to the end of linkedlist without meeting slow pointer then there is no loop in linkedlist (i.e fastPtr->next or fastPtr->next->next become null).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">\/\/ C program to detect loop in a linked list <br\/>#include<stdio.h> <br\/>#include<stdlib.h> <br\/>\/* Link list node *\/<br\/>struct Node <br\/>{ <br\/>\tint data; <br\/>\tstruct Node* next; <br\/>}; <br\/><br\/>void push(struct Node** head_ref, int new_data) <br\/>{ <br\/>\t\/* allocate node *\/<br\/>\tstruct Node* new_node = <br\/>\t\t(struct Node*) malloc(sizeof(struct Node)); <br\/><br\/>\t\/* put in the data *\/<br\/>\tnew_node->data = new_data; <br\/><br\/>\t\/* link the old list off the new node *\/<br\/>\tnew_node->next = (*head_ref); <br\/><br\/>\t\/* move the head to point to the new node *\/<br\/>\t(*head_ref) = new_node; <br\/>} <br\/><br\/>int detectloop(struct Node *list) <br\/>{ <br\/>\tstruct Node *slow_p = list, *fast_p = list; <br\/><br\/>\twhile (slow_p && fast_p && fast_p->next ) <br\/>\t{ <br\/>\t\tslow_p = slow_p->next; <br\/>\t\tfast_p = fast_p->next->next; <br\/>\t\tif (slow_p == fast_p) <br\/>\t\t{ <br\/>\t\tprintf(&quot;Found Loop&quot;); <br\/>\t\treturn 1; <br\/>\t\t} <br\/>\t} <br\/>\treturn 0; <br\/>} <br\/><br\/>\/* Drier program to test above function*\/<br\/>int main() <br\/>{ <br\/>\t\/* Start with the empty list *\/<br\/>\tstruct Node* head = NULL; <br\/><br\/>\tpush(&head, 10); <br\/>\tpush(&head, 4); <br\/>\tpush(&head, 5); <br\/>\tpush(&head, 10); <br\/><br\/>\t\/* Create a loop for testing *\/<br\/>\thead->next->next->next->next = head; <br\/>\tdetectloop(head); <br\/><br\/>\treturn 0; <br\/>}<\/code><\/pre> <\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"output-2\" class=\"color-blue\">Output:<\/h2>\n<\/div>\n<\/div>\n<div class=\"CodeContent\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<pre><code id=\"code2\" class=\"hljs\" data-lang=\"\"><span class=\"nt\">Found Loop<\/span><\/code><\/pre>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : There are two ways to detect loop in linked list&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3028],"tags":[195,971,491,221,368,203,199,214,198,363,3057,205,3196,3191,3195,3186,3193,222,3187,3192,484,3054,196,212,3184,3188,3194,3189,3182,3183,3185,207,3190,366,204,3180,15925,206,972,200,15921,3055,197,3181,968,3056,285,969],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-data-structure","tag-accenture-interview-questions-and-answers","tag-altimetrik-india-pvt-ltd-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-bharti-airtel-interview-questions-and-answers","tag-bmc-software-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-te-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-find-length-of-linked-list-java","tag-find-length-of-loop-in-linked-list","tag-find-length-of-loop-in-linked-list-in-java","tag-find-start-of-loop-in-linked-list","tag-find-start-of-loop-in-linked-list-java","tag-flipkart-interview-questions-and-answers","tag-floyds-cycle-detection-algorithm","tag-for-loop-linked-list-c","tag-genpact-interview-questions-and-answers","tag-globallogic-india-pvt-ltd-interview-questions-and-answers","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-java-detect","tag-length-of-loop-in-linked-list","tag-length-of-loop-in-linked-list-java","tag-linked-list-algorithm","tag-linked-list-in-data-structure","tag-linked-list-program-in-c-with-explanation","tag-linked-list-program-in-clinked-list-algorithm","tag-mphasis-interview-questions-and-answers","tag-nth-node-from-end-of-linked-list","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-reverse-a-linked-list","tag-samsung-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-sapient-consulting-pvt-ltd-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-telibrahma-interview-questions-and-answers","tag-tracxn-technologies-pvt-ltd-interview-questions-and-answers","tag-unitedhealth-group-interview-questions-and-answers","tag-what-is-loop","tag-wipro-infotech-interview-questions-and-answers","tag-wm-global-technology-services-india-pvt-ltd-limited-wmgts-interview-questions-and-answers","tag-xoriant-solutions-pvt-ltd-interview-questions-and-answers","tag-yodlee-infotech-pvt-ltd-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Detect loop in a linked list ? - Data Structure Interview Questions<\/title>\n<meta name=\"description\" content=\"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Detect loop in a linked list ? - Data Structure Interview Questions\" \/>\n<meta property=\"og:description\" content=\"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T11:08:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-16T12:32:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/\"},\"author\":{\"name\":\"Editor\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"headline\":\"Detect loop in a linked list ?\",\"datePublished\":\"2021-07-13T11:08:43+00:00\",\"dateModified\":\"2021-09-16T12:32:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/\"},\"wordCount\":788,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list.png\",\"keywords\":[\"Accenture interview questions and answers\",\"Altimetrik India Pvt Ltd interview questions and answers\",\"Applied Materials interview questions and answers\",\"Bharti Airtel interview questions and answers\",\"BMC Software interview questions and answers\",\"Capgemini interview questions and answers\",\"CASTING NETWORKS INDIA PVT LIMITED interview questions and answers\",\"CGI Group Inc interview questions and answers\",\"Chetu interview questions and answers\",\"Ciena Corporation interview questions and answers\",\"Collabera Te interview questions and answers\",\"Dell International Services India Pvt Ltd interview questions and answers\",\"find length of linked list java\",\"find length of loop in linked list\",\"find length of loop in linked list in java\",\"find start of loop in linked list\",\"find start of loop in linked list java\",\"Flipkart interview questions and answers\",\"floyd's cycle detection algorithm\",\"for loop linked list c++\",\"Genpact interview questions and answers\",\"Globallogic India Pvt Ltd interview questions and answers\",\"IBM interview questions and answers\",\"Indecomm Global Services interview questions and answers\",\"java detect\",\"length of loop in linked list\",\"length of loop in linked list java\",\"linked list algorithm\",\"linked list in data structure\",\"linked list program in c with explanation\",\"linked list program in clinked list algorithm\",\"Mphasis interview questions and answers\",\"n'th node from end of linked list\",\"NetApp interview questions and answers\",\"Oracle Corporation interview questions and answers\",\"reverse a linked list\",\"samsung interview questions and answers\",\"SAP Labs India Pvt Ltd interview questions and answers\",\"Sapient Consulting Pvt Ltd interview questions and answers\",\"Tech Mahindra interview questions and answers\",\"telibrahma interview questions and answers\",\"Tracxn Technologies Pvt Ltd interview questions and answers\",\"UnitedHealth Group interview questions and answers\",\"what is loop\",\"Wipro Infotech interview questions and answers\",\"WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers\",\"Xoriant Solutions Pvt Ltd interview questions and answers\",\"Yodlee Infotech Pvt Ltd interview questions and answers\"],\"articleSection\":[\"Data Structure\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/\",\"name\":\"Detect loop in a linked list ? - Data Structure Interview Questions\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list.png\",\"datePublished\":\"2021-07-13T11:08:43+00:00\",\"dateModified\":\"2021-09-16T12:32:43+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list.png\",\"contentUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/detect-loop-in-a-linked-list.png\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/editor\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Detect loop in a linked list ? - Data Structure Interview Questions","description":"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Detect loop in a linked list ? - Data Structure Interview Questions","og_description":"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/","og_site_name":"Wikitechy","article_published_time":"2021-07-13T11:08:43+00:00","article_modified_time":"2021-09-16T12:32:43+00:00","og_image":[{"url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png","type":"","width":"","height":""}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/"},"author":{"name":"Editor","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"headline":"Detect loop in a linked list ?","datePublished":"2021-07-13T11:08:43+00:00","dateModified":"2021-09-16T12:32:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/"},"wordCount":788,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png","keywords":["Accenture interview questions and answers","Altimetrik India Pvt Ltd interview questions and answers","Applied Materials interview questions and answers","Bharti Airtel interview questions and answers","BMC Software interview questions and answers","Capgemini interview questions and answers","CASTING NETWORKS INDIA PVT LIMITED interview questions and answers","CGI Group Inc interview questions and answers","Chetu interview questions and answers","Ciena Corporation interview questions and answers","Collabera Te interview questions and answers","Dell International Services India Pvt Ltd interview questions and answers","find length of linked list java","find length of loop in linked list","find length of loop in linked list in java","find start of loop in linked list","find start of loop in linked list java","Flipkart interview questions and answers","floyd's cycle detection algorithm","for loop linked list c++","Genpact interview questions and answers","Globallogic India Pvt Ltd interview questions and answers","IBM interview questions and answers","Indecomm Global Services interview questions and answers","java detect","length of loop in linked list","length of loop in linked list java","linked list algorithm","linked list in data structure","linked list program in c with explanation","linked list program in clinked list algorithm","Mphasis interview questions and answers","n'th node from end of linked list","NetApp interview questions and answers","Oracle Corporation interview questions and answers","reverse a linked list","samsung interview questions and answers","SAP Labs India Pvt Ltd interview questions and answers","Sapient Consulting Pvt Ltd interview questions and answers","Tech Mahindra interview questions and answers","telibrahma interview questions and answers","Tracxn Technologies Pvt Ltd interview questions and answers","UnitedHealth Group interview questions and answers","what is loop","Wipro Infotech interview questions and answers","WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers","Xoriant Solutions Pvt Ltd interview questions and answers","Yodlee Infotech Pvt Ltd interview questions and answers"],"articleSection":["Data Structure"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/","name":"Detect loop in a linked list ? - Data Structure Interview Questions","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png","datePublished":"2021-07-13T11:08:43+00:00","dateModified":"2021-09-16T12:32:43+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"Detect loop in a linked list ? - Traverse through each node till end , tracking visited node using Hash map. If you find node that is already visited, then there is a loop in LinkedList","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list\/#primaryimage","url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png","contentUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/detect-loop-in-a-linked-list.png"},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":4,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"predecessor-version":[{"id":3531,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/473\/revisions\/3531"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}