Algorithm for detection and removal of cycle in linked list using Floyd's cycle-finding algorithm and a hash table:
- Initialize two pointers, 'slow' and 'fast', to the head of the linked list.
- Create an unordered_set container to store visited nodes.
- Use a while loop to iterate through the linked list. In each iteration, move the 'slow' pointer one node at a time and the 'fast' pointer two nodes at a time.
- Check if the 'slow' pointer is in the unordered_set container. If it is, a cycle has been detected.
- If a cycle is detected, initialize a new pointer 'last' to the 'slow' pointer.
- Use another while loop to iterate through the cycle, starting from the 'last' pointer, until the 'last' pointer points to the 'slow' pointer.
- Set the next pointer of the 'last' pointer to NULL, breaking the cycle.
- If the 'slow' pointer is not in the unordered_set container, add it to the set of visited nodes.
- Repeat steps 3-8 until the end of the linked list is reached.
- If the 'fast' pointer is NULL or the 'fast' pointer's next pointer is NULL, return false, indicating that there is no cycle in the linked list.
- If the 'slow' pointer and 'fast' pointer are equal, return true, indicating that there is a cycle in the linked list.
It's important to note that, this algorithm has a time complexity of O(n) and a space complexity of O(n) as it uses hash table to keep track of the visited nodes.