Question 9
Consider the following class Node:
Consider an implementation of a linked list where each node is created using the given class Node. Suppose head points to the first node of the linked list. Assume that the linked list is in sorted order.
What is an efficient way to count duplicate values in the linked list?
Traverse the linked list once, comparing each node with its immediate successor and count duplicates.
Traverse the linked list once and store each node’s value in a hash table to count duplicates.
Use a nested loop to compare each node with all other nodes and count duplicates.
Recursively traverse the linked list from the tail and count duplicates.