We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you don't care about the list after the program(like here) , you can reduce worst case complexity to O(N) and in other case O(k), where k is no. of nodes you have visited , it'll be better than O(100) and O(n^2).
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
If you don't care about the list after the program(like here) , you can reduce worst case complexity to O(N) and in other case O(k), where k is no. of nodes you have visited , it'll be better than O(100) and O(n^2).