data structures - Checking if the linked list is circular -


i reading tortoise , hare (slow , fast runner) algorithm here, don't understand why it's considered best solution.

wouldn't less time consuming this:

  • save root node

  • travel through linked list

  • at each new node, check if it's root node.

just realized circular list doesn't need connecting head. can have loop somewhere in middle. makes 2 "runners" necessary.

but if checking explicitly "snake eating own tail" kind of linked list, enough check equality of pointer root node, suggested before


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -