<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kanishk Raj Tanwar on Medium]]></title>
        <description><![CDATA[Stories by Kanishk Raj Tanwar on Medium]]></description>
        <link>https://medium.com/@rajkanishk2709?source=rss-fe240ca2fc91------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4O2Fd5M45AF9V5YpIbO5Pg.jpeg</url>
            <title>Stories by Kanishk Raj Tanwar on Medium</title>
            <link>https://medium.com/@rajkanishk2709?source=rss-fe240ca2fc91------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:31:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajkanishk2709/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What Does It Mean To Color A Graph With (–1) Colors?]]></title>
            <link>https://thequantasticjournal.com/what-does-it-mean-to-color-a-graph-with-1-colors-b7904359e0a2?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7904359e0a2</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[discrete-mathematics]]></category>
            <category><![CDATA[combinatorics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 20:01:50 GMT</pubDate>
            <atom:updated>2026-11-20T04:42:08.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZFNK_tlnbZhbYT2fuYWsNA.png" /></figure><h4>How the chromatic polynomial connects an impossible coloring problem to the number of ways a graph’s edges can be directed without forming a cycle.</h4><p>At first glance, the title might sound completely absurd. How can we possibly color a graph with −1 colors? After all, coloring a graph means assigning colors to its vertices, and having a negative number of colors doesn’t seem to make any mathematical sense, but that’s exactly what makes this question so interesting.</p><p>In graph theory, we have something called the <em>chromatic polynomial</em>, which counts the number of ways to properly color a graph using <em>k</em> available colors. Naturally, this interpretation makes sense when<em> k</em> is a positive integer. But the chromatic polynomial is, after all, a polynomial, and nothing stops us from evaluating a polynomial at a negative integer, say <em>k</em>=−1.</p><p>So what happens when we do that? Is the result just some meaningless number, or is there something deeper hiding behind it?</p><p>Surprisingly, it turns out that if <em>Pɢ</em>(<em>k</em>) is the chromatic polynomial of a graph <em>G</em>, then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MR5DG72k6vbLuMLE637s0A.png" /></figure><p>This is a beautiful example of a much broader mathematical phenomenon known as <em>combinatorial reciprocity</em>, where evaluating a counting polynomial at negative integers reveals an entirely different combinatorial interpretation.</p><p>Let’s understand why this happens.</p><figure><img alt="Two undirected graphs shown side by side: G₁, a wheel graph with 7 vertices, and G₂, a cube graph with 8 vertices. Below each graph are its chromatic polynomial and the number of acyclic orientations: 726 for G₁ and 1,862 for G₂. Both satisfy Stanley’s theorem, which states that (−1)^|V(G)| P_G(−1) equals the number of acyclic orientations of G. The bottom of the image also defines the chromatic polynomial as the number of proper k-colorings of a graph." src="https://cdn-images-1.medium.com/max/1024/1*9HxY4mUvaAQ1jTKET8qBDQ.png" /><figcaption>Two graphs, G₁ and G₂, whose chromatic polynomials reveal 726 and 1,862 acyclic orientations, respectively, when evaluated at −1 with the appropriate sign correction.</figcaption></figure><p>To start off, what exactly is proper coloring? A coloring is proper if adjacent vertices receive different colors. As an example, suppose our graph is just one edge</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rMCgJtN0ad7KCQUSeQxpg.png" /></figure><p>If we have <em>k</em> colors, then in how many ways can we properly color this graph? Vertex <em>a</em> will have <em>k</em> choices; vertex <em>b</em> can use anything except <em>a</em>’s color, so it will have <em>k</em>−1 choices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pr73-nApgvkVF76S8hcug.png" /></figure><p>For the triangle <em>K</em>₃,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nPS6H_5-0H8FZ6G9ng-tg.png" /></figure><p>we will have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FdwZS6teQXmIh99A__P4A.png" /></figure><p>Originally, <em>Pɢ</em>(<em>k</em>) counts colorings only when <em>k</em>=1, 2, 3, …, but notice that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9AofDKXP-PWctyaMYNtXg.png" /></figure><p>This does not mean that there are −6 possible colorings; instead, the value of the polynomial at the negative integer turns out to encode another combinatorial object, which is called an <em>acyclic orientation</em>.</p><p>If you are new to this terminology: an ordinary graph edge <em>u</em>—<em>v </em>has no direction. An orientation would mean choosing one of the two possible directions: <em>u</em>→<em>v</em> or <em>u</em>←<em>v</em>.</p><p>We do this independently for each edge of our graph. If a graph has <em>m</em> edges, there are exactly 2<em>ᵐ</em> possible orientations, because every edge has two choices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/141/0*QjTJ_Vbc1Y6rNVly" /><figcaption>A directed cycle</figcaption></figure><p>An orientation of a graph is called acyclic if it contains no directed cycle. Such a directed graph is commonly called a <em>DAG</em> (directed acyclic graph).</p><p>The main claim of this article, which we will prove for finite simple graphs <em>G</em> (undirected graphs without loops or parallel edges), is that,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gtryfm3UH4tV1VObDmcsKA.png" /></figure><p>where <em>a</em>(<em>G</em>) denotes the number of acyclic orientations of <em>G</em>. This is actually known as Stanley’s theorem in the standard literature.</p><p>Let’s illustrate this with our triangle <em>K₃</em>: we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*myRX2oXOJMS9Afpb1TTpaw.png" /></figure><p>And the total number of acyclic orientations for <em>K₃</em> is actually 6. This makes sense since the triangle has 3 edges, so 2³ = 8 orientations are possible. Exactly two of them are directed cycles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/0*N5FO45BSFuRDwzBM" /></figure><p>So the remaining 8 − 2 = 6 orientations are acyclic. ∴ <em>a</em>(<em>K₃</em>) = 6.</p><p>To understand the proof of Stanley’s theorem, we need two graph operations:</p><p><strong>(<em>i</em>) </strong>Edge deletion: If an edge <em>e</em> is removed, the resulting graph is denoted as <em>G</em> − <em>e</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEjjVm2-WkJ3qIHUViWqQw.png" /></figure><p><strong>(<em>ii</em>) </strong>Edge Contraction: Contracting <em>e</em> = <em>uv</em> means merging <em>u</em> and <em>v</em> into a single vertex. If this produces parallel edges, we replace them with a single edge. The resulting graph is denoted as <em>G</em>/<em>e</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qc_deTL7nzN3cKvHsNH7xw.png" /></figure><p>Now there is a crucial identity for chromatic polynomials that is key to our proof:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZINXMlZkUiaC4G0nUAjuA.png" /></figure><p>How is this true? Suppose <em>e</em>=<em>uv</em>. Look at all proper colorings of <em>G</em>−<em>e</em>. Since the edge <em>uv</em> has been removed, <em>u</em> and <em>v</em> are allowed to have either different colors, or the same color.</p><p><strong><em>Case I</em>:</strong> If <em>u</em> and <em>v</em> have different colors, then putting the edge <em>uv</em> back causes no problem. So these colorings are precisely the proper colorings of <em>G</em>, i.e., <em>Pɢ</em>(<em>k</em>) .</p><p><strong><em>Case II</em>:</strong> If <em>u</em> and <em>v</em> have the same color, then we may imagine identifying <em>u</em> and <em>v</em> into a single vertex. But that is exactly what edge contraction does. Thus such colorings correspond to proper colorings of <em>G</em>/<em>e</em>. Therefore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMSxAGlBd7NhBMBRLlIwSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5HsPMd8PSdclEDDnEq1WA.png" /></figure><p>Let’s evaluate this identity at <em>k</em>=−1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R18N53revJPlnUmoWv7-3g.png" /></figure><p>Let <em>n</em> = |<em>V</em>(<em>G</em>)|. If we multiply both sides by (−1)ⁿ,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3aRYRJsJgnny46zegXxH3Q.png" /></figure><p>Since <em>G</em>/<em>e</em> has<em> n</em>−1 vertices, and −(−1)ⁿ = (−1)ⁿ⁻¹ :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Vdz2FG5hdoMLlXsOGfRig.png" /></figure><p>If we define <em>F</em>(<em>G</em>) as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8f_T1JumT2klzzqLyIF6Q.png" /></figure><p>we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pglhqhrwp70HyEk61zAQKw.png" /></figure><p>As a matter of fact, we will discover that the number of acyclic orientations will also satisfy exactly the same recurrence.</p><p>Let <em>a</em>(<em>G</em>) = number of acyclic orientations of <em>G</em>. We want to prove</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGZCRxRowD-PgjmFs1JmBQ.png" /></figure><p>Let’s take <em>e</em> = <em>uv</em>, and let’s start with an acyclic orientation of <em>G</em> − <em>e</em>. Then in how many ways can we put the missing edge uv back and orient it while remaining acyclic? There are two possibilities:</p><p><strong><em>i</em>)</strong> Suppose our orientation of <em>G</em> − <em>e</em> already contains a directed path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nc1LGWnjkeONp7oy_K0ZoQ.png" /></figure><p>(we can denote this as <em>u</em> ⇝ <em>v</em>). Then what happens if we insert <em>v</em> → <em>u</em>? We would obtain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ggkr8D_pMjb6d-Gad5PRUg.png" /></figure><p>which is a directed cycle, hence <em>v</em>→<em>u</em> is forbidden. But <em>u</em>→<em>v</em> is safe.<br>Therefore this orientation of <em>G</em>−<em>e</em> has exactly one valid extension to <em>G</em>. The same argument works if there is a path <em>v</em>⇝<em>u</em>.</p><p><strong><em>ii</em>)</strong> But what if there is no directed path either way? Suppose there is neither <em>u</em>⇝<em>v</em> nor <em>v</em>⇝<em>u</em>. Then we can insert <em>u</em>→<em>v</em> without creating a cycle. Why? A newly created cycle would have to use the new edge; if that cycle contained <em>u</em>→<em>v</em>, the rest of the cycle would provide a path <em>v</em>⇝<em>u</em>, but we assumed no such path exists! Similarly, <em>v</em>→<em>u</em> is also safe. So in this case we obtain <em>two</em> orientations of <em>G</em>.</p><p>Thus, some orientations of <em>G</em>−<em>e</em> contribute 1 to <em>a</em>(<em>G</em>), and some others contribute 2. Consequently,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0EMXFt4vKgCNSvABe5u6iw.png" /></figure><p>The brilliant observation is that <em>the number of acyclic orientations of G−e with no path between u, v is exactly a(G/e)</em>.</p><p>How?—Suppose we have an acyclic orientation of <em>G</em>−<em>e</em> in which neither <em>u</em>⇝<em>v</em> nor <em>v</em>⇝<em>u</em>. Now identify <em>u</em> and <em>v</em> into one vertex, which is precisely the contraction <em>G</em>/<em>e</em>.</p><p>Could contraction create a directed cycle? Suppose it did, in which case the new cycle would necessarily pass through the contracted vertex. This would mean that before contraction, that cycle would have been a directed path by either</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGNx_YoWGxZ3eRIgJnfn5g.png" /></figure><p>But by assumption neither exists, which is a contradiction.</p><p>Conversely, starting with an acyclic orientation of <em>G</em>/<em>e</em>, we may split the contracted vertex back into u and v. The resulting orientation of <em>G</em>−<em>e</em> cannot contain a directed path <em>u</em>⇝<em>v</em> or <em>v</em>⇝<em>u</em>, because contracting such a path would turn it into a directed cycle in <em>G</em>/<em>e</em>.</p><p>Thus these two collections correspond to one another. Hence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGZCRxRowD-PgjmFs1JmBQ.png" /></figure><p>So we have proved that <em>F</em>(<em>G</em>) and<em> a</em>(<em>G</em>) satisfy the same recursive rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ugbBkDQ3ZafsaX3PtgPabQ.png" /></figure><p>If two quantities satisfy the same recursion and the same base cases, then they <em>are</em> the same quantity. Let’s prove this via induction on the number of edges.</p><p>(i) For the base case, suppose <em>G</em> has <em>n</em> vertices but no edges. Then every vertex may independently receive any of the <em>k</em> colors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Nj6W8WvScFWp2CacPAdow.png" /></figure><p>What about acyclic orientations? There are no edges to orient, and there is exactly one orientation: the empty choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YyScl5iAY_irWQbB9XW5xg.png" /></figure><p>In the inductive step, assume the statement is true for every graph with fewer than <em>m</em> edges. Now let <em>G </em>have <em>m</em> edges and choose some edge <em>e</em>.<br>Both <em>G</em>−<em>e</em> and <em>G</em>/<em>e</em> are smaller graphs, so by the induction hypothesis,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjsVFdWyJROzy4sFgdeuAw.png" /></figure><p>Therefore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hLRdNm6kqJrjciNOTPflgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6CD4Yd5t0bMJcrDkSBLffQ.png" /></figure><p>Let’s look at another nice special case where this works, i.e., on trees. Let <em>T</em> be a tree on <em>n</em> vertices. Its chromatic polynomial is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jXVPMdjNerkDRZGVd5VOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ab5w2wl-0K--aqS9Map0lQ.png" /></figure><p>Since this tree contains <em>n</em>−1 edges, and because it is acyclic by definition, no choice of arrow directions can ever produce a directed cycle. Every edge can independently face one of two ways. Therefore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgZhFofC23IJMxqBmKmp0A.png" /></figure><p>which is consistent with Stanley’s theorem.</p><p>This theorem is one of the classic examples of combinatorial reciprocity. In many combinatorial reciprocity theorems, a polynomial that counts one family of objects at positive integers reveals a different, but closely related, family of objects when evaluated at negative integers.</p><h4><strong>References</strong></h4><ol><li>Stanley, Richard P. (1973). “<a href="https://math.mit.edu/~rstan/pubs/pubfiles/18.pdf">Acyclic Orientations of Graphs.</a>” Discrete Mathematics, 5(2), 171–178.</li><li>Beck, Matthias, and Raman Sanyal. (2019). <a href="https://page.mi.fu-berlin.de/sanyal/teaching/crt/CRT-Book-Online.pdf">Combinatorial Reciprocity Theorems: An Invitation to Enumerative Geometric Combinatorics.</a> American Mathematical Society, Graduate Studies in Mathematics, Vol. 195.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7904359e0a2" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/what-does-it-mean-to-color-a-graph-with-1-colors-b7904359e0a2">What Does It Mean To Color A Graph With (–1) Colors?</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Surprising Connection Between The Tower Of Hanoi And The Sierpiński Triangle]]></title>
            <link>https://medium.com/data-science-collective/a-surprising-connection-between-the-tower-of-hanoi-and-the-sierpi%C5%84ski-triangle-aa45fe1adc14?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa45fe1adc14</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 21:34:59 GMT</pubDate>
            <atom:updated>2026-11-20T04:56:27.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwJ1YPWnZROEuf56-OhLFg.png" /></figure><p>Surprisingly, there is a close connection between the Tower of Hanoi problem and the Sierpiński Triangle. This was first discovered by Ian Stewart in 1989. In computer science, many problems can be represented as a <strong><em>state-space graph, </em></strong>where each vertex represents a possible state of a system, while the edges represent allowed transitions between states. Once we have such a graph, questions about solving the puzzle turn into familiar graph problems: for instance, it could turn into a reachability or a shortest path problem.</p><p>Let me first describe the Tower of Hanoi problem: Suppose we have three pegs A, B, C and n disks numbered 1, 2, …, n, where disk 1 is the smallest and disk n is the largest. The rules are to move only one disk at a time, and only the top disk of a peg can move. Usually we’re asked to move A → C, using B as needed. <br>A move is valid exactly when<br>(i) You move one disk at a time. <br>(ii) It is the top disk of its current peg. <br>(iii) You place it on an empty peg or on top of a larger disk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58zZDEVcSie8YYBxXS7v0w.png" /><figcaption>A bit of a summary of what we will discuss in this article: on the top-left, we have the Tower of Hanoi puzzle having 3 disks, along with its state graph H₃ on the top-right. Below them are the formulas that we will discuss.</figcaption></figure><p>We can represent the Tower of Hanoi puzzle as a graph by considering every possible valid arrangement of its disks. In the graph, each vertex will represent one valid configuration and an edge will connect two vertices exactly when one valid move takes us from one configuration to the other.<br>For example, with one disk, there are only three configurations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pk-cwNY5xIC-SEKVXeyJVg.png" /></figure><p>The disk can move directly between any two pegs, so every pair of vertices is connected. The resulting graph is a triangle</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwdr3tF-B8WqsP226LjhAA.png" /></figure><p>A sequence of legal moves corresponds to a walk through this graph, and solving the puzzle in the fewest moves means finding a shortest path from the starting configuration to the target configuration.</p><p>Let’s see what happens for two disks. With two disks, we represent each configuration by an ordered pair (x₂, x₁) where x₂ is the position of the large disk and x₁ is the position of the small disk. Each xᵢ can be A, B or C. So there are 3 × 3 = 9 possible configurations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZrBKJCFsfY9F19GWL7pAQ.png" /></figure><p>All nine are valid: when the disks share a peg, the small disk sits above the large one. We can group these configurations according to the large disk’s position:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtHkG4f9cbmqIwjDVxo0cA.png" /></figure><p>Within each group, the large disk stays fixed while the small disk can move freely between all three pegs. Every pair of configurations in that group is therefore connected by an edge, forming a triangle. Thus, the two-disk graph contains three copies of the one-disk graph.<br>To connect these triangles, we must move the large disk. Suppose we want to move it from A to B: <br>(i) The small disk cannot be on A, because then it would cover the large disk. <br>(ii) The small disk cannot be on B, because then the large disk cannot be placed on top of it. <br>(iii) Therefore, the small disk must be on C.<br>This gives the edge AC ↔ BC. Applying the same reasoning to the other pairs of pegs gives exactly three edges between the groups, i.e., AC ↔ BC, AB ↔ CB and BA ↔ CA. The complete graph looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgQBFPxeCs7Pkb_XQuRGSQ.png" /></figure><p>With three disks, we represent each configuration by (x₃, x₂, x₁) and there are 27 configurations. For the largest disk, i.e., disk 3, there are three possibilities: A, B or C.</p><p>Suppose disk 3 stays on A, then disk 1 and 2 can do whatever a normal 2-disk Tower of Hanoi can do. So this part of the graph is exactly a copy of the 2-disk graph. The same logic applies if the largest disk is on B or C.</p><p>Let Hₙ denote the Tower of Hanoi graph with n disks. Then H₃ consists of three copies of H₂, joined by moves of the largest disk.<br>To move the largest disk from A to B: <br>(i) Neither smaller disk can be on A, because the largest disk must be uncovered. <br>(ii) Neither smaller disk can be on B, because the largest disk cannot be placed on a smaller disk. <br>(iii) Therefore, both smaller disks must be stacked on C.<br>This gives the connecting edge ACC ↔ BCC. Similarly, we get ABB ↔ CBB and BAA ↔ CAA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axcCjQLnXs17_hhqKnNnTA.png" /></figure><p>The same reasoning continues for n ≥ 3; Hₙ consists of three copies of Hₙ₋₁, joined by three edges. If we notice carefully, this repeated arrangement of three smaller copies resembles the construction of the Sierpinski Triangle. In fact, the n-disk Tower of Hanoi graph is <strong><em>isomorphic</em></strong> to the corresponding finite Sierpiński graph: the vertices can be matched so that legal Hanoi moves correspond exactly to edges of the Sierpiński graph.</p><p>The cool thing is that from this graph we can easily find the minimum number of moves in which the puzzle can be solved.<br>Suppose we want to go from the extreme corner Aⁿ = AAA…A to Cⁿ = CCC…C. Then the shortest path will have exactly this shape:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uNZ1w1zar094GKicRUUljg.png" /></figure><p>Going from Aⁿ → ABB…B is an (n − 1)-disk corner-to-corner problem. Going from ABB…B → CBB…B takes just one edge. The last piece CBB…B → Cⁿ is another (n − 1)-disk corner-to-corner problem. If Lₙ is the corner-to-corner distance, the geometry therefore forces</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1eF3w0Jr28XIBoW5JKSJA.png" /></figure><p>Solving this, we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KphsFgDAb7YafYdYXLzZtw.png" /></figure><p>which is exactly the <em>minimum number of moves needed to transfer an n-disk tower from one peg to another in the standard Tower of Hanoi puzzle.</em></p><p>How many edges does the whole Hanoi graph have? By observation, it can be described by the recurrence relation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*19RsuFoyATU2VtjRY35PMg.png" /></figure><p>solving it gives</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpEEGolo1wmeATdTYF8_8g.png" /></figure><p>which is also the <em>total number of valid moves available to us in the n-disk puzzle.</em></p><p>There are a few more interesting relations that are related to this puzzle we can derive about this puzzle. If Sₙ is the total sum of the shortest-path lengths over every ordered pair of configurations, then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vyttHcAtHVEgALVGP4EgaQ.png" /></figure><p>and the average distance between two independently chosen random configurations will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jf_QoXRmt4JC2ihaWpudAg.png" /></figure><p>So two random Hanoi states are, on average, roughly (0.5266)2ⁿ moves apart.<br>How did we get that large formula for Sₙ ? Notice that the first few values are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3mWS0ejF5HXGDEYG_Z4qg.png" /></figure><p>It turns out that the sequence satisfies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtAN5N8JEf36caZbYL0UJg.png" /></figure><p>And how was this recurrence derived in the first place? Well, that is a whole another topic of discussion maybe best suited for some other article, but we can derive the general formula of Sₙ from this recurrence.<br>How? We package the entire sequence S₀, S₁, S₂, S₃, … into one formal power series;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fDpPRMIy09srI1zy3M131Q.png" /></figure><p>where the coefficient of zⁿ stores Sₙ. We have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2M5toLRDt7xpBDThZu537g.png" /></figure><p>If we multiply both sides by zⁿ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKyYQj1UoFlkRIrCW5Vn1Q.png" /></figure><p>Summing this for every n ≥ 5:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fd-UQoiKFT699Nep56r-rw.png" /></figure><p>From (1), we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYAcgcAH0OQ2vVDlgvPB9A.png" /></figure><p>Using the initial values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqFOEVm0IXoY_60ksigoeg.png" /></figure><p>Since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VarZz8tsHvtsSfrC8_M-g.png" /></figure><p>If we put m = n − 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Gkp5ZBXqh9CvuteaeHWzw.png" /></figure><p>But</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqzJwZuGRkEtwScpZE_-lw.png" /></figure><p>We will do the same for the remaining shifts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9U-louERfRz5mhJqNHWXw.png" /></figure><p>Substituting all this in equation (2), we will see</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ex5alkPSrVSDu5tRr08DPw.png" /></figure><p>If we calculate everything carefully, we’ll get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ReK-zLeJuea_8E5eoKUuMw.png" /></figure><p>Performing its partial fraction decomposition gives us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7w58oNeNyHAKIFHp0Qxygw.png" /></figure><p>Since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jq7zgqjafjLO1pwQUvhC7Q.png" /></figure><p>Therefore the coefficient of zⁿ is exactly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zj_Tew3yMK7tqD6zmHzeew.png" /></figure><p>which is precisely the desired formula for Sₙ.</p><h3>References</h3><ol><li>Stewart, I. (1992). “The Lion, the Llama, and the Lettuce.” In <a href="https://books.google.com/books?id=u5GPE97-ZhsC"><em>Another Fine Math You’ve Got Me Into…</em></a> W. H. Freeman.</li><li>OEIS Foundation Inc. “<a href="https://oeis.org/A290004">A290004 — Wiener Index of the n-Hanoi Graph.</a>” <em>The On-Line Encyclopedia of Integer Sequences</em>. Accessed 7 October 2026.</li><li>Romik, D. (2006). “<a href="https://arxiv.org/abs/math/0310109">Shortest paths in the Tower of Hanoi graph and finite automata.</a>”</li><li>Weisstein, E. W. “<a href="https://mathworld.wolfram.com/TowerofHanoi.html">Tower of Hanoi.</a>” <em>MathWorld — A Wolfram Resource</em>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa45fe1adc14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-collective/a-surprising-connection-between-the-tower-of-hanoi-and-the-sierpi%C5%84ski-triangle-aa45fe1adc14">A Surprising Connection Between The Tower Of Hanoi And The Sierpiński Triangle</a> was originally published in <a href="https://medium.com/data-science-collective">Data Science Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Hidden Divisibility Pattern in Pythagorean Triples]]></title>
            <link>https://thequantasticjournal.com/a-hidden-divisibility-pattern-in-pythagorean-triples-938571ea6422?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/938571ea6422</guid>
            <category><![CDATA[geometry]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[recreational-mathematics]]></category>
            <category><![CDATA[pythagoras]]></category>
            <category><![CDATA[number-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 14:57:42 GMT</pubDate>
            <atom:updated>2026-11-20T05:01:14.254Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Scatter plot of integer right triangles, with each Pythagorean triple shown as a point at coordinates (a, b). Primitive triples are highlighted in orange and non-primitive scaled multiples in blue. The points align along many straight rays extending outward from the origin." src="https://cdn-images-1.medium.com/max/1024/1*Zna3-c0NlEiaFHRZM_L2Rg.png" /><figcaption>Scatter plot of Pythagorean triples. Each point is a Pythagorean triple, with its two legs read off as the coordinates <em>a</em> and <em>b</em>. Orange marks the primitive triples- the ones in lowest terms, like 3‑4‑5, while blue marks their scaled multiples. Because every multiple of a triple lies on the same line through the origin, the whole family of solutions organizes itself into radiating rays.</figcaption></figure><p>It turns out that for any integer right triangle with sides <em>a</em>, <em>b</em>, <em>c</em>, the product <em>abc</em> will be a multiple of 60. Honestly, at first glance I felt this result was deeply counterintuitive; there is no obvious geometric reason why a right triangle’s sides should inherently link to the number 60. But it does, and it is very surprising.</p><p>This is actually a classical property of Pythagorean triples (see MacHale and van den Bosch [<a href="https://doi.org/10.1017/S0025557200004010">1</a>]). There’s a standard modular arithmetic approach to prove this result: for a primitive Pythagorean triple (<em>a</em>, <em>b</em>, <em>c</em>), if one can prove separately that 3|<em>abc</em> , 4|<em>abc</em> and 5|<em>abc</em>, then 60|<em>abc</em>, since 3, 4 and 5 are pairwise coprime. Doing so will require us to go through various congruence arguments. However, there is a more interesting and elegant approach which involves Euclid’s parametrization of primitive Pythagorean triples, which I will demonstrate now.<br><em>(Note: The equations may not render as clearly in Medium’s dark mode and are best viewed in light mode.)</em></p><p>Suppose <em>a</em>, <em>b</em>, <em>c</em> are positive integers satisfying <em>a² + b² = c²</em>. We want to prove that 60<em>|abc</em> (meaning 60 divides <em>abc</em>).</p><p>It is enough to consider a primitive Pythagorean triple, meaning <strong>gcd</strong><em>(a,b,c)=1</em>. If the triple is not primitive, we can write <em>(a,b,c)=d(a₀,b₀,c₀)</em>, where <em>(a₀,b₀,c₀)</em> is primitive and <em>d=</em><strong>gcd</strong><em>(a, b, c) </em>is a positive integer greater than 1. Then <em>abc=d³a₀b₀c₀</em>, so if <em>60|a₀b₀c₀</em>, then automatically <em>60|abc</em>.</p><p>Now we use the classical parametrization of primitive Pythagorean triples. Every primitive Pythagorean triple, after interchanging the two legs if necessary, has the form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JVEi6JNrXpPpHChl2Bb6dA.png" /></figure><p>for some integers <em>m&gt;n&gt;0</em>, with <em>m</em> and <em>n</em> coprime and of opposite parity. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDhpI80vn99MkXRfCmLn1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60vQZ1_2wraFoxFHMM03Cg.png" /></figure><p>Notice that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4aAJ_a7xvz1kZjgYpCafg.png" /></figure><p>Now here’s the key fact of our entire argument: 30<em>|x⁵−x</em> for every integer <em>x</em>. How? If we factor <em>x⁵−x</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTggXnbwoO2nEhuYbMCh5Q.png" /></figure><p><em>x−</em>1, <em>x</em>, and <em>x+</em>1 are three consecutive integers. Among any three consecutive integers, at least one is even and exactly one is divisible by 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QVCPO-vN1EuewW9S22AWg.png" /></figure><p>Also, Fermat’s little theorem says that for any prime number <em>p</em> and any integer <em>x</em>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zfMpGeXJwiYYN38QyEPcrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Ytom6HgCOog7SY4emMTMg.png" /></figure><p>Since 2, 3, and 5 are pairwise coprime, it follows that 30<em>|x⁵−x</em>. Thus both <em>m⁵−m</em> and <em>n⁵−n</em> are multiples of 30. Any integer linear combination of them is therefore also a multiple of 30.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cB8k_3MM3bvOpotqX-k0gA.png" /></figure><p>But that expression is <em>abc</em>/2. Thus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_K49aehTlNyIjlJG2_9Kw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WquBSGso-PaU-ewoNa1a3g.png" /></figure><p>This proves our statement. From the proof, one can clearly observe why the number 60 appears: the parametrization gives</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SoFpofOX8Bwqjd63jIMmNQ.png" /></figure><p>so one factor of 2 is already sitting in front of us. The remaining part, <em>mn</em>(<em>m</em>⁴−<em>n</em>⁴), can be rewritten using <em>m</em>⁵−<em>m</em> and <em>n</em>⁵–<em>n</em>, and every number of the form <em>x</em>⁵–<em>x</em> is divisible by 30=2⋅3⋅5. So the factor 60 emerges directly from the arithmetic structure of the parametrization.</p><p>In fact, 60 is not merely a divisor that happens to work- it is the largest integer that can divide the product of the sides of every Pythagorean triangle. The 3–4–5 triangle already has product exactly 60, so no larger universal divisor is possible.</p><p>Number theory never fails to amaze me. There is one more reason why the expression we obtained for <em>abc</em> is interesting. It leads directly to a simple question about Pythagorean triples that is still open:</p><blockquote><strong><em>Can two genuinely different primitive Pythagorean triples have exactly the same product of their sides?</em></strong></blockquote><p>Suppose one primitive triple is generated by parameters <em>m</em>, <em>n</em>, and another by <em>r</em>, <em>s</em>. Their side products are 2<em>mn</em>(<em>m</em>⁴−<em>n</em>⁴) and 2<em>rs(r⁴</em>−<em>s⁴). I</em>f the two products were to be equal, we would need</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QUT3UrNtVNVGdMdGAFGfHw.png" /></figure><p>In other words, we are asking whether two genuinely different choices of the parameters can produce exactly the same integer. The pairs (<em>m</em>,<em>n</em>) and (<em>r</em>, <em>s</em>) must each satisfy the usual conditions for primitive Pythagorean triples: the two numbers are coprime, have opposite parity, and the first is larger than the second.</p><p>So what began as a simple question about right triangles has turned into a <strong><em>Diophantine equation</em></strong>, i.e,<strong><em> </em></strong>a polynomial equation with integer coefficients for which we seek integer solutions. In expanded form, the equation is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4PLPo7U0vKLn960B27s1Q.png" /></figure><p>Every term has total degree six, so this is a sextic equation in four integer variables.<br>No such pair of distinct primitive Pythagorean triples is currently known, and it is still unknown whether one exists at all. <a href="https://oeis.org/A063011">OEIS A063011</a> still lists this as an open problem.</p><p>In fact, the question remains open even if we allow nonprimitive triples (see <a href="https://oeis.org/A057096">OEIS A057096</a>). In the general case, a Pythagorean triple is a scaled primitive one, so if the primitive triple generated by <em>m</em>, <em>n </em>is scaled by a factor <em>k</em>, its sides become</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CL7nkoynTbVHPSAj88nqdQ.png" /></figure><p>and their product is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sfy24vlucIzQ7iu8faTC8g.png" /></figure><p>If another triple, generated from <em>r</em>, <em>s</em>, is scaled by a factor <em>ℓ</em>, then equal side-products would require</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1l0B6wntmXKqEYztBvBNeA.png" /></figure><p>which is a homogeneous Diophantine equation of total degree 9 in the six integer variables<em> k</em>, <em>ℓ</em>, <em>m</em>,<em> n</em>, <em>r</em>, <em>s</em> together with the usual coprimality and opposite-parity conditions on <em>m</em>, <em>n </em>and<em> r</em>, <em>s</em>. The primitive equation is just the special case when <em>k</em>=<em>ℓ</em>=1.</p><h4>References</h4><ol><li>Des MacHale and Christian van den Bosch, “<a href="https://doi.org/10.1017/S0025557200004010">Generalising a result about Pythagorean triples</a>,” The Mathematical Gazette 96 (2012), 91–96.</li><li>Ravi P. Agarwal, “Pythagorean Triples before and after Pythagoras,” <em>Computation</em>, Vol. 8, No. 3, Article 62, 2020. DOI: <a href="https://doi.org/10.3390/computation8030062">10.3390/computation8030062</a>.</li><li>OEIS Foundation Inc., <a href="https://oeis.org/A063011">A063011 — Ordered products of the sides of primitive Pythagorean triangles.</a></li><li>OEIS Foundation Inc., <a href="https://oeis.org/A057096"><em>A057096 — Saint-Exupéry numbers: ordered products of the three sides of Pythagorean triangles</em>.</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938571ea6422" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/a-hidden-divisibility-pattern-in-pythagorean-triples-938571ea6422">A Hidden Divisibility Pattern in Pythagorean Triples</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Shortest Paths Using The Adjacency Matrix]]></title>
            <link>https://thequantasticjournal.com/finding-shortest-paths-using-the-adjacency-matrix-44e82802fdf2?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/44e82802fdf2</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[graph-spectral-theory]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Wed, 16 Sep 2026 14:47:37 GMT</pubDate>
            <atom:updated>2026-11-20T04:07:35.280Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A colorful undirected graph on a black background, with one path highlighted in yellow across the network." src="https://cdn-images-1.medium.com/max/1024/1*zx_5y2PjxGpFE9k2CT2iGw.png" /></figure><p>Suppose that we are given a finite, simple, undirected graph <em>G</em> having <em>n</em> vertices. One of the most natural questions we can ask about the graph is:</p><blockquote><strong><em>What is the shortest path between any two vertices in the graph? And how much would that shortest distance be?</em></strong></blockquote><p>It turns out that we can answer these questions using the adjacency matrix of our graph.</p><figure><img alt="A nine-vertex undirected graph shown with its adjacency matrix A and shortest-distance matrix D, together with the formula that recovers graph distances from powers of A." src="https://cdn-images-1.medium.com/max/1024/1*U_R0ukiUBTJ0Pqi310TKiQ.png" /><figcaption>A graph G with nine vertices shown alongside its adjacency matrix A and shortest-distance matrix D. The shortest distance between any two vertices i and j can be determined from powers of the adjacency matrix, using the first power <em>Aᵏ </em>for which <em>(Aᵏ)ᵢⱼ &gt; 0.</em></figcaption></figure><p>The adjacency matrix <em>A = </em>(<em>A</em>)<em>ᵤᵥ ∈ </em>{0<em>, </em>1}<em>ⁿ˟ⁿ </em>is defined as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FyEf4zTmHTf7t2BeFPIQQ.png" /></figure><p>The first key thing to note is that the (<em>u,v</em>)-th element of <em>Aᵏ</em> will give us the number of walks of length <em>k</em> from vertex <em>u</em> to vertex <em>v</em>. Why is this true? Think about what happens during matrix multiplication:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oLv-1ahUZF_JDaoqxqioCw.png" /></figure><p>Look at <em>AᵤₓAₓᵥ</em>. Since each factor is either 0 or 1,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2N4n_MfHYZN8g7zYjgdXGg.png" /></figure><p>exactly when both <em>u ～ x</em> and <em>x ～ v</em>, meaning that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBzMiFzbme7PVjC1S7f69g.png" /></figure><p>is a valid walk of length 2. So every possible intermediate vertex <em>x</em> contributes 1 if it gives a valid length-2 walk and 0 otherwise. Therefore,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIRuGbgALYNqnBBrmfO8tg.png" /></figure><p>In general, (<em>Aᵏ</em>)<em>ᵤᵥ</em> counts the number of walks of length <em>k</em> from <em>u</em> to <em>v</em>. We can prove this statement by the principle of mathematical induction. (For the whole proof, please see my article on <a href="https://medium.com/@rajkanishk2709/hidden-information-in-adjacency-matrices-ff1c82cfc32b?sharedUserId=rajkanishk2709">Hidden Information In Adjacency Matrices</a>.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzAuGe1wE2UdbuQDUYdz2A.png" /></figure><p>Now suppose we want the shortest distance from<em> s</em> to<em> t</em>. For that, we calculate <em>A, A², A³, …</em> and we inspect the entry corresponding to <em>s, t</em>. Suppose we obtain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7jfZHkt5hy0ki9M2KFcqA.png" /></figure><p>This means that there is no walk of length 1 and length 2, but there is at least one walk of length 3. Therefore the shortest possible length is<em> </em>3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lo49CmDhG0LptGIv779rrg.png" /></figure><p>In general,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ezexQVATA3HTw6smI_nTQ.png" /></figure><p>So the smallest <em>k</em> for which (<em>Aᵏ</em>)<em>ᵤᵥ </em>&gt;<em> </em>0 will be the shortest-walk distance between <em>u</em> and <em>v</em>, measured in number of edges.</p><p>But <em>Aᵏ </em>actually counts walks, not paths. A walk may repeat vertices. For example, <em>A−B−C−B−C−D</em> is a walk but it is not a simple path because <em>B</em> and <em>C</em> repeat.<br>It turns out that we don’t have to worry about it, because <strong><em>finding the shortest walk between two vertices will always give us the shortest path</em></strong>.<br>How? Suppose a shortest walk from <em>s</em> to <em>t</em> repeats some vertex <em>x. </em>Then it looks schematically like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oeQ1fsncdEb0xm_6ylHjAQ.png" /></figure><p>Since we return to <em>x</em>, the middle portion forms a closed loop. Deleting that loop will still keep it a valid walk. Then we obtain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DuXQ-Lu7zeSC8T8_KOXHGA.png" /></figure><p>with fewer edges. But this contradicts our assumption that our original walk was shortest. Therefore a shortest walk cannot repeat a vertex- hence it is a path.</p><p>We can now state the result cleanly. For distinct connected vertices <em>i</em> and <em>j</em>, the shortest-path distance <em>d</em>(<em>i, j</em>) is given by the formula</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bScjRgCH1hsKZIHbCywt5w.png" /></figure><p>If (<em>Aᵏ</em>)<em>ᵢⱼ </em>= 0 for every <em>k</em>, then no path connects them. They lie in different connected components and one often writes <em>d</em>(<em>i, j</em>)<em>=∞</em> . (We won’t actually have to calculate infinitely many powers of <em>A</em>, because if a graph has <em>n</em> vertices, every shortest path will have at most n-1 edges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2V16TXhxDMfirqTH0ChOw.png" /></figure><p>So it is enough to examine <em>A, A², A³, …, Aⁿ⁻¹.</em>)</p><p>This gives us a way to construct the entire shortest distance matrix <em>D</em>, where <em>Dᵢⱼ</em> represents the shortest-path distance between vertices <em>i </em>and <em>j</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ys8rUfbEQRVVLN2wqaX63g.png" /></figure><p>As an example, for the graph <em>A−B−C−D</em>, we will have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCVaqZX1hjlBEU5TRBpTtQ.png" /></figure><p>So far we know the shortest distances. But how can we recover the path itself?</p><p>Suppose we know <em>d</em>(<em>s,t</em>)=<em> k</em>. We are standing at <em>s</em>, and we want to know which neighbour to move to. <strong><em>Then, a neighbour u of s lies on a shortest s-t path exactly when</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Foo88AEutYTgt0B8IPZPdQ.png" /></figure><p>Why should the distance decrease by exactly <em>1</em>? Suppose <em>d</em>(<em>s,t</em>)<em>=k</em> and imagine the shortest path is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWVe916Yx4Y0XDtSK3zqbg.png" /></figure><p>The first edge is<em> v₀v₁</em> , so<em> v₁</em> is a neighbour of <em>s</em>. The remaining portion is <em>v₁, v₂, … , vₖ .</em> It has <em>k˗1</em> edges, therefore <em>d</em>(<em>v₁,t</em>)<em>≤k˗1</em>. But could it be even smaller? Suppose <em>d</em>(<em>v₁ ,t</em>)<em>&lt;k˗1</em>. Then there would be some path from<em> v₁</em> to <em>t</em> shorter than<em> k˗1</em>. Prepend the edge <em>s — v₁</em>. Then we would obtain an s-to-t path of length less than <em>1+</em>(<em>k˗1</em>)<em> </em>=<em> k.</em></p><p>But <em>k</em>=<em>d</em>(<em>s,t</em>) was supposed to be the shortest. This is a contradiction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kiaryZP9CEtmVW4zXfNxnQ.png" /></figure><p>Conversely, why does decreasing by 1 guarantee a shortest path? Suppose <em>u</em> is a neighbour of <em>s</em>, and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Foo88AEutYTgt0B8IPZPdQ.png" /></figure><p>Let <em>d</em>(<em>s,t</em>)=<em>k</em>. Then <em>d</em>(<em>u,t</em>)=<em>k˗1</em>. Since <em>s</em> and <em>u</em> share an edge, travel <em>s→u</em>. Then follow a shortest path from <em>u</em> to<em> t</em>, which has length <em>k˗1</em>. The total length is therefore <em>1+</em>(<em>k˗1</em>)<em>=k</em>.</p><p>But <em>k=d</em>(<em>s,t</em>). Hence this constructed path is the shortest. Therefore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9JXTt2j5MRKfpHy7Pg_CJg.png" /></figure><p>is both necessary and sufficient for <em>u</em> to be a valid next vertex on some shortest path.</p><p>So the algorithm for finding the shortest path becomes:</p><p><strong><em>Step 1</em></strong>: Compute <em>A, A², A³, …, Aⁿ⁻¹</em>.</p><p><strong><em>Step 2: </em></strong>For every pair <em>i, j,</em> set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ys8rUfbEQRVVLN2wqaX63g.png" /></figure><p>This will construct our shortest distance matrix.</p><p>If <em>Dₛₜ</em>=∞, then no path from <em>s</em> to <em>t</em> exists and the reconstruction stops here. Otherwise continue.</p><p><strong><em>Step 3: </em></strong>Suppose we want the shortest path from<em> s</em> to <em>t</em>. Start at <em>s</em>. Set <em>v </em>= <em>s</em>.</p><p><strong><em>Step 4: </em></strong>Repeatedly select a neighbour <em>u</em> satisfying</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vvyjLwaBcCW5Jxs0wQh83A.png" /></figure><p>where <em>v</em> is your current vertex. Then set <em>v </em>=<em> u</em>.</p><p><strong><em>Step 5: </em></strong>Continue until <em>Dᵥₜ </em>=<em> </em>0. Then <em>v </em>=<em> t</em>, and we will have recovered the shortest path.</p><p>Note that this approach is different from the Floyd-Warshall algorithm, which is the standard algorithm for the all-pairs shortest-path problem, and uses dynamic programming to progressively improve a distance matrix by allowing more vertices to act as intermediate points. It has a time complexity of O(n³). For ordinary unweighted graphs, breadth-first search is usually preferable. Our approach is less efficient computationally, having a time complexity of O(n⁴) when the successive matrix powers are computed using ordinary matrix multiplication, but here the aim is to rather provide a more algebraic perspective on how graph distance is encoded in the adjacency matrix, and to emphasize the underlying mathematical structure that is present here.</p><p>There’s one more scenario to discuss: suppose <em>d</em>(<em>s,t</em>)=<em>k</em> and <em>s</em> has two neighbours <em>a, b </em>satisfying <em>d</em>(<em>a,t</em>)<em>=k˗</em>1 and <em>d</em>(<em>b,t</em>)<em>=k˗</em>1. Then both</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQZr4WMbSP26eKpKp0VZOA.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wsL4nZGeDcgXjoaezJPaw.png" /></figure><p>can begin shortest paths. So this method does not merely find one shortest path, but it also reveals the entire branching structure of all shortest paths. At each vertex <em>v</em>, all neighbours satisfying</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7iPnbCWiq9HQI08loRwUNQ.png" /></figure><p>are precisely the valid next steps along shortest paths.</p><p>Let’s see this in action with an example graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KetSzo7DO3g6E5uEIHdaKg.png" /></figure><p>In the above graph, there are two obvious routes of length 3 from <em>S</em> to <em>T</em>:<br><em>S→A→C→T</em> and <em>S→B→D→T</em>. <br>The shortest distance matrix is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RSKlnuzq13awlSMHQNEzA.png" /></figure><p>The row tells us where we are starting, and the column tells us where we are going.<br>How can we reconstruct a shortest path from <em>S</em> to <em>T</em>? We begin by looking at</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRs0n1SAIAU05uDaSUtNNA.png" /></figure><p>So any shortest path from <em>S</em> to <em>T</em> must contain three edges. We start at <em>S</em>. The neighbours of<em> S</em> are <em>A</em> and <em>B</em>. Both satisfy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EY1MCObWt47fZshed6PJLQ.png" /></figure><p>So either <em>A </em>or <em>B </em>can be the first step of a shortest path. Let’s choose<em> A</em>.<br>So far, <em>S→A</em>. Now we are at <em>A</em>, and <em>Dₐₜ</em>=2. The neighbours of <em>A</em> are<em> S</em> and <em>C</em>. Their distances to <em>T</em> are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjWXb4cAeYsFap2MfTfYuA.png" /></figure><p>So the correct choice is C: <em>∴ S→A→C</em>.<br>Now,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dufuC5QX0wdJhQgecVLf4g.png" /></figure><p>We need a neighbouring vertex at distance 1–1=0 from <em>T</em>. The only vertex at distance 0<em> </em>from <em>T </em>is <em>T</em> itself. Hence <em>C→T</em>.<br>Therefore we have reconstructed the shortest path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wd1yVxkKEUNhMyrrKKwg5g.png" /></figure><p>Had we chosen <em>B</em> at the first step instead, the same rule would have produced</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_qo6arGOhi1jtWz77CLaA.png" /></figure><h4><strong>References</strong></h4><ol><li>Duncan, A. (2004). <a href="https://www.um.edu.mt/library/oar/handle/123456789/24439">“Powers of the adjacency matrix and the walk matrix.”</a> <em>The Collection</em>, 9, 4–11.</li><li>Lehman, E., Leighton, F. T., &amp; Meyer, A. R. (2015). “Adjacency Matrices.” <a href="https://ocw.mit.edu/courses/6-042j-mathematics-for-computer-science-spring-2015/resources/mit6_042js15_textbook/"><em>Mathematics for Computer Science</em></a>, Section 9.3, 323–326. Massachusetts Institute of Technology.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44e82802fdf2" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/finding-shortest-paths-using-the-adjacency-matrix-44e82802fdf2">Finding Shortest Paths Using The Adjacency Matrix</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How A Matrix Can Tell If A Graph Is Connected]]></title>
            <link>https://thequantasticjournal.com/how-a-matrix-can-tell-if-a-graph-is-connected-d14702bad69e?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/d14702bad69e</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[graph-theory]]></category>
            <category><![CDATA[graph-spectral-theory]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Sat, 12 Sep 2026 03:53:34 GMT</pubDate>
            <atom:updated>2026-11-20T04:31:52.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="How A Matrix Can Tell If A Graph Is Connected" src="https://cdn-images-1.medium.com/max/1024/1*8psde0j51NFKRWxh3x-VRA.png" /></figure><h4>A surprising bridge between linear algebra and network structure</h4><p>There’s a surprising way to check if any undirected graph <em>G</em> is connected or not without using a BFS/DFS approach: <strong><em>If the second-smallest eigenvalue of the Laplacian matrix of G is strictly positive, then G is connected.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsFRYVTuf_LPjaqwM4IbLQ.png" /></figure><p>Even better, <em>λ₂</em> doesn’t merely tell us whether <em>G</em> is connected/disconnected, but it can also tell us something about how well-connected <em>G</em> is. This is why <em>λ₂</em> is also called the algebraic connectivity of the graph.</p><figure><img alt="Two example graphs and their Laplacian matrices, illustrating how the Laplacian spectrum reveals connectivity: the connected graph has λ₂ &gt; 0, while the disconnected graph has λ₂ = 0." src="https://cdn-images-1.medium.com/max/1024/1*8OuBoxWAPMY_jg53xZuOqA.png" /><figcaption>Two example graphs and their Laplacian matrices, illustrating how the Laplacian spectrum reveals connectivity: the connected graph has <em>λ₂ &gt; 0, while the disconnected graph has λ₂ = 0.</em></figcaption></figure><p>Let’s try to understand why this is the case.</p><p>Suppose we have a finite, simple, undirected graph <em>G</em>=(<em>V</em>,<em>E</em>) with <em>n</em> vertices. For example, consider the graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HB29hc5qi9hnmsQCdlLqfw.png" /></figure><p>Its adjacency matrix is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEMVp3CF_1VuQHo_1sctNg.png" /></figure><p>and the degree matrix, whose diagonal contains the degree of each vertex, is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jk_qqTwt5qXt9TdElLK--Q.png" /></figure><p>The Laplacian matrix is defined as<em> L = D - A</em> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pi5sGqH4OAvqhWxw92_mOw.png" /></figure><p>But what information does the Laplacian matrix actually carry with itself? What does it do, intuitively?</p><p>Let’s perform an experiment to understand this: let’s assign a number to each vertex in our graph. Suppose vertex <em>i</em> gets assigned the number <em>xᵢ </em>. Encode all these numbers in a vector</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZw_Fq3kAk94wRd86Yp3zA.png" /></figure><p>Let’s compute <em>Lx</em>. For vertex <em>i</em>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKRlXmbpHIcHwhRHeowpFA.png" /></figure><p>Since <em>dᵢxᵢ </em>is just <em>xᵢ</em> repeated once for every neighbour,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zv9kMgpAkJFN_XuCzQwDvw.png" /></figure><p>Equivalently,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*evqAqU_OoxytLK9IKbKEFQ.png" /></figure><p>is the average value of the neighbours of <em>i</em>. Thus <em>Lx</em> measures a vertex’s deviation from the average of its neighbours.<br>For the graph 1−2−3, we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0DcDtQqZSta9I0JaCxs2qg.png" /></figure><p>Let’s analyze a few more properties of the Laplacian matrix <em>L</em>. Notice that the vector</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rC8ttZS-R7inhphpFVdKlw.png" /></figure><p>will always be an eigenvector of <em>L</em>, with eigenvalue 0, since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3XjnfERxnFDc2qUtO-giQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fddNr5Ph4vsqeZ4VLJF2Xw.png" /></figure><p>So every graph Laplacian has eigenvalue <em>0</em> (this would also explain why our theorem involves the second eigenvalue rather than the first).<br>What about the other eigenvalues of <em>L</em>? Will they always be positive?Consider the quadratic form <em>xᵀLx</em>. Since <em>L=D–A</em>, we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wCwuDsVPVIMjxQXYK6PnVw.png" /></figure><p>Now,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPxv-bbRUAlnX4HyExlmOA.png" /></figure><p>For an undirected graph, each edge<em> {i, j}</em> contributes once to <em>dᵢxᵢ²</em> (as <em>xᵢ²</em>) and once to <em>dⱼxⱼ² </em>(as <em>xⱼ²</em>). Thus,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2H9SjcDtKN8h62ik_e3WA.png" /></figure><p>Meanwhile,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e33kn3su9gW39tz0xlBIRA.png" /></figure><p>Because an undirected edge appears twice in <em>A</em>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7mUErcds28SpHUvP9LJxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kn8NthoLpVT4JZbyIEXT1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UhvUz05Bx-do03YQwvNZCQ.png" /></figure><p>Intuitively speaking, the Laplacian quadratic form measures the total edgewise disagreement without cancellation, since every difference is squared. Clearly,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0eIzOm9-O-iI-TApsUf4g.png" /></figure><p>for every vector <em>x</em>. So our symmetric matrix <em>L</em> is positive semidefinite. This means that all its eigenvalues will be real and greater than or equal to zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQCbRlXkLiGYJUJht6xu3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2H47_3djka4dkzKNoabmg.png" /></figure><p>We have one last property to discuss: what would the kernel of <em>L</em> be? The kernel of <em>L</em> is simply the set of all vectors <em>x</em> such that <em>Lx=</em>0:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_14Z1dsAC_CRRg12GZQiQ.png" /></figure><p>For x to belong to the kernel of L, what should its characteristics be?<br>Suppose <em>x∈</em><strong>ker</strong><em> L</em>. Then <em>Lx=</em>0<em> ⟹ xᵀLx=</em>0 , which means that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ICWnma6h9P1HhQZG0QDCA.png" /></figure><p>So for every edge <em>{i, j}</em>, <em>xᵢ = xⱼ</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjYcJaeh5aewzaCTu57ycA.png" /></figure><p>If the graph is connected here, then for any vertices <em>u</em> and <em>v</em>, there exists a path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bCKvw1xcFXKXcEHzSIbqtQ.png" /></figure><p>which means that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RcWxEU-jifIHRZfc96X5fg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKDcN9lNmvkzClFuRSsCWw.png" /></figure><p>and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQT_bheZI3-BzTxjKkoxdw.png" /></figure><p>and since u and v were arbitrary,<em> x₁ = x₂ = x₃ = … = xₙ</em> . So <em>x</em> must look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3ih5px7ReEqmXaHpOb82A.png" /></figure><p>for some number <em>c</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rO36dKUGDCH8S0JANASggw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpH76S8lTwX17uCvFb7Gcw.png" /></figure><p>The interesting part to now see is: what if the graph was disconnected? Let’s use a concrete graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X8PXPd3gwPO2UupYUzoDtQ.png" /></figure><p>There are two connected components: <em>C₁=</em>{1, 2, 3} and <em>C₂=</em>{4, 5}. Here, what vectors <em>x</em> satisfy <em>Lx = 0</em>? As before, along every edge we need equal values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRH3sI6nfzw9hsTCajen2Q.png" /></figure><p>But nothing forces <em>x₁</em> to be equal to <em>x₄</em>, so these two constants can be different. Here a kernel vector can look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGTuj0EOsCb0nz-xSFFidw.png" /></figure><p>For <em>k</em> connected components <em>C₁, C₂, …, Cₖ</em>, a kernel vector is allowed to have <em>c₁</em> on component <em>C₁</em>, <em>c₂</em> on component <em>C₂</em>, and so on. So the structure of the kernel vector is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgLc9GexKj541LIp7UaoJA.png" /></figure><p>The value is constant inside each connected component, but different components may choose different constants.<br>Now let me define a new vector <em>kᵣ</em> for each component <em>Cᵣ</em>, namely</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnJGc8D4Aucu7ApCODenzA.png" /></figure><p>In our example, <em>C₁=</em>{1, 2, 3}, <em>C₂=</em>{4, 5}. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsT2thDUCBK_5FgqgwP8SQ.png" /></figure><p>They’re actually called indicator vectors because they indicate membership (1<em>=</em>inside the set, 0<em>=</em>outside the set.)<br>Notice that all indicator vectors <em>k₁, k₂, …, kᵣ</em> will be in the kernel of <em>L</em>. How? Take</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8gCQlnAR9CkzDjIWH0vmA.png" /></figure><p>for example. An edge cannot connect <em>C₁</em> to <em>C₂</em> because then they wouldn’t be separate connected components — so every edge lies entirely inside one component. If the edge is inside <em>C₁</em>, then both endpoints have value <em>1 ⇒ xᵢ−xⱼ=1−1=0.</em> If the edge is inside <em>C₂</em>, then both endpoints have value zero <em>⇒ xᵢ−xⱼ=0</em> again. Therefore every edge contributes zero</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2UtN93A_5ihK6oHEpGl4EA.png" /></figure><p>Hence <em>Lx=</em>0. So <em>Lkᵣ=</em>0 for all <em>r</em> connected components. Also, all these indicator vectors are linearly independent. How? If</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9D7fBfwfPtSONF6zmL3zw.png" /></figure><p>then pick a vertex <em>i∈C₁</em>. At coordinate <em>i</em>, <em>(k₁)ᵢ=1</em> while all the other indicator vectors have zero there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHWEWYo8HNxcnnXk6ZQLjA.png" /></figure><p>So coordinate<em> i</em> of <em>(a₁k₁+⋯+aᵣkᵣ)</em> simply becomes <em>a₁</em>. Since the whole vector equals <em>0</em>, <em>a₁=0</em>. (The same reasoning can be applied for <em>a₂,a₃,…,aᵣ</em>.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfpeJhRFcmbuPFJ7-Oyd1w.png" /></figure><p>In our earlier example with two connected components, we said that every kernel vector has the form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lw4IG61fBUp16EmzwwWH5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YadT-Oj9Nh5zoTBoc_UyhQ.png" /></figure><p>For <em>r</em> components,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGzrekaYzuye0MwDyevqIg.png" /></figure><p>Since all the indicator vectors are linearly independent,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42HOZUCWRUE4Ir1zmNi3zQ.png" /></figure><p>But <em>r</em> is exactly the number of connected components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jhZaTsBOlbq_DltZ0R-W9g.png" /></figure><p>Now our theorem becomes trivial. Let</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TdQkEmSBtIreGg4aWzrqA.png" /></figure><p>be all our eigenvalues of <em>L</em>. We’ve proved that <em>0</em> is always an eigenvalue, so <em>λ₁=0</em>. The multiplicity of the eigenvalue 0 is <strong>dim</strong><em>(</em><strong>ker</strong><em> L)</em>, which is the number of connected components.<br>If <em>G</em> is connected, there is exactly one component. Therefore 0 occurs exactly once;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iPXAR-8u28eZCz6UDc3anw.png" /></figure><p>So</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOgEeCcNEJJQ5wADd7OFbw.png" /></figure><p>Conversely, suppose <em>G</em> is disconnected. Then it has at least two connected components. So 0 has multiplicity at least 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFRy4ZSXg0zPPN04IUFhgw.png" /></figure><p>Hence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsFRYVTuf_LPjaqwM4IbLQ.png" /></figure><p>The value of<em> λ₂ </em>can also tell us something about the graph’s connectivity beyond simply whether it is connected. A small positive <em>λ₂</em> generally signals the presence of a bottleneck: the graph admits a division into parts that are weakly coupled relative to their size. A larger <em>λ₂</em> indicates stronger algebraic connectivity. The interpretation is qualitative, however, and direct comparisons between graphs of very different sizes or degree distributions require care.</p><figure><img alt="λ₂ (the algebraic connectivity, or Fiedler value) measures how strongly G is connected: the larger λ₂, the harder it is to split G into two pieces." src="https://cdn-images-1.medium.com/max/1024/1*8PA4KseIk3Ns2MH9M_kg8Q.png" /><figcaption>λ₂ (the algebraic connectivity, or Fiedler value) measures how strongly G is connected: the larger λ₂, the harder it is to split G into two pieces.</figcaption></figure><h4><strong><em>References</em></strong></h4><ol><li>Fiedler, M. (1973). “Algebraic connectivity of graphs.” <em>Czechoslovak Mathematical Journal</em>, 23(2), 298–305. <a href="https://doi.org/10.21136/CMJ.1973.101168">DOI: 10.21136/CMJ.1973.101168.</a></li><li>von Luxburg, U. (2007). “A Tutorial on Spectral Clustering.” <em>Statistics and Computing</em>, 17, 395–416. DOI: <a href="https://doi.org/10.1007/s11222-007-9033-z">10.1007/s11222–007–9033-z.</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d14702bad69e" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/how-a-matrix-can-tell-if-a-graph-is-connected-d14702bad69e">How A Matrix Can Tell If A Graph Is Connected</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hidden Information In Adjacency Matrices]]></title>
            <link>https://medium.com/@rajkanishk2709/hidden-information-in-adjacency-matrices-ff1c82cfc32b?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff1c82cfc32b</guid>
            <category><![CDATA[discrete-mathematics]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Wed, 26 Aug 2026 22:55:02 GMT</pubDate>
            <atom:updated>2026-11-20T05:06:37.655Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y77vwPwyLtVbHzBpa23N9A.png" /></figure><p>There’s a lot of nice information that can be extracted from the adjacency matrix of a graph. For instance, the (u, v)-th element of Aᵏ will give us the number of walks of length k from vertex u to vertex v.<br>Why is this true? Think about what happens during matrix multiplication:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oLv-1ahUZF_JDaoqxqioCw.png" /></figure><p>Look at AᵤₓAₓᵥ. Since each factor is either 0 or 1,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2N4n_MfHYZN8g7zYjgdXGg.png" /></figure><p>exactly when both u ～ x and x ～ v, meaning that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBzMiFzbme7PVjC1S7f69g.png" /></figure><p>is a valid walk of length 2. So every possible intermediate vertex x contributes 1 if it gives a valid length-2 walk and 0 otherwise. Therefore,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIRuGbgALYNqnBBrmfO8tg.png" /></figure><p>In general, (Aᵏ)ᵤᵥ counts the number of walks of length k from u to v. We can prove this by induction:<br>For the base case when k = 1, by definition, (A)ᵤᵥ = 1 exactly when there is an edge between u and v (a walk of length 1). So the statement is true for k = 1.</p><p>Now assume (Aᵏ)ᵤₓ counts length-k walks from u to x. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vwaaTpl5VMG2_MfmR00bmw.png" /></figure><p>By the induction hypothesis, (Aᵏ)ᵤₓ is the number of length-k walks from u to x. If Aₓᵥ = 1, then x ～ v, so each such length-k walk can be extended by one edge: u → ⋯ → x → v.<br>∴(Aᵏ)ᵤₓAₓᵥ counts length-(k+1) walks from u to v whose penultimate vertex is x. (penultimate vertex- the vertex visited immediately before v.) Summing over x counts every such walk exactly once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xV2XYsV4nYyKwaIS47Cfsw.png" /></figure><p>The induction is complete.</p><p>There’s some other cool information that we can extract as well.</p><p>The degree of any vertex in an undirected graph is actually hidden in the diagonal of A². How so?<br>Take the theorem with k = 2 and the same starting and ending vertex — (A²)ᵥᵥ. It counts length-2 walks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EizKyERQF2XaMwHcSx6fgw.png" /></figure><p>Because the graph is undirected, this happens exactly when x is a neighbour of v. For every neighbour x ∈ N(v), there is exactly one walk v → x → v. So the number of these walks equals the number of neighbours of v i.e. its degree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nmm3Iq8QFEsx2DHQ1qtd2w.png" /></figure><p>Now since the trace is the sum of the diagonal entries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9nlunMyfun-NPkPyyO8wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdM2WlQWDlplWkNh-W56OA.png" /></figure><p>But the handshaking lemma says that for a simple undirected graph,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5nH0bFZMx0P2FnTkGwldw.png" /></figure><p>Hence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfGVmD1RLeUcyHqcd68P_w.png" /></figure><p>Note that this works only for simple undirected graphs. For directed graphs the directed edge count is just</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KZuiwPguD60kD54PdZ1NDw.png" /></figure><p>Also, there is a neat formula to calculate the number of triangles in any undirected graph as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CJUTMca-7rkkhT0LiEjkRg.png" /></figure><p>How? From our walk-counting theorem, (A³)ᵥᵥ counts all closed walks of length 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gNdmH-WsMu9E-GBEXZSfg.png" /></figure><p>So</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcju5p0Fnq3OU9La4PjfUg.png" /></figure><p>counts all closed walks of length 3, with the starting vertex remembered. Here every closed walk corresponds to traversing a triangle. But one triangle (suppose a, b, c) produces several closed walks. (We can start at any of its three vertices. Starting at a, there are two directions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y8j9CDMYvgSYZdet1mcUSA.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BhVYxTd_thDQ3ixgspJGDA.png" /></figure><p>Similarly, two different directions for starting at b and two for starting at c.) So every triangle contributes exactly 6 closed length-3 walks. Hence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WLDo5YpbWo7rxcjLRShm9Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff1c82cfc32b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Egyptian Fraction Theorem]]></title>
            <link>https://medium.com/@rajkanishk2709/the-egyptian-fraction-theorem-a0a65ee0c342?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0a65ee0c342</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[greedy-algorithms]]></category>
            <category><![CDATA[number-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Mon, 24 Aug 2026 23:41:11 GMT</pubDate>
            <atom:updated>2026-11-20T05:11:57.735Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BeeodOcgYBebHhjKZkgZVg.png" /></figure><p>Every positive rational number can actually be expressed as a finite sum of distinct unit fractions. Such a representation is called an Egyptian fraction representation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDiCQl9mlu_R24iUdMvQAw.png" /></figure><p>How can we prove this? Well, there are two possibilities: either the fraction a/b is in (0, 1) or it is ≥ 1. Let’s deal with the first one. Suppose</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRYmdmQwisb6ZQvEah5oug.png" /></figure><p>To get its Egyptian fraction representation, there is a recursive algorithm, which is to, so to speak, peel off(meaning subtract) unit fractions from a/b, one by one, till we get zero as the remainder. Once we get zero, we have our full representation. But which one should we subtract off first? Let’s just take the largest unit fraction that does not exceed a/b; we will try to repeatedly do this until we get our full Egyptian fraction representation.</p><p>So we want some integer n satisfying</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAoG2Hr4Tg6SkkP98Z-OUA.png" /></figure><p>The smallest integer satisfying this condition is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKYaN56zAuS4_clISpsCxg.png" /></figure><p>We will now subtract it from a/b: the remainder will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyXOtvG1HJdzurXo_PaPyg.png" /></figure><p>Now there are two possibilities: if</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcmlE9preVa415OH0f_fOQ.png" /></figure><p>then we’re done and 1/n is our complete representation. The second possibility is that R &gt; 0. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Mxk62vijZTonbxD6wEJ6g.png" /></figure><p>Since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGmc2OeO0fbUCC44jDxP4A.png" /></figure><p>Since the possibility of a/b = 1/n is already tackled, an - b &gt; 0 actually.<br>Also, as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5WxkxzOIiAro5Zm1m-bQmQ.png" /></figure><p>So the numerator of R has strictly decreased. This actually proves that our algorithm will terminate. How so?<br>Suppose we repeat exactly the same procedure on the remainder. We might start with numerator a, then after one step we get a smaller positive numerator a₁,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uhoc1xJEHgi0XtFvl0Z5Q.png" /></figure><p>After another step, we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqmFOl0K-Uw9-BRztsk_pg.png" /></figure><p>and so on…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3g4DGAJaiYans1psbsqAjQ.png" /></figure><p>where every aᵢ is a positive integer. But we cannot have an infinite strictly decreasing sequence of positive integers, by the <em>well-ordering principle.</em><br>So the process must terminate after finitely many steps. Eventually the remainder itself becomes a unit fraction(1/m for some m). Therefore we will obtain a finite decomposition</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tqn_GPXaitJTqwAp-5KzDw.png" /></figure><p>Note that for a rational number x = a/b larger than 1, we will first have to remove a suitable initial piece of the harmonic series</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YH-9brQnayHdbk09XcPrAg.png" /></figure><p>from it and then apply our algorithm once R is in (0, 1). Since the harmonic series diverges to infinity, no matter how large our rational number x is, eventually a partial sum will exceed it. Define</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ncUn9e-6ec61vojGZdC23w.png" /></figure><p>Suppose x ≥ 1. Because Hₙ → ∞ as n → ∞, we can find n such that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSYRG_vTVKN3FWajMcyqLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0lw5O-brevDLpP-4kptrA.png" /></figure><p>Let</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMqa-1t-1RJ1hnnsUJJq9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P_E2cSL_Hip0BMmLuJ7mw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0a65ee0c342" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kirchhoff’s Matrix-Tree Theorem]]></title>
            <link>https://medium.com/@rajkanishk2709/kirchhoffs-matrix-tree-theorem-775d0791c81a?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/775d0791c81a</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[discrete-mathematics]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 06:43:21 GMT</pubDate>
            <atom:updated>2026-11-20T05:23:37.319Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elkZBE7stE9ul8CFejbPyA.png" /></figure><p>This is just an incredible theorem that I recently came across; it’s so good that I had to write about it. It helps you find out the number of spanning trees of any graph. A brute-force algorithm to compute the number of spanning trees could have taken exponential time, but it can be done in polynomial time using this theorem.</p><p>Let me just recall a few terminologies: For a simple graph, the adjacency matrix A is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VdHakjp9qhg7FBs4qkoiGQ.png" /></figure><p>Also, the degree matrix D is a diagonal matrix defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9bibBBNRE_DSq-zb_l7izA.png" /></figure><p>Here’s the theorem:<br>Let G = (V, E) be a graph with n vertices, and let</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXj9keBZgfqpiwZIYDRyaw.png" /></figure><p>be its Laplacian matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKcvzxudrMp_xTsKCsvXSw.png" /></figure><p>Then Kirchhoff’s Matrix-Tree theorem says:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IUetrkgKsDgfWHxiprPigA.png" /></figure><p>where τ(G) is the number of spanning trees of G. Remarkably, the answer does not depend on which vertex i we choose.</p><p>As an example, consider the triangle K₃</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*TpzY1NHRaaB_T6o61WdMJw.png" /></figure><p>Its three spanning trees are obtained by deleting any one edge, so τ(G) = 3. The Laplacian is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4t3ykBJ7uVrjsrzanzK_yw.png" /></figure><p>Pick i = 1. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jOnF7MHlRQ8Sde1kgRcRkw.png" /></figure><p>But why does this even work? The reason relates to a beautiful recursive rule for spanning trees, which I will now discuss.</p><p>Pick an edge e = (i, j) from G. Every spanning tree of G falls into exactly one of two categories: either the tree contains e or the tree does not contain e.</p><p>For an edge e, define G−e to mean “delete e” from G and G/e to mean “contract e”. (Contracting e = (i, j) means merging vertices i and j into one vertex). Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc7ujGufFcebTuCI0xBcpw.png" /></figure><p>Why? Consider spanning trees that do not contain e. Deleting e from the graph changes nothing for them, therefore they are exactly the spanning trees of G−e.</p><p>Now consider spanning trees that do contain e. Since e is definitely present, contract it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgPbrzZEHm6LfpnG6sEbFA.png" /></figure><p>A spanning tree containing e becomes a spanning tree of G/e. Conversely, a spanning tree of G/e can be expanded back and e inserted, giving a spanning tree of G containing e.</p><p>Adding the two disjoint cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc7ujGufFcebTuCI0xBcpw.png" /></figure><p>Let’s see this concept in action on our triangle K₃​. Take e = (1, 2). If we delete e, then we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nOvWl1zt0aucJVklcmZ-9Q.png" /></figure><p>That’s already a tree, so τ(G−e) = 1.</p><p>If we contract e, we merge vertices 1 and 2 into one vertex x. Originally we had both 1−3 and 2−3, but after contraction they will become two parallel edges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qf3amcXN4ExPAyBUeMhTEg.png" /></figure><p>There are two ways to choose one of those edges as a spanning tree, so τ(G/e) = 2.<br>∴ τ(G)=τ(G−e) + τ(G/e) = 1 + 2 = 3.</p><p>We’re halfway through. But there are a few more observations to be made.</p><p>Define Eᵢᵢ to be the matrix that is zero everywhere except for a 1 in position (i,i). For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mr0MqDEjQgbLnez7kAWEfg.png" /></figure><p>It turns out that for a square matrix A,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QenKtnJNUdhN9Rrm6Pa4UQ.png" /></figure><p>There’s a clean way to prove this using linearity of the determinant in one row. A + Eᵢᵢ changes row i by adding the row vector</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WrfWuhXTzbNxGc3ivkeNDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ulbhPEUtprJXT8bUUZuNsQ.png" /></figure><p>Expanding the second determinant along row i, whose only non-zero entry is the 1 in column i, gives</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRANH_SNDgcnd5-Km9ho9A.png" /></figure><p>This is going to be useful to us later.</p><p>The important thing to understand from this point is that the Laplacian matrix can be thought of as the sum of the contributions of individual edges. To illustrate, suppose we have just one edge e = (i, j). What does this one edge do to D and A?<br>Because i participates in this edge, its degree increases by 1. Also, because j participates in this edge, its degree increases by 1. So this edge contributes +1 to Dᵢᵢ​ and +1 to Dⱼⱼ.<br>Meanwhile, because i and j are adjacent,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uw6qAwPO_CrdCFkUbHYodQ.png" /></figure><p>And because L = D - A, those adjacency entries become −1 in the Laplacian matrix.<br>So this single edge (i, j) produces</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2sOYVE4IU9F-1Zu5mdl4g.png" /></figure><p>inside L.<br>For instance, take the triangle K₃ . Its Laplacian is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyDQflbxhVE3DANfxwJgGQ.png" /></figure><p>Instead of constructing this all at once, let’s build it edge by edge.</p><p>Edge (1, 2) contributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fydip8pb0NHu2Qab75l0tQ.png" /></figure><p>Edge (1, 3) contributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0wZp3sjsgq1mOlIFGES5A.png" /></figure><p>Edge (2, 3):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L52xGUSaUZr7bVLR6I3j7Q.png" /></figure><p>Adding them all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nG7M84P4fsVsslYSwFH0ew.png" /></figure><p>The important thing to note is this: we have chosen an edge e = (i, j), and Kirchhoff’s theorem asks us to compute a determinant after deleting row i and column i of our Laplacian matrix. What happens to this edge’s little matrix when row i and column i disappear?<br>Originally, the edge contributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2sOYVE4IU9F-1Zu5mdl4g.png" /></figure><p>After deleting row i and column i, everything except the +1 at the (j, j) position vanishes.</p><p>Now suppose we have two graphs:<br>G : contains the edge e = (i, j).<br>G−e: exactly the same graph, but that one edge is removed.</p><p>Their Laplacians differ only by the contribution from that edge. Before deleting anything,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzzCyZP-Yw6D8twhKL6-og.png" /></figure><p>Now delete row i and column i. The edge contribution collapses down to just one 1 at (j, j).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJv_uQd5kiZ_yx-9tDN0uA.png" /></figure><p>Taking determinants on both sides:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9YygoWnzVlGFZ1FcR3yr7g.png" /></figure><p>Since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYduXqsZQNVYK2ltTaSpxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofvtdQD38O8Olh76-UROSg.png" /></figure><p>Here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wu0lc9mH5G1No2GFhpktqw.png" /></figure><p>means to delete rows and columns corresponding to both i and j.<br>But</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vp-7sH_I5pUD69gLIKKTw.png" /></figure><p>Why? Because the deleted edge (i, j) only changes entries associated with vertices i and j — i.e., (i, i), (i, j), (j, i), (j, j).<br>But after deleting both rows and columns i and j, every entry affected by e disappears! So</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vp-7sH_I5pUD69gLIKKTw.png" /></figure><p>Also,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbvDVq101bklHjCuklvR7w.png" /></figure><p>How? Because after contracting i and j, suppose we subsequently delete the row and column of the new merged vertex j. What vertices remain? Exactly V / {i, j}.<br>Now consider two surviving vertices u, v ∉ {i, j}. Their relationships with one another haven’t changed at all under contraction; edges u−v remain u−v. Their degrees also remain the same: any edge from u to i or j becomes an edge from u to the merged vertex, so it still contributes to u’s degree.</p><p>∴ Once the merged vertex is removed from the matrix, the remaining Laplacian entries are exactly the entries we would have obtained from the original graph by simply removing i and j.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbvDVq101bklHjCuklvR7w.png" /></figure><p>Since we know that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1YIBEzR9MrcCF3I7Wfp3A.png" /></figure><p>But</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aY_7JDMnB-ulUg3twAKP4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*998X4yKieHSn8LJdqWpB0g.png" /></figure><p>If we think about it, it feels quite similar to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc7ujGufFcebTuCI0xBcpw.png" /></figure><p>If we can prove that they are the same recurrence, we’re done. Let’s do that by induction.</p><p><em>Base Case:</em> Pick an empty graph on two vertices. It has no spanning trees, so τ(G) = 0. The Laplacian is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrFsn8gBFStu8SUPaoJvvw.png" /></figure><p>Deleting one row and column gives</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCPNOxAtY65iwi27qdC14w.png" /></figure><p>so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvl3vQKdSpFtCvIAG4Re7g.png" /></figure><p><em>Inductive Step:</em> The induction is on the size of the graph, say</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RB73a-JZyONgz7j2ZuecYw.png" /></figure><p>We want to prove, for every vertex i,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q815C-zwYsfVHxv9CrQFqg.png" /></figure><p>Assume the theorem is true for every graph H with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjtLDs-YqOHouHfLg7m93w.png" /></figure><p>Now we gotta prove it for G.<br>Choose an edge e=(i, j) incident to i. We’ve already established algebraically that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9H0GeEtsImL5c_IKmI39BA.png" /></figure><p>Now both graphs on the right are smaller</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*48d60Nh0QSUR3GzurdmWkw.png" /></figure><p>and G/e has one fewer vertex, so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FkioUQ0hpHuPbWESCHrHYQ.png" /></figure><p>Therefore the induction hypothesis applies to both of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HmZwWFvlx3i3KpyxhAsgVQ.png" /></figure><p>Substituting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGqnDyJL4H_I6LzQMTwcmg.png" /></figure><p>But independently, deletion-contraction for spanning trees tells us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc7ujGufFcebTuCI0xBcpw.png" /></figure><p>Hence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dj3W3kcp6ZtiLVZW6epvog.png" /></figure><p><strong>References:</strong><br>1) <a href="https://u.osu.edu/nix.39/2021/10/28/kirchhoffs-matrix-tree-theorem/">Ohio State University pag</a>e on this theorem.<br>2) <a href="https://mathweb.ucsd.edu/~ssam/old/19W-154/notes.pdf">UC San Diego notes</a> on this theorem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=775d0791c81a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zeckendorf’s Theorem]]></title>
            <link>https://medium.com/@rajkanishk2709/zeckendorfs-theorem-6b62bc1a11d5?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b62bc1a11d5</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[number-theory]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[fibonacci-sequence]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Wed, 19 Aug 2026 07:31:16 GMT</pubDate>
            <atom:updated>2026-11-20T05:29:22.188Z</atom:updated>
            <content:encoded><![CDATA[<p>Zeckendorf’s theorem states that every positive integer can be written uniquely as a sum of nonconsecutive Fibonacci numbers.</p><p>Let’s first formally define the Fibonacci sequence used in this theorem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpxBqAdP8KS2MhBEtf1AcQ.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wLG8VYfCAF2MatpykOF3zw.png" /></figure><p>A valid Zeckendorf representation is a sum</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZC-7NhMfJExoglgsgSLwA.png" /></figure><p>in which no two selected Fibonacci numbers are consecutive in the sequence. For example, 100 = 89 + 8 + 3 is valid.</p><p>Suppose we are given some positive integer N. How can we find its Zeckendorf representation? There’s an algorithm to find it. It works as follows:<br><em>Pick the largest Fibonacci number not exceeding N, subtract it from N, and repeat on the remainder until we reach 0.<br></em>For example, for 100,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQaWA8V0NZLj1Wuf0soD1A.png" /></figure><p>then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5J0FOREemMXAIJ0W4qRxYg.png" /></figure><p>then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dtlAIAgo5m2tZnl_udSpbQ.png" /></figure><p>The process will eventually reach 0 for every number. But how do we know that this algorithm never chooses two consecutive Fibonacci numbers?</p><p>Suppose Fₖ​ is the largest Fibonacci number satisfying</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttFpEb2bDHxyP97A1FlMCg.png" /></figure><p>Since Fₖ​ is the largest, the next Fibonacci number must be too large:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6CK0-pjUz8rExgygP1mh5A.png" /></figure><p>But</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q3jgqNt8PS6ztFMph4f0dQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KTwb5iMREfc0_vUpGN0AOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAmFTUMtGgzhA5OyEYWMEA.png" /></figure><p>Let R = N - Fₖ​ be the remainder. Then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylYO9ecxz6DxO1H6ZanAAg.png" /></figure><p>Look at what just happened. We selected Fₖ​. The Fibonacci number immediately preceding it is Fₖ₋₁. But the remainder satisfies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylYO9ecxz6DxO1H6ZanAAg.png" /></figure><p>So in the next step, when the algorithm looks for the largest Fibonacci number ≤ R, it cannot possibly select Fₖ₋₁. The next selected number must therefore be at most</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-a5wasGBiKzuEDCO8ljH9g.png" /></figure><p>Hence the algorithm skips at least one Fibonacci number after every subsequent choice.</p><p>Repeating the same argument on each remainder produces a sequence of nonconsecutive Fibonacci numbers. Because each step strictly reduces a nonnegative integer remainder, the algorithm eventually terminates at 0.</p><p>Hence every positive integer has a representation as a sum of nonconsecutive Fibonacci numbers.</p><p>But how do we know that such a representation is unique? To prove uniqueness, we’re going to need an identity and a lemma.</p><p><em>Identity:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cu0OkMP-rQxZMWV5qxImdg.png" /></figure><p>How? By definition,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXetNuUv6GddNuapA7VFAg.png" /></figure><p>Similarly,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_O4la2HWo5ee3uBC0gwuAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHoAZmWT0cTuUqMhJL_6Aw.png" /></figure><p>and so on. Adding them all up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Ppf_LrDGZggHAKpQrV3Qw.png" /></figure><p><em>Lemma: Any sum of nonconsecutive Fibonacci numbers chosen from F₁, F₂, …, Fₖ₋₁ is at most Fₖ − 1.<br></em>Why? Because the largest term you could choose is Fₖ₋₁. If you choose Fₖ₋₁, you cannot choose Fₖ₋₂; you have to choose Fₖ₋₃, then Fₖ₋₅ and so on…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07ILO7QwK2QU0v9GLf3nXQ.png" /></figure><p>This proves our lemma.</p><p>Now we can jump back to our uniqueness proof. Suppose for contradiction that some integer N has two different Zeckendorf representations. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYCIshr1PudNnl9mL2Rfig.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7TNe7WdqB7QQhG2LvMRvGw.png" /></figure><p>Because the representations are different, there must be some Fibonacci number that occurs in one representation but not the other. Choose the largest such Fibonacci number. Call it Fₖ . <br>Suppose Fₖ​ occurs in the first representation but not the second. Then any Fibonacci numbers larger than Fₖ​​ must occur identically in both representations; otherwise, Fₖ​ would not be the largest place where they differ.<br>So cancel all those common larger terms. What remains is an equality of the form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yb2Tu2MfQSA9SnCx8paXXA.png" /></figure><p>Clearly, LHS ≥ Fₖ . But the right-hand side is a legal sum involving only Fibonacci numbers smaller than Fₖ ​. By our lemma derived above, RHS ≤ Fₖ -1<br>But LHS = RHS, so this doesn’t make sense.</p><p>Therefore there cannot be two different valid representations, thus uniqueness is proved.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b62bc1a11d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prime Numbers Of The Form 2ⁿ ± 1]]></title>
            <link>https://medium.com/@rajkanishk2709/prime-numbers-of-the-form-2%E2%81%BF-1-ce3cd1ed2162?source=rss-fe240ca2fc91------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce3cd1ed2162</guid>
            <category><![CDATA[prime-numbers]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[number-theory]]></category>
            <dc:creator><![CDATA[Kanishk Raj Tanwar]]></dc:creator>
            <pubDate>Mon, 17 Aug 2026 05:03:50 GMT</pubDate>
            <atom:updated>2026-11-20T05:34:23.664Z</atom:updated>
            <content:encoded><![CDATA[<p>Two interesting observations:<br>1) If 2ⁿ - 1 is prime, then n is prime.<br>2) If 2ⁿ + 1 is prime, then n is a power of 2.</p><p>Let’s see why both these statements are true.</p><h3>If 2ⁿ - 1 is prime, then n is prime.</h3><p>If we prove that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0EX665O0VuOTsk1altYEA.png" /></figure><p>then we’re done.<br>Since n is composite,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9EDGrMpWVVFfvcO9etRKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYiMAxS7nhIpTeiGrG6tZg.png" /></figure><p>This is an expression of the form xᵇ - 1. <br>Now, xᵇ - 1 can be factorized as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vcIU3kMyYakEq4tFr2BkhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dAGDKXfzVOs-dFcpCrsTMw.png" /></figure><p>Since a &gt; 1, 2ᵃ - 1 &gt; 1. As b &gt; 1, the second factor is also greater than 1.</p><p>Therefore, 2ᵃᵇ−1 has a non-trivial factorization into two integers greater than 1, and is thus composite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDGvQmUILUVEXzIVkSgguA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_wFG1x06WHI3IkJNwp_YA.png" /></figure><h3>If 2ⁿ + 1 is prime, then n is a power of 2.</h3><p>What we have to prove is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tqOiSprTEPtbcoxe2rlymg.png" /></figure><p>Again, we can do this by proving its contrapositive,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2YN7B2uNDsWV4b2VHOdeA.png" /></figure><p>If n is not a power of 2, then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4l8y7Tb7R1QqVicLIRSgA.png" /></figure><p>where m &gt; 1 and is odd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8MJQAEP1MO9xgY5v8DArg.png" /></figure><p>If we let</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JW14c0tyXicuNnIux9PXyA.png" /></figure><p>then 2ⁿ + 1 is of the form xᵐ + 1, where m is odd.<br>For odd m,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gc1_yMuQON2L8TXcJ06Lvw.png" /></figure><p>(How? If m is odd, then (-1)ᵐ = -1 . Therefore,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1xj2frBd63O86oyQRIei_w.png" /></figure><p>Then we use the identity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDyAoW18dNq6eQuUddzIPQ.png" /></figure><p>and replace a with x , and b with -1.)</p><p>Therefore,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jo7oVnIl7RzM-FDQ38995w.png" /></figure><p>whenever m is odd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RTrW9KyOnMxYZbjOtWEcnQ.png" /></figure><p>Since m &gt; 1, this is a proper nontrivial divisor ⇒ 2ⁿ + 1 is composite. Thus,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2YN7B2uNDsWV4b2VHOdeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g2j7knwX36AgM3XjbsrONw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce3cd1ed2162" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>