<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Graph on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/graph/</link><description>Recent content in Graph on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Tue, 13 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/graph/index.xml" rel="self" type="application/rss+xml"/><item><title>LC - Floyds slow fast pointer</title><link>https://linkingmon.github.io/blog/coding/lc-floyd/</link><pubDate>Tue, 13 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-floyd/</guid><description>&lt;h2 id="detect-loop"&gt;Detect Loop&lt;/h2&gt;
&lt;p&gt;Recently I practice the topic for floyd&amp;rsquo;s fast slow pointer algorithm to detect loop.
The basic problem is that there is a link list with cycle (that is each node only points to at most one node), we can detect it by walking a fast pointer (do two &lt;code&gt;-&amp;gt;next&lt;/code&gt; per loop), and slow pointer (one &lt;code&gt;-&amp;gt;next&lt;/code&gt; at a time). In this case, there is a loop if two pointers can meet each other.&lt;/p&gt;</description></item><item><title>LC 1235 - Maximum Profit in Job Scheduling</title><link>https://linkingmon.github.io/blog/coding/lc-1235/</link><pubDate>Sat, 10 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-1235/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;this is a dp like problem, we maintain for each endTime what is the best profit, then for the next subproblem, we just combine the sub-solution for taking current interval or not. If we take hte current interval, we use the &lt;code&gt;upper_bound&lt;/code&gt; to get the best cost that end before the starting time of current interval, otherwise we take the privious solution.&lt;/p&gt;
&lt;p&gt;One part that we need to be careful with is the duplicated endTime, we need to maintain the max if there are multiple intervals with the same endTime.&lt;/p&gt;</description></item><item><title>LC 127 - Word Ladder</title><link>https://linkingmon.github.io/blog/coding/lc-127/</link><pubDate>Fri, 09 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-127/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;I was thinking a naive approach to build the graph for neighbor string first, and then try to do BFS. so the adjacency list part is TC &lt;code&gt;O(MN^2)&lt;/code&gt;, and the BFS part is &lt;code&gt;O(M)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I saw a different method and think that it has lower complexity (actually not). We put the beginning number into the queue for BFS, and its neighbor is having at most &lt;code&gt;O(25M)&lt;/code&gt; neighbors, since we can change one character among &lt;code&gt;M&lt;/code&gt; to any other 25 characters, and we only need to hash the &lt;code&gt;wordList&lt;/code&gt; and find if it is in the hash. If it is present in the hash we erase it and put it into the queue. In this case, all the element ahve at most &lt;code&gt;25M&lt;/code&gt; neighbor, and number of traversal is at most &lt;code&gt;N&lt;/code&gt;, but the complexity is still &lt;code&gt;O(M^2N)&lt;/code&gt; since hashing a length &lt;code&gt;M&lt;/code&gt; string is &lt;code&gt;O(M)&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>