How to detect a loop (cycle) in a linked list

Traversing linked list is easy but what would happen if there is a cycle in the linked list?It will just fall into an infinity loop if traversing is implemented without a cycle prevention code.Thankfully, there is already a known algorithm for this kind of problem. How to detect if a cycle exists? Suppose there is a linked list that has a cycle like below.Now the question is how to detect the cycle. Let’s first think about what would happen if there is a cycle. Iterating linked list typically happens in a while loop like these steps. Check if the node READ MORE

Intro to Linked List data structure

Today, we will go over a popular data structure – linked list.Linked list may not make much sense for some languages such as python and javascript since there is already a good one such as list. However, since linked list is quite useful for languages like C++ it is still worthwhile to go over.In this post I will go over some important characteristics about linked list and strengths and weaknesses.Please note that all the explanations will be based on C++. What is Linked List? Linked list is a data structure that each node is connected like a chain via pointer.It READ MORE