Skip to content

Commit

Permalink
add cycle finding algo
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-bro committed Dec 18, 2023
1 parent 86892df commit b887164
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
34 changes: 34 additions & 0 deletions content-org/all-posts.en.org
Expand Up @@ -3944,6 +3944,40 @@ I use termux[fn:termux] to do these:
#+CAPTION: enable tcpip on the phone
[[file:../static/images/posts/connect-to-your-android-wirelessly/enable-tcpip-on-android.png]]

* DONE Cycle Finding Algorithms :cycle_finding:@Data_Structure_and_Algorithm:
CLOSED: [2023-12-19 Tue 00:27]
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: cycle-finding-algorithms
:EXPORT_FILE_NAME: index
:EXPORT_DATE: [2023-12-17 Sun 23:24]
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :image "/images/icons/TortoiseHare.jpg"
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :libraries '(mathjax)
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :description "this is a description"
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2023-12-19 Tue 00:27]
:END:

** Floyd's tortoise and hare


#+CAPTION: tortoise and hare
[[../static/images/posts/cycle-finding/tortoise-and-hare.svg]]

hare and tortoise both starts from point *Start*, at speed of $2$ and $1$ respectively. They'll meet at some point in the cycle.

when they meet, hare traveled $S_2 - S_{1}$ more points than tortoise. We have: ($\lambda$ is the cycle length)

$$
S_{2} - S_{1} = 0 = S_{1} = x + m \pmod{\lambda}
$$

after they meet, one starts over from Start point, the other starts from Meet point, at speed of $1$, they'll meet again at *Cycle Start* point. because:

$$
x = x + m + x \pmod{\lambda}
$$

* Footnotes

[fn:org-download] [[https://github.com/abo-abo/org-download][org-download]] facilitates moving images from point A to B.
Expand Down
28 changes: 28 additions & 0 deletions content/en/posts/cycle-finding-algorithms/index.md
@@ -0,0 +1,28 @@
+++
title = "Cycle Finding Algorithms"
date = 2023-12-19T00:27:00+08:00
tags = ["cycle-finding"]
categories = ["Data-Structure-and-Algorithm"]
draft = false
image = "/images/icons/TortoiseHare.jpg"
libraries = ["mathjax"]
description = "this is a description"
+++

## Floyd's tortoise and hare {#floyd-s-tortoise-and-hare}

{{< figure src="/images/posts/cycle-finding/tortoise-and-hare.svg" caption="<span class=\"figure-number\">Figure 1: </span>tortoise and hare" >}}

hare and tortoise both starts from point **Start**, at speed of \\(2\\) and \\(1\\) respectively. They'll meet at some point in the cycle.

when they meet, hare traveled \\(S\_2 - S\_{1}\\) more points than tortoise. We have: (\\(\lambda\\) is the cycle length)

\\[
S\_{2} - S\_{1} = 0 = S\_{1} = x + m \pmod{\lambda}
\\]

after they meet, one starts over from Start point, the other starts from Meet point, at speed of \\(1\\), they'll meet again at **Cycle Start** point. because:

\\[
x = x + m + x \pmod{\lambda}
\\]
Binary file added static/images/icons/TortoiseHare.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions static/images/posts/cycle-finding/tortoise-and-hare.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit b887164

@vercel
Copy link

@vercel vercel bot commented on b887164 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog-src – ./

blog-src-ky13.vercel.app
blog-src-git-master-ky13.vercel.app
k4i.top

Please sign in to comment.