Write an algorithm that counts number of nodes in the circular linked list
Answer / Ashutosh Upadhyay
Here's an iterative solution for counting nodes in a circular linked list. Let `slow` and `fast` be pointers.n
1. Initialize `slow` to the head of the list, and `fast` to `NULL`.
2. Move `fast` two steps ahead of `slow` (i.e., `fast = slow->next->next`).
3. Continue moving `slow` one step ahead (i.e., `slow = slow->next`).
4. If `fast` and `slow` meet, the number of nodes in the circular linked list is one less than the number of steps taken by `slow` since they would have met at the starting node.
5. After step 4, move `slow` to the beginning of the list (i.e., `slow = head`) and increment a counter for each step taken until meeting the original position of `fast`.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is mean by selection sort?
Is set sorted?
When will we get ArrayStoreException?
Explain the Linked List
Differentiate between hashset and hashmap.
What happens if we try to insert duplicate key in hashmap?
Define adjacent nodes?
Is a hash table a map?
Can binary tree have 1 child?
What is data and its type?
What happens if we put a key object in a hashmap which exists?
What is difference between data type and data structure?