<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Algorithms on JinerX blog</title><link>https://jinerx.github.io/tags/algorithms/</link><description>Recent content in Algorithms on JinerX blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>© 2026 Jędrzej Sajnóg</copyright><lastBuildDate>Thu, 19 Mar 2026 19:04:21 +0100</lastBuildDate><atom:link href="https://jinerx.github.io/tags/algorithms/index.xml" rel="self" type="application/rss+xml"/><item><title>Local search</title><link>https://jinerx.github.io/learning_log/local-search/</link><pubDate>Thu, 19 Mar 2026 19:04:21 +0100</pubDate><guid>https://jinerx.github.io/learning_log/local-search/</guid><description>&lt;p&gt;Local search is a simple approximation algorithm, which doesn&amp;rsquo;t necessarirly lead to the best result, instead it has a tendency to get stuck in a local minimum. Still if combined with other techniques like for example use of heuristics it can cheaply with low overhead improve the quality of the found solution.&lt;/p&gt;
&lt;p&gt;pseudocode:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;function local_search:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;INPUT: graph of the state G = (V,E), cost function f
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;OUTPUT: found state
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;s &amp;lt;- generate_initial_state()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;while (true): // we might want iteration amount limit in case the state space is infinite and the optimum unreachable
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s&amp;#39; &amp;lt;- s
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; for n in get_neighbors(s):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if f(n) &amp;lt; f(s&amp;#39;):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s&amp;#39; &amp;lt;- n
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if (s&amp;#39; /= s):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s &amp;lt;- s&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; else:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; break
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;return s&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This pseudocode was written for a graph but can easily be generalized to any general solution space. Simply instead of looking at neighbours of a state we at states we can possibly &amp;ldquo;go to&amp;rdquo;.&lt;/p&gt;</description></item><item><title>Minimum Spanning Tree</title><link>https://jinerx.github.io/learning_log/minimum-spanning-tree/</link><pubDate>Wed, 18 Mar 2026 16:25:43 +0100</pubDate><guid>https://jinerx.github.io/learning_log/minimum-spanning-tree/</guid><description>&lt;p&gt;Here we&amp;rsquo;re going to cover what are Minimum Spanning Trees (MSTs), methods for finding them and use cases.&lt;/p&gt;

&lt;h2 class="relative group"&gt;What is a tree?
 &lt;div id="what-is-a-tree" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#what-is-a-tree" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;In graph theory we call graph $T=(V,E)$ a tree if it is connected and it doesn&amp;rsquo;t have any cycles.&lt;/p&gt;
&lt;div class="admonition relative overflow-hidden rounded-lg border-l-4 my-3 px-4 py-3 shadow-sm" data-type="info"&gt;
 &lt;div class="flex items-center gap-2 font-semibold text-inherit"&gt;
 &lt;div class="flex shrink-0 h-5 w-5 items-center justify-center text-lg"&gt;&lt;span class="relative block icon"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"&gt;&lt;path fill="currentColor" d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 128c17.67 0 32 14.33 32 32c0 17.67-14.33 32-32 32S224 177.7 224 160C224 142.3 238.3 128 256 128zM296 384h-80C202.8 384 192 373.3 192 360s10.75-24 24-24h16v-64H224c-13.25 0-24-10.75-24-24S210.8 224 224 224h32c13.25 0 24 10.75 24 24v88h16c13.25 0 24 10.75 24 24S309.3 384 296 384z"/&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/div&gt;
 &lt;div class="grow"&gt;
 Forrest
 &lt;/div&gt;
 &lt;/div&gt;&lt;div class="admonition-content mt-3 text-base leading-relaxed text-inherit"&gt;&lt;p&gt;We call a graph with no cycles a forrest (contrary to the tree it doesn&amp;rsquo;t need to be connected). In a forrest each &lt;strong&gt;connected component&lt;/strong&gt; is a tree.&lt;/p&gt;</description></item></channel></rss>