<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Algos on Ctrl &#43; Champagne</title>
    <link>/tags/algos/</link>
    <description>Recent content in Algos on Ctrl &#43; Champagne</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 06 Jun 2025 13:45:56 +0000</lastBuildDate>
    <atom:link href="/tags/algos/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Bron to Clique</title>
      <link>/posts/aoc24_23/</link>
      <pubDate>Fri, 06 Jun 2025 13:45:56 +0000</pubDate>
      <guid>/posts/aoc24_23/</guid>
      <description>&lt;h2 id=&#34;discovery-of-bron-kerbosch-in-aoc24-23&#34;&gt;Discovery of Bron-Kerbosch in AoC24-23&lt;/h2&gt;&#xA;&lt;p&gt;For part 2 of this challenge, I am actually ashamed of showing here what I initially tried to program without knowing what a&#xA;clique was, nor that an algorithm existed to find the maximal cliques in a graph&amp;hellip;&#xA;Maybe one day when I add a Premium Pass to this blog, a few privileged users could see the &lt;em&gt;pépite&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;/posts/aoc24_23/23.jpeg&#34; alt=&#34;text&#34;&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;part-1---the-piece-of-&#34;&gt;Part 1 - the piece of 🍰&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;As The Historians wander around a secure area at Easter Bunny HQ, you come across posters for a LAN party scheduled for today! &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Maybe you can find it; you connect to a nearby datalink port and download a map of the local network (your puzzle input).&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;The network map provides a list of every connection between two computers. For example:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;kh-tc&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;qp-kh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;de-cg&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ka-co&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Each line of text in the network map represents a single connection; the line kh-tc represents a connection between the &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;computer named kh and the computer named tc. Connections aren&amp;#39;t directional; tc-kh would mean exactly the same thing.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;LAN parties typically involve multiplayer games, so maybe you can locate it by finding groups of connected computers. &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Start by looking for sets of three computers where each computer in the set is connected to the other two computers.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;If the Chief Historian is here, and he&amp;#39;s at the LAN party, it would be best to know that right away. You&amp;#39;re pretty &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sure his computer&amp;#39;s name starts with t, so consider only sets of three computers where at least one computer&amp;#39;s name &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;starts with t. That narrows the list down to 7 sets of three inter-connected computers:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;co,de,ta&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;co,ka,ta&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;de,ka,ta&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;qp,td,wh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tb,vc,wq&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tc,td,wh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;td,wh,yn&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Find all the sets of three inter-connected computers. How many contain at least one computer with a name that starts &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;with t?&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;initial-thoughts&#34;&gt;Initial Thoughts&lt;/h4&gt;&#xA;&lt;p&gt;Setting the &amp;ldquo;starts with t&amp;rdquo; requirement aside, the list of computers given is a list of edges connecting two computers&#xA;(nodes).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Finishing your thoughts since... you started typing</title>
      <link>/posts/trie/</link>
      <pubDate>Tue, 18 Mar 2025 13:45:56 +0000</pubDate>
      <guid>/posts/trie/</guid>
      <description>&lt;h2 id=&#34;typeahead-system&#34;&gt;Typeahead System&lt;/h2&gt;&#xA;&lt;h3 id=&#34;a-little-background&#34;&gt;A little background&lt;/h3&gt;&#xA;&lt;p&gt;An autocomplete system, also called typeahead, is a feature often experienced&#xA;by users while typing in a search bar (or your IDE for that matter).&#xA;The software suggests the rest of a word or word sequence based on what&#xA;the user has already typed.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;/posts/trie/autocomp.png&#34; alt=&#34;text&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;These suggestions can be ranked depending on how often/popular a search is. Remember that gorgeous Versace dress&#xA;J-Lo wore for the Grammy Awards back in 2000? Everyone googled it - in fact it became the most popular search query at the&#xA;time and - fun fact - prompted Google engineers to develop the image search!&#xA;The objective is to make user searches more efficient and reduce the amount of typing required, while keeping the&#xA;suggestions relevant with current search trends.&lt;/p&gt;</description>
    </item>
    <item>
      <title>No Huff and Puff—Just Compress!</title>
      <link>/posts/huffman/</link>
      <pubDate>Sun, 16 Mar 2025 13:45:56 +0000</pubDate>
      <guid>/posts/huffman/</guid>
      <description>&lt;h2 id=&#34;the-huffmans-algorithm&#34;&gt;The Huffman&amp;rsquo;s Algorithm&lt;/h2&gt;&#xA;&lt;p&gt;The Huffman&amp;rsquo;s algorithm was born in 1952 as a way to perform a lossless compression&#xA;on data files. Its efficiency comes from the frequency analysis of characters&#xA;present in the text to encode: shorter codes are used to encode more frequent characters&#xA;while longer codes are used to encore less frequent ones.&lt;/p&gt;&#xA;&lt;p&gt;It constitutes the foundation of modern text compression.&lt;/p&gt;&#xA;&lt;p&gt;You can read more on variable-length encoding and tree representations&#xA;under the Design tag on this blog.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sorting Spree</title>
      <link>/posts/lc_23/</link>
      <pubDate>Sun, 23 Feb 2025 13:45:56 +0000</pubDate>
      <guid>/posts/lc_23/</guid>
      <description>&lt;h2 id=&#34;lc23---merge-k-sorted-lists&#34;&gt;LC23 - Merge k Sorted Lists&lt;/h2&gt;&#xA;&lt;h3 id=&#34;problem-statement&#34;&gt;Problem Statement&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.&#xA;Merge all the linked-lists into one sorted linked-list and return it.&#xA;&#xA;# Definition for singly-linked list.&#xA;# class ListNode:&#xA;#     def __init__(self, val=0, next=None):&#xA;#         self.val = val&#xA;#         self.next = next&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;smelling-like-merge-sort-in-the-air&#34;&gt;Smelling like merge sort in the air?&lt;/h3&gt;&#xA;&lt;p&gt;We know each list is already in sorted order. Does it remind us of the merge step from a classic merge-sort algorithm?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Why compare when you can just count?</title>
      <link>/posts/buckersort/</link>
      <pubDate>Sun, 23 Feb 2025 13:45:56 +0000</pubDate>
      <guid>/posts/buckersort/</guid>
      <description>&lt;h2 id=&#34;the-bucket-sort-algorithm&#34;&gt;The Bucket Sort algorithm&lt;/h2&gt;&#xA;&lt;h3 id=&#34;lc75---example-of-sorting-colors&#34;&gt;LC75 - example of Sorting Colors&lt;/h3&gt;&#xA;&lt;p&gt;The problem statement is as below.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;are adjacent, with the colors in the order red, white, and blue.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;You must solve this problem without using the library&amp;#39;s sort function.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Solution&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;sortColors&lt;/span&gt;(self, nums: List[int]) &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Do not return anything, modify nums in-place instead.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# bucket sort &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        value_range &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;#red, white or blue&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        counts &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; value_range&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; i, n &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(nums):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            counts[n] &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        i &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; value, freq &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(counts):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            print(value, freq)  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; _ &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(freq):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                nums[i] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; value&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                i &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;quick-rundown&#34;&gt;Quick rundown&lt;/h3&gt;&#xA;&lt;p&gt;The bucket sort algorithm relies on the fact that values belong to a known range. In this example it is &lt;code&gt;[0,2] ∈ Z&lt;/code&gt;.&#xA;The input arrays have already been prepared, by &lt;em&gt;encoding&lt;/em&gt; categorical values into numerical ones. The same&#xA;thing could be said about a different numerical range where the start of range is re-indexed or shifted back to 0.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Valentine&#39;s Matchmaker Algorithm 💖</title>
      <link>/posts/lc_765/</link>
      <pubDate>Sat, 22 Feb 2025 13:45:56 +0000</pubDate>
      <guid>/posts/lc_765/</guid>
      <description>&lt;h2 id=&#34;lc765---couples-holding-hands&#34;&gt;LC765 - Couples holding hands&lt;/h2&gt;&#xA;&lt;h3 id=&#34;problem-statement&#34;&gt;Problem Statement&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;There are n couples sitting in 2n seats arranged in a row and want to hold hands.&#xA;The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. &#xA;The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), &#xA;and so on with the last couple being (2n - 2, 2n - 1).&#xA;&#xA;Return the minimum number of swaps so that every couple is sitting side by side. &#xA;A swap consists of choosing any two people, then they stand up and switch seats.&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;initial-solution&#34;&gt;Initial solution&lt;/h3&gt;&#xA;&lt;p&gt;The below solution provides an O(n) time complexity and memory.&#xA;Relatively simply, checking for every pair of people, if the left-hand side person is not seated next to its beloved, then we swap the right person next to them.&lt;/p&gt;</description>
    </item>
    <item>
      <title>AoC24 - Some stone blinking</title>
      <link>/posts/aoc24_11/</link>
      <pubDate>Sun, 09 Feb 2025 13:45:56 +0000</pubDate>
      <guid>/posts/aoc24_11/</guid>
      <description>&lt;h2 id=&#34;who-said-aoc25-11-should-be-complicated&#34;&gt;Who said AoC25-11 should be complicated?&lt;/h2&gt;&#xA;&lt;h3 id=&#34;the-challenge&#34;&gt;The Challenge&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;The ancient civilization on Pluto created stones that change every time you blink. Each stone follows specific transformation rules:&#xA;- A stone marked 0 becomes 1.&#xA;- A stone with an even number of digits splits into two stones, each half of the original number.&#xA;- Any other stone is replaced by a new one, with its number multiplied by 2024.&#xA;The stones remain in order, and their transformations continue with each blink. For example, the sequence [0, 1, 10, 99, 999] would change to [1, 2024, 1, 0, 9, 9, 2021976] after one blink.&#xA;Part 1: blink 25 times. Part 2: blink 75 times.&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Full description available &lt;a href=&#34;https://adventofcode.com/2024/day/11&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
