Thursday, March 31, 2011

Java program to find the middle of a linked list in O(n) time

Method:
. Use two pointers in a loop
. One pointer will jump one node, where as the other pointer will jump 2 nodes.
. When the fast pointer reaches the end, the slow pointer will be at the middle.

No comments: