• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Doubly Linked Lists Question

I have a class assignment and one of the algorithms we are to provide in our Doubly Linked List class is a reverse() function that will reverse the list in O(1) time. Just wondering how exaxctly that can be done?

Obviously O(N) would be simple (reversing each next and prev pointer) but I'm not too sure about doing it in a constant time

Any hints or help would be appreciative
 
The key to this problem is that there's really no need to physically "reverse" the list since it is a doubly linked list. You just need to know which "direction" you're going in.

There are a couple of different solutions to this problem, all of which will be O(1) but some will yield a higher O(N) constant during traversal (which your Professor is probably not concerned about).
 
Back
Top