<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ken Luzuriaga</title>
    <description>The latest articles on DEV Community by Ken Luzuriaga (@kenluzu).</description>
    <link>https://dev.to/kenluzu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3850056%2Fdc36d720-e28c-49a2-a1d5-7838fd29a8a0.png</url>
      <title>DEV Community: Ken Luzuriaga</title>
      <link>https://dev.to/kenluzu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kenluzu"/>
    <language>en</language>
    <item>
      <title>Performance &amp; Recursion</title>
      <dc:creator>Ken Luzuriaga</dc:creator>
      <pubDate>Sun, 29 Mar 2026 21:08:46 +0000</pubDate>
      <link>https://dev.to/kenluzu/performance-recursion-7bd</link>
      <guid>https://dev.to/kenluzu/performance-recursion-7bd</guid>
      <description>&lt;p&gt;How can you count all the participants in an auditorium if you don't have sensors, check-in processes or access control?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Option 1:&lt;/strong&gt; Use my eyes and my mind to count them one by one: 1,2,3,4...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Option 2:&lt;/strong&gt; Count by twos, like 2,4,6,8,...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Option 3:&lt;/strong&gt; Ask the participants to follow these instructions:

&lt;ol&gt;
&lt;li&gt; Stand up and think of the number 1&lt;/li&gt;
&lt;li&gt; Pair off with someone standing, add their number to yours, and remember the sum&lt;/li&gt;
&lt;li&gt; One of you should then sit down&lt;/li&gt;
&lt;li&gt; If still standing, go back to step 2.
The final person standing will know the exact number of participants.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Option 3 is the most efficient and faster than the other methods. This is why algorithms are important.&lt;/p&gt;

&lt;p&gt;That's how the conference by David Malan begins. Malan is a Computer Science professor at Harvard University, and he's teaching how different ways of solving problems can lead to disaster or simply become a small everyday hurdle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance and Complexity
&lt;/h3&gt;

&lt;p&gt;Performance tells you how much slower a program becomes as the input grows. If I have 10 records to process, it takes &lt;em&gt;x&lt;/em&gt; time. But if I have 1 million records, will it take 1,000,000 * &lt;em&gt;x&lt;/em&gt;  time, or could it be different? This is known as &lt;strong&gt;Big O notation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the example of counting people in a room, it would be something like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Option 1&lt;/strong&gt; is &lt;em&gt;O(n)&lt;/em&gt; (Linear time). It takes as many steps as there are people. If there are 100 participants, this takes 100 steps&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Option 2&lt;/strong&gt; is &lt;em&gt;O(n/2)&lt;/em&gt;, still linear but slightly faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Option 3&lt;/strong&gt; is &lt;em&gt;O(log n)&lt;/em&gt; (Logarithmic time). If there are 100 participants, just takes 7 steps, because the number of people standing reduces by half in each round.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Recursion
&lt;/h3&gt;

&lt;p&gt;What makes option 3 the winning option? ✨ The recursion ✨&lt;br&gt;
Recursion is when a function calls itself to solve a smaller version of the same problem.&lt;/p&gt;

&lt;p&gt;Every recursive function needs a &lt;strong&gt;Base Case&lt;/strong&gt; to avoid running forever. Think of it as a 'Divide and Conquer' strategy: break the problem down until it’s simple enough to solve&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Matryoshka Doll (The Logic)&lt;/em&gt;&lt;br&gt;
Think of recursion like a Russian nesting doll. To find out how many dolls are inside, you don't just look at the big one; you follow these rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Recursive Step:&lt;/strong&gt; Open the current doll. If there is another one inside, repeat the process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Base Case:&lt;/strong&gt; Eventually, you reach the smallest doll that cannot be opened. This is where you stop and start counting back.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# base case
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# recursive case
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  The CS50 Auditorium (The Efficiency)
&lt;/h4&gt;

&lt;p&gt;David Malan uses a clever way to count people in a room. Instead of counting 1, 2, 3... (&lt;em&gt;O(n)&lt;/em&gt;), he uses a &lt;strong&gt;recursive strategy&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stand up&lt;/strong&gt; and assign yourself the number 1.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pair off&lt;/strong&gt; with someone else standing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add&lt;/strong&gt; your numbers together, and one person sits down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repeat&lt;/strong&gt; until only one person is left standing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Why it works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The problem is cut in half in every round. If you have 1,000 people, you only need about 10 rounds to find the total. This is the power of &lt;strong&gt;Logarithmic Time (&lt;em&gt;O(log n)&lt;/em&gt;)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmv856u275t6f5nt1i3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmv856u275t6f5nt1i3m.png" alt="Recursion step by step" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Download a summay in spanish:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://drive.google.com/file/d/1P24x1MLHxKQtc8raQBTimKkMEbmARdMm/view?usp=sharing" rel="noopener noreferrer"&gt;Recursion_Blueprint.pdf&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=6Svu_ae5ebk" rel="noopener noreferrer"&gt;CS50x 2026 - Lecture 3 - Algorithms&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  My blog
&lt;/h3&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://kenluzuriaga.com/recursion" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkenluzuriaga.com%2F_astro%2Fblog-3_portrait.C-ZsXquY_1Bdm06.jpg" height="444" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://kenluzuriaga.com/recursion" rel="noopener noreferrer" class="c-link"&gt;
            Performance &amp;amp; Recursion
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Solving problems by the smarter way
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkenluzuriaga.com%2F_astro%2Ffavicon.Dq0EFTCk.ico" width="256" height="215"&gt;
          kenluzuriaga.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>algorithms</category>
      <category>performance</category>
      <category>recursion</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
