Monday, December 3, 2007

Linked List Circular or Not?

Given a pointer to the head of a link list write a function that returns 0 if the linked list ends in NULL or 1 if it is a circular linked list. Note that a final node in a circular link list doesn't necessarily point to the first node, but could point to any node in the list.

Part 1) Write a function that solves the problem in O(n^2)
Part 2) Write a function that solves the problem in O(n)