<?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 Xyrolle on Medium]]></title>
        <description><![CDATA[Stories by Xyrolle on Medium]]></description>
        <link>https://medium.com/@serii.hmeli123123?source=rss-a85dd2c61c56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*gfM0EvwKtKSxHB8JX_9qPA.jpeg</url>
            <title>Stories by Xyrolle on Medium</title>
            <link>https://medium.com/@serii.hmeli123123?source=rss-a85dd2c61c56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:50:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serii.hmeli123123/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[Path matrix — Warshalls Algorithm]]></title>
            <link>https://medium.com/@serii.hmeli123123/path-matrix-warshalls-algorithm-afe331147df0?source=rss-a85dd2c61c56------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe331147df0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Xyrolle]]></dc:creator>
            <pubDate>Sun, 01 Mar 2020 22:11:07 GMT</pubDate>
            <atom:updated>2020-03-03T08:43:15.707Z</atom:updated>
            <content:encoded><![CDATA[<h3>Path matrix — Warshalls Algorithm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BWImTbguBeD7gP6x" /><figcaption>Photo by <a href="https://unsplash.com/@alicekat?utm_source=medium&amp;utm_medium=referral">Alice Donovan Rouse</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello everyone, today I want to give you a brief explanation of how Warshalls algorithm works and how it can be applied. Personally I found some of explanations quite hard and incomprehensible, so I decided to write this article. So, let’s start.</p><h3>What is Washalls algorithm?</h3><p>Warshalls algorithm helps us to obtain <em>path matrix </em>from adjacency matrix in efficient way. So, to understand this algorithm let’s first explore concept of path matrix.</p><h3>Path matrix</h3><p>A path matrix of a simple directed graph is a boolean matrix (with entries as 1 or 0). Path matrix uses concept of <strong><em>transitive closure</em></strong>.</p><blockquote>Given a relation <strong>r</strong><em> </em>on a set A, the <strong>transitive closure of r<em> </em></strong>is the smallest transitive relation that contains <strong>r<em> </em></strong>as a subset. Usually denoted as <strong>r*</strong>.</blockquote><p>I know, it sounds cryptic, but I promise it will make sense. Let’s look at how we can actually make compute transitive relations.</p><h3>Computing transitive relations</h3><p>Based on previous definition we know that transitive closure is superset of original set, so it has the same amount of pairs <em>{V, E}</em> or more. So how can we actually get a transitive closure from a set?</p><blockquote>Let <strong>r<em> </em></strong>be a relation on <strong>A</strong> and <strong>r*</strong> its transitive closure. Then (a, b) ∈ <strong>r*</strong> <em>if and only if there is a path of edges from </em>a<em> to </em>b<em>.</em></blockquote><p>So, by definition pair <em>{V, E}</em> will be in transitive closure if there is a <em>way</em> to get from <em>a</em> to <em>b</em>. Enough talk, let’s walk through example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*Cgv3q-1W8j5JDPJteaKL8Q.png" /><figcaption>Adjacency matrix</figcaption></figure><p>Here is adjacency matrix, but it’s not very good visual representation, is it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*LJYVhQXTjvwNxtECjFbq2g.png" /><figcaption>Graph (Visual representation)</figcaption></figure><p>Oh, that’s much better. So, now we can clearly see connections between nodes. But what we actually want to do is find <strong><em>path matrix </em></strong>of this particular matrix. But where should we start? Let’s look at how we can make a transitive closure of this matrix. To make it we take each node and iterate through all level connections, for example:</p><blockquote>1 is only directly connected to 0, but <br>If 1 is connected to 0, and 0 is connected to 2, then there is a <em>second level connection</em> between 1 and 2. Next we see that 2 is connected to 3, so we can get from 1 to 3, through <em>third level connection</em>.</blockquote><p>By doing this for each and every node in our original set we get <strong><em>transitive closure</em></strong><em>. </em>But imagine if we had thousands of nodes and connections between them. This isn’t scaling very well, is it? Imagine we had thousands or even millions of nodes and connections and we want to get <strong><em>transitive closure</em></strong>. This could take a lot of computational power, but here is where <strong><em>Warshalls algorithm </em></strong>come in handy.</p><h3>Warshall Algorithm</h3><p>Now, when we covered some theory you are ready to see some code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85669fa401ebc5fe3988eab5d8c8e119/href">https://medium.com/media/85669fa401ebc5fe3988eab5d8c8e119/href</a></iframe><p>Let’s focus on last line, because this is where all logic is concentrated.<br>It states that W[i, j] will get value of one <strong><em>if</em></strong> one of the conditions are met:<br>1. W[i, j] is already 1 (node already has edge to this node).<br>2. There is linking node, as we saw earlier <strong><em>if</em></strong> (1 -&gt; 0) <strong>and (</strong>0 -&gt; 2), then (1 -&gt; 2). That’s is basically the same, except it performs this on adjacency matrix, rather than visually.</p><p>In conclusion I want to encourage you to play around with this code and try to understand what each line means. Also if you struggle to do so, try pen and paper. Draw adjacency matrix and try to understand connections.</p><p>I hope that you enjoyed reading this. Bye!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe331147df0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>