1 / 48

Detecting a cycle

Detecting a cycle L Detecting a cycle L p Detecting a cycle L p stack Detecting a cycle L p stack Detecting a cycle L p Detecting a cycle p Cycle detected at p L Now restore the list using the saved pointers p L Restoring . . . L p Restoring . . . L p Restoring . . .

andrew
Télécharger la présentation

Detecting a cycle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Detecting a cycle L

  2. Detecting a cycle L p

  3. Detecting a cycle L p stack

  4. Detecting a cycle L p stack

  5. Detecting a cycle L p

  6. Detecting a cycle p Cycle detected at p L

  7. Now restore the listusing the saved pointers p L

  8. Restoring . . . L p

  9. Restoring . . . L p

  10. Restoring . . . L p

  11. Restoring . . . L p

  12. Restored! L

  13. How much time and space? L

  14. How much time and space? O(N)time p L O(N)space for stack

  15. Detecting a cyclewith two-speed pointers L p q

  16. Detecting a cyclewith two-speed pointers L p q

  17. Detecting a cyclewith two-speed pointers L p q

  18. Detecting a cyclewith two-speed pointers L p q

  19. Detecting a cyclewith two-speed pointers L p q

  20. Detecting a cyclewith two-speed pointers p L q

  21. Detecting a cyclewith two-speed pointers p L q

  22. Detecting a cyclewith two-speed pointers L p q

  23. Detecting a cyclewith two-speed pointers L p q

  24. Detecting a cyclewith two-speed pointers L Cycle detected p q

  25. How much time and space? L

  26. Two-speed method:a larger example

  27. Two-speed method:a larger example

  28. Two-speed method:a larger example

  29. Two-speed method:a larger example

  30. Two-speed method:a larger example

  31. Two-speed method:a larger example

  32. Two-speed method:a larger example

  33. Two-speed method:a larger example

  34. Two-speed method:a larger example

  35. Two-speed method:a larger example

  36. Two-speed method:a larger example

  37. Two-speed method:a larger example

  38. Two-speed method:a larger example

  39. Two-speed method:a larger example

  40. Two-speed method:a larger example

  41. Two-speed method:a larger example

  42. Two-speed method:a larger example

  43. Two-speed method:a larger example

  44. Two-speed method:a larger example

  45. Two-speed method:a larger example

  46. Two-speed method:a larger example Cycle detected!

  47. How much time and space?

  48. How much time and space? O(1)space O(N)time

More Related