Answer Posted / sujith
Simultaneously go through the list by ones (slow iterator)
and by twos (fast iterator). If there is a loop the fast
iterator will go around that loop twice as fast as the slow
iterator. The fast iterator will lap the slow iterator
within a single pass through the cycle. Detecting a loop is
then just detecting that the slow iterator has been lapped
by the fast iterator.
This solution is "Floyd's Cycle-Finding Algorithm" as
published in "Non-deterministic Algorithms" by Robert W.
Floyd in 1967. It is also called "The Tortoise and the Hare
Algorithm"
Is This Answer Correct ? | 11 Yes | 2 No |
Post New Answer View All Answers
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
Is javascript written in c?
Write a program to find factorial of a number using recursive function.
How can a process change an environment variable in its caller?
With the help of using classes, write a program to add two numbers.
How can I delete a file?
What is spark map function?
What is adt in c programming?
Explain about the functions strcat() and strcmp()?
What are volatile variables in c?
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
What is huge pointer in c?
Write a program for finding factorial of a number.
write a program for the normal snake games find in most of the mobiles.
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory