Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

starting point of loop linked list proof

m => length from starting of list to starting of loop (i.e 1-2-3-4)
l => length of loop (i.e. 4-5-6-7-8-9)
k => length between starting of loop to meeting point (i.e. 4-5-6-7)

Total distance traveled by slowPtr = m + p(l) +k
where p => number of repetition of circle covered by slowPtr

Total distance traveled by fastPtr = m + q(l) + k
where q => number of repetition of circle covered by fastPtr

Since,
fastPtr running twice faster than slowPtr

Hence,
Total distance traveled by fastPtr = 2 X Total distance traveled by slowPtr
i.e
m + q(l) + k = 2 * ( m + p(l) +k )
or, m + k = q(l) - p(l)
or, m + k = (q-p) l
or, m = (q-p) l - k

So,
If slowPtr starts from beginning of list and travels "m" length then, it will reach to Point 4 (i.e. 1-2-3-4)

and
fastPtr start from Point 7 and travels " (q-p) l - k " length then, it will reach to Point 4 (i.e. 7-8-9-4),
because "(q-p) l" is a complete circle length with " (q-p) " times.
Comment

PREVIOUS NEXT
Code Example
Python :: Python-Generating numbers according to a corellation matrix 
Python :: File "script.py", line 1 import module math ^ SyntaxError: invalid syntax 
Python :: see python function details in vscode 
Python :: tessa thompson 
Python :: Random Hex Colors bar generator, python turtle 
Python :: cs50 templating urls 
Python :: instal django impoer expor 
Python :: japanese translator google 
Python :: value counts normalize 
Python :: value keys in dictionary are immutable true/false 
Python :: using django model translation with django rest 
Python :: subplots whitespace 
Python :: django models get all 
Python :: COMBINE TWO 2-D NUMPY ARRAYS WITH NP.VSTACK 
Python :: python project 
Python :: Django Signup urls.py 
Python :: how to set text in QComboBox pyqt5 
Python :: display all rows pandas 
Python :: plot by hour of day pandas 
Python :: Kinesis Client get_records response json 
Python :: python3 subprocess getoutput 
Python :: python .exe long start 
Python :: importing modules in kv lang 
Python :: select rainfall events and calculate rainfall event total from time-series data 
Python :: pandas select only earliest event for duplicates 
Python :: scrapy pass string as html 
Python :: graph bokeh 
Python :: how to search on wikipedia with python and speak the result 
Python :: Pouring 8 litres into 2 empty container of size 3 and 5 to get 4 litre in any container 
Python :: python move all txt files 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =