Extra credit (on both exams) The problem boils down to detecting a loop in a single-linked list. This has to be done without modifying the list, in constant additional space and linear time. bool isListCircular(const Rec* begin) { if (begin==NULL || begin->next == NULL || begin->next->next) return false; const Rec *ptr1=begin->next; //these two pointers == O(1) additional memory const Rec *ptr2=ptr1 ->next; // ptr2 starts ahead of ptr1 and moves faster while (ptr1!=ptr2) // this can only happen after ptr1 and ptr2 { // get inside the loop ptr2=ptr2->next; if (ptr1==NULL) return false; ptr2=ptr2->next; if (ptr1==NULL) return false; ptr1=ptr1->next; // no need to compare to NULL because ptr2 is ahead } return true; }; Complexity analysis: The while loop takes linear time because the distance between ptr1 and ptr2 is growing by one at every step at most until both pointers get inside the loop and the distance becomes == the loop size. At that moment, the pointers will be equal. The necessary number of steps for this to happen is the sum of the number of elements before the loop (prt1 must walk that distance at minimum) plus, in the worst-case, the number of elements in the loop.