202 views

1 Answer

Best answer
4 votes
4 votes

Initialise two pointers to head.

Increment one pointer by one and other of two .

So the one pointer which is incremented by two will reach the end of linked list eventually .So the pointer which was being incremented by one will be at the middle of the linked list.

So effectively , the complexity of the code becomes O(length / 2)

Hence C) is the correct option.

Reference : http://www.geeksforgeeks.org/write-a-c-function-to-print-the-middle-of-the-linked-list/

selected by

No related questions found