How do you find the middle node of a linked list, and what are the two approaches?
There are two standard approaches and they differ in what they trade.
The first counts the nodes in one pass, then walks half of that distance in a second pass. It is easy to follow and needs only one pointer, but it touches every node twice.
The second uses two pointers moving at different speeds. The fast pointer moves two nodes per step and the slow pointer one. When the fast pointer reaches the end, the slow pointer is exactly at the middle. It touches each node about half as many times and uses no extra memory beyond the second pointer, but the loop condition is subtler because you have to check that the fast pointer and its successor both exist.
The mechanism behind the fast and slow version is that the fast pointer is always one full lap of the slow pointer ahead. When the list has an odd number of nodes, the fast pointer reaches the last node and the slow pointer sits on the true middle. When the list has an even number, the fast pointer goes one past the end and the slow pointer sits on the second of the two central nodes, which is the usual convention.
The trade-off to name is that the two pointer version is one pass instead of two, which matters for a list that might be long enough that the second pass is expensive, for example one backed by a disk read rather than memory. It also avoids the case where the list changes between the two passes, which would leave the second pass working on stale information.