<?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 Diógenes Dassan Feijó on Medium]]></title>
        <description><![CDATA[Stories by Diógenes Dassan Feijó on Medium]]></description>
        <link>https://medium.com/@diogenes.feijo?source=rss-460dbe7bdb94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dMeX7fnDjOt4yPGB.jpg</url>
            <title>Stories by Diógenes Dassan Feijó on Medium</title>
            <link>https://medium.com/@diogenes.feijo?source=rss-460dbe7bdb94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:37:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diogenes.feijo/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[Data Structures and Algorithms Must Be Best Friends]]></title>
            <link>https://medium.com/@diogenes.feijo/data-structures-and-algorithms-must-be-best-friends-1156afa5ddb6?source=rss-460dbe7bdb94------2</link>
            <guid isPermaLink="false">https://medium.com/p/1156afa5ddb6</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Diógenes Dassan Feijó]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 19:53:40 GMT</pubDate>
            <atom:updated>2018-11-28T19:53:40.308Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t13gDMUTumSgeXW8ZQjsyA.jpeg" /></figure><p>In programming, algorithm is a set of well defined instructions in sequence to solve a problem. It’s written in some human-friendly language that can be intepreted by computers. A software is actually a bunch of algorithms that run synchronously and / or asynchronously.</p><p>In order to work, algorithms must make use of data. The data is either created or received from outside as an input and then manipulated by the algorithm. Most of times our algorithms need a bunch of data and a way to organize them.</p><h3>Enter Data Structures</h3><p>A data structure is an arbitrary construct used to describe how to store data in a system. It may be as simple as a single primitive, or as complex as a class.</p><p>They are used to minimize the cost of access and to organize the bits in RAM.</p><p>It’s an organized collection of values that is specialized for its own thing.</p><p>Let’s get things cleared up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*7_vtVK54UNxOaEdpGu07UQ.png" /><figcaption>Examples of real world data structures</figcaption></figure><p>As you can see in the above image we have:</p><ul><li><strong>A)</strong> A backpack</li><li><strong>B)</strong> A drawer</li><li><strong>C)</strong> A fridge</li><li><strong>D)</strong> A box</li><li><strong>E)</strong> A folder</li></ul><blockquote>Each of these real world data structures are specialized to organize some sort of data.</blockquote><p>You can put food on the fridge or get food from it. You can put some documents in the folder and sort them by date. Clothes in the drawer sorted by color. Sometimes we can mix things up. You can also put food in the drawer or food on the folder, but, would it be wise?</p><p>As in real life we have a ton of data structures to use in our programs. Just take a look at this link in Wikipedia and you will be impressed:</p><p><a href="https://en.wikipedia.org/wiki/List_of_data_structures">List of data structures - Wikipedia</a></p><h3>Choosing wisely</h3><blockquote>Good programmers pick the right data sctructures for the right algorithms.</blockquote><p>As a programmer you must take chaos and disorder and make order out of it. Just like we do in real life with our fridges and folders. We model real life scenarios. And the more advanced as a developer you become the more you will expend time thinking about data structures to optimize your algorithms.</p><p>Some data structures are better than the other for some aspects. That’s why they exist. Each one for a specific case. So it’s very important to choose wisely which one to use or if necessary to create one.</p><h3>Operations</h3><p>There are a common set of operations that we usually must do in data structures:</p><ul><li><strong>Access</strong></li><li><strong>Insertion</strong></li><li><strong>Deletion</strong></li><li><strong>Traversal</strong></li><li><strong>Searching</strong></li><li><strong>Sorting</strong></li></ul><p>Each one of them has a space and time complexity that you must take in account when using in your code.</p><p>Do you remember Big-O?</p><p><a href="https://medium.com/@diogenes.feijo/the-limiting-behavior-or-just-big-o-333bdb03c2bb">The Limiting Behavior … or just Big-O</a></p><p>Here you can find the complexities of the most common operations in data structures:</p><p><a href="http://bigocheatsheet.com/">Know Thy Complexities!</a></p><p>You also must be aware when using built-in algorithms of the programming languages. Look for the documentation and you shall find a more detailed explanation and even the complexities involved.</p><h3>Conclusion</h3><blockquote>Data Structures + Algorithms = Programs</blockquote><p>We usually give more importance in what language we’ll use for coding rather than take some serious time thinking and reflecting about which would be the best data structures to fit our algorithms.</p><p>Those choices have an imense impact in the overall program performance. That’s why big companies such as Google, Facebook or Amazon look for programmers that rather than knowing fancy programming languages know first how to build great algorithms with the right data structures to optimize performance and get the best out of computers.</p><p>Let’s keep on practicing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1156afa5ddb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Limiting Behavior … or just Big-O]]></title>
            <link>https://medium.com/@diogenes.feijo/the-limiting-behavior-or-just-big-o-333bdb03c2bb?source=rss-460dbe7bdb94------2</link>
            <guid isPermaLink="false">https://medium.com/p/333bdb03c2bb</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Diógenes Dassan Feijó]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 13:56:28 GMT</pubDate>
            <atom:updated>2018-11-28T11:26:30.156Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Limiting Behavior … or just Big-O</h3><p>As a programmer, literally there are only two things that you should know how to deal with very well above all others: <strong><em>Space </em></strong>and <strong><em>Time</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*jDfvzTln3PvN7_iMUftD6Q.png" /></figure><p>A computer has limited resources. It has limited space (memory/storage) and limited processing power (CPU). So, when you write any code, the efficiency of it depends on how well you deal with those limitations to get the desired result on an optimal time using an optimal space.</p><p>So regardless of what programming language you use, you should be more concerned of how well your algorithms are written and how do you get the most of the space and time of a computer.</p><h4>Measuring the efficiency of a code</h4><p>Imagine that you’ve written a nice piece of code using a fancy programming language that runs on 2ms on your machine. Proudly, you send this code to your friend and tell him of your achievement. Your friend runs the code and tell you that it doesn’t look so nice because it took 200ms to run on his machine. You feel sad :/ … what the hell happened?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*iAv_VygP2G6Jt7gbQ0AVGA.png" /><figcaption>Fast Computer vs Slow Computer</figcaption></figure><p>Two different computer in terms of computational power and memory space running the same code would present different results in regard of time. Or even no result at all if it exceeds its limits.</p><blockquote>We can’t measure the performance or the efficiency of a code using time by itself.</blockquote><h4>Enter Asymptotic Analysis</h4><blockquote>Asymptotic analysis of an algorithm refers to defining the mathematical boundation of its run-time performance. <strong>Using it, we can conclude the best case, average case, and worst case scenario of an algorithm.</strong></blockquote><p>Read the above quotation 50 times and you may not fully understand. But the important thing to understand is the bolded part.</p><p>Let’s get things simplified.</p><p>Using asymptotic analysis we are no longer concerned about how many milliseconds some algorithm will need to run but how its performance is going to behave mathematically.</p><blockquote>It tells you how well a problem is solved!</blockquote><p>The analysis is mainly input bound. If there’s no input to the algorithm, it is concluded to work in a constant time. Other than the input, all other factors are considered constant. Let’s see some examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*9Otd5UivtKQa7sXqTSUf6w.png" /><figcaption>A function that runs in constant time</figcaption></figure><p>The code above is said to take constant time to run because it has no input. That is, no matter how many times you run it or what type of computer you use, it will perform constantly. It depends only of itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*61yCiKjqcPQOrT20xJFr4g.png" /><figcaption>A function that runs in linear time</figcaption></figure><p>The function above receives an input (names) as argument and, as we can see, does some heavy load processing inside of it that even Tim Berners-Lee would be proud.</p><p>Asymptotically analyzing it, we can see that as the input size grows our run-time increases linearly, because we loop through the items of the input to do some constant processing. The image below will enlighten things up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*t_Qwsklh0A9PDhYbqzDZKw.png" /><figcaption>Linear time operations</figcaption></figure><p>As the number of elements increases in the input the number of operations increases in a linear fashion.</p><p>So, which is better? A constant time algorithm or a linear one? Pretty sure that it’s the constant one, because it will always take a constant amount of time to execute. On the linear one, the amount of time will grow linearly as the input grows. That way its limiting behavior is bounded to its input.</p><blockquote><strong>Which one is faster?</strong></blockquote><p><strong>It doesn’t matter.</strong> Remember, we are measuring the time performance of its limiting behavior and not its speed. We are measuring the efficiency of an algorithm.</p><p>That’s the purpose of the Asymptotic Analysis. To give us a parameter to see if we are writing good code.</p><h4>What’s good code?</h4><p>A good code is said to be both:</p><ul><li><strong>Readable (by humans)</strong></li><li><strong>Scalable (in time and space)</strong></li></ul><p>Readability comes with the good practices on writing code (names, conventions, patterns, etc). The less you need to explain your code to others the better the readability.</p><p>Regarding the scalability we need to ensure that our code runs in an optimal time and uses the space (memory) the as best as possible as the processing demand increases.</p><blockquote>To analyze if our code is scalable we use the Asymptotic Analysis.</blockquote><h4>The Big-O Notation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*kCBq2mibJbUPohUTMF_ZJQ.jpeg" /><figcaption>Tip: Never do this</figcaption></figure><p>It’s nothing more than the notation that we use to define the limiting behavior of our algorithm using the asymptotic analysis that we’ve seen.</p><blockquote><em>In computer science, Big-O notation is used to classify algorithms according to how their running time or space requirements grow as the input size grows.</em></blockquote><p>We use it to denote the complexity (performance) of our algorithm in a matter of <strong>space </strong>and <strong>time</strong> for the <strong>worst case scenario.</strong></p><p>There are also two other important notations that we won’t discuss here but work the same way as Big-O and you should take a look at too:</p><ul><li><strong>Θ:</strong> <strong>Theta notation </strong>for the <strong>average case scenario</strong></li><li><strong>Ω:</strong> <strong>Omega notation </strong>for the <strong>best case scenario</strong></li></ul><p>We often only use Big-O to determine the worst case scenario because it’s the most important thing to know for scalability issues. So if we say that a given algorithm has a time complexity of “O(n)” we are talking about the worst case scenario.</p><p>With the Big-O notation we can determine two things about our algorithm:</p><ul><li><strong>Time complexity</strong></li><li><strong>Space complexity</strong></li></ul><blockquote>We will talk about space complexity later.</blockquote><p><strong>In regard of time complexity</strong>, as we have seen, it’s about how many steps the algorithm has to perform, given a certain input, and not about how much time it uses to do so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*oelMzrRTP6afz3TSOyxJrQ.png" /></figure><p>Let’s detail the complexities above in regard of time from best to worst:</p><ul><li><strong>O(1)</strong> — Constant (no loops)</li><li><strong>O(log n)</strong> — Logarithmic. The elements on which the action is performed are digits of the input. Usually searching algorithms have log n if they are sorted (Binary Search using divide-and-conquer). In a logarithmic time scale doubling the size of the input data set has little effect on its growth. A single iteration just halves the input data so it is more efficient for handling large sets.</li><li><strong>O(n) </strong>— Linear (loops)</li><li><strong>O(n log n)</strong> — Logarithmic linear (sorting operations)</li><li><strong>O(n²) </strong>— Quadratic. Every element in the input needs to be compared to ever other element. Two nested loops.</li><li><strong>O(2^n) </strong>— Exponential. Recursive algorithms that solves a problem of the input size.</li><li><strong>O(n!) </strong>— Factorial. Adding a loop for every element of the input.</li></ul><blockquote>It answers the question: How quickly the run-time grows?</blockquote><h4>What can cause Time Complexity in a code?</h4><ul><li>Operations (+, -, *, /)</li><li>Comparisons (&lt; , &gt;, ==)</li><li>Looping (for, while)</li><li>Outside function/method call</li></ul><p>Operations and comparisons usually generates constant time. Looping and outside function/method calls can generate all sort of things.</p><p>The final time complexity of the algorithm will be the sum of all time complexities inside it, as we can see below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*e0dxTL1v6HitS5akkBmJyQ.png" /><figcaption>Calculating the time complexity</figcaption></figure><p>If we have different inputs we shall use different identifiers in the notation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*M7WXS4tR91VAIYhhuB73vg.png" /><figcaption>Calculating with different inputs</figcaption></figure><p>In the case above, as the loops are not nested, we sum them up. Which won’t be the case if they were nested:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*KNeSDlnsITst9uhRDDxluw.png" /><figcaption>Calculating with different inputs (nested)</figcaption></figure><p>In this case we have to multiply the complexities as each item of array1(a) calls for a nested loop of array2(b).</p><h4>Some rules to follow</h4><p><strong>Rule 1:</strong> <strong>Always use the worst case</strong></p><p>For example: iterating through half a collection is still <em>O(n)</em> as we are assuming the worst case scenario. It doesn’t matter if you break the loop when you find something in the collection. You have to assume that in the worst case the algorithm might iterate over all items to find something.</p><p><strong>Rule 2:</strong> <strong>Remove Constants</strong></p><p>We should remove the constants of the calculation as they have little or no impact in the final result.</p><p>So <em>O(4 + n)</em> should be <em>O(n)</em>.</p><p>Let’s assume that N could reach the value of 20 Trillions of data. What’s 4 compared to 20 trillions? So we discard it to keep simplier.</p><p><strong>Rule 3: Different inputs should have different variables.</strong></p><p>If your algorithm has multiple inputs you should use different variables in the notation to differentiate them in the final calculation. Like in the below example you could use A for <em>array1 </em>and B for <em>array2</em>.</p><p><em>function(array1, array2) { }</em></p><p>Somethings to be aware:</p><ul><li>Sum for steps in order:<em> O(a + b)</em>.</li><li>Multiply for nested steps:<em> O(a * b)</em></li></ul><p><strong>Rule 4: Drop non-dominant terms</strong></p><p>Let’s assume that we have an algorithm with time complexity of:</p><p><em>O(</em><strong><em>n²</em></strong><em> +2n + 300 +n/2)</em></p><p>Carefully analyzing we can determine that as the size of <em>N</em> increases the most impactful term is <strong><em>N² (quadratic)</em></strong>. It’s the <strong>dominant term</strong> that has the most impact in the algorithm efficiency (look at the complexity chart again). So we could drop all others and still have a pretty much idea of how bad (or good) this algorithm is.</p><p>So we can simply write: <strong><em>O(n²)</em></strong></p><h4>Examples</h4><p>I recommend you to take a look at the link below to better understand how each time complexity that we’ve seen works. It uses a Phone Book as example and perform some operations, classifying them from best to worst.</p><p><a href="https://stackoverflow.com/questions/2307283/what-does-olog-n-mean-exactly">What does O(log n) mean exactly?</a></p><h4>Space Complexity</h4><blockquote>Memory usually sacrifices speed and vice versa</blockquote><p>Having a good algorithm is not only about how well it deals with the time but also how well it deals with the space that’s available.</p><p>Programming languages usually define the memory of a program in:</p><ul><li><strong>Heap (variables)</strong></li><li><strong>Stack (functions)</strong></li></ul><p>To analyze space complexity using Big-O you have to determine all the space that’s used inside the algorithm (not considering the input).</p><p>It’s very similar to the time complexity. We simply look at the total space that is being used (allocated) relative to the size of the input (or none if it’s constant).</p><h4>What causes Space Complexity?</h4><ul><li>Variables</li><li>Data Structures</li><li>Function Calls</li><li>Allocations</li></ul><p>Let’s take a look at some examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*h0oCaEHobmWPgkQNRpjJ_Q.png" /><figcaption>Constant space function</figcaption></figure><p>In the code above we can see that, as we do not consider the input, the space complexity of the function is constant. It does not create any additional space inside of it and only use the input to write in the console. So it has a O(1) space complexity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*ewAjtukln85919032xZ6dQ.png" /><figcaption>Linear space function</figcaption></figure><p>Here we have a precious code that produces an amount of space in the same size order as its input. It has a O(n) space complexity.</p><h4>Wrapping Up</h4><p>We have seen the impact that an algorithm could have on a computer program regarding its time and space complexity. Also we have seen how to identify and measure them using the Asymptotic Analysis and the Big-O notation.</p><p>As developers sometimes we usually don’t give it the due importance and build things that won’t scale properly if demanded.</p><p>There’s much more to learn in the Big-O universe and we merely scratch the surface but i hope all we’ve seen here could be useful to excite you to search for more.</p><p>If you have noticed something wrong or have something to add please leave a comment.</p><p>See you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=333bdb03c2bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enter The Matrix]]></title>
            <link>https://medium.com/@diogenes.feijo/enter-the-matrix-b3b09502f7a4?source=rss-460dbe7bdb94------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3b09502f7a4</guid>
            <category><![CDATA[motivational]]></category>
            <category><![CDATA[stories]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[escrita]]></category>
            <category><![CDATA[escrita-criativa]]></category>
            <dc:creator><![CDATA[Diógenes Dassan Feijó]]></dc:creator>
            <pubDate>Fri, 12 Jan 2018 12:41:39 GMT</pubDate>
            <atom:updated>2018-01-12T12:41:39.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjKsaCgr_veKA5SA5As5ww.jpeg" /><figcaption>Neo em um mundo controlado por regras que não se aplicam a ele</figcaption></figure><p>Hoje notei que escrever estórias pode ser bem libertador. É difícil no começo mas assim que você ganha tração você entra em um estado de hipnose ou hiperfoco. Dependendo do texto que você escreve sua imaginação fica incrivelmente aguçada e toda uma cena se cria na sua cabeça. As personagens ganham vida com suas próprias personalidades e características. Assim como todos detalhes visuais e sonoros, os odores e sensações. E é o seu mundo ali. Você constrói, destrói, reconstrói, ajusta e estabelece as próprias leis. E no final você acaba conhecendo mais sobre você mesmo.</p><p>Para mim que gosto de programação de computadores e tecnologias é mais uma forma de criação. E assim como na programação, onde eu posso criar um sistema que faça alguma coisa, com a escrita eu posso criar também, mas muito além. É mais uma forma de expressão e liberdade. E o mais interessante agora que estou adentrando esta comunidade é que encontrei muitas pessoas como eu, programadores que também estão se aventurando na escrita.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*C9DdgwJ_0FifXoOz7mJUdw.jpeg" /><figcaption>Morpheus guia Neo em The Matrix</figcaption></figure><p>Quando você imagina estórias você é quase um Neo em The Matrix. As regras que antes te limitavam já não se aplicam mais a você. Você é livre para imaginar e se expressar. Mas quando se diz respeito a escrita e as limitações da linguagem, bem, você não é tão “Neo” assim. Quando as ideias saem da sua cabeça para o papel ou algum meio digital, elas entram em um mundo baseado em regras. Sintáticas, gramaticais, linguísticas, políticas, sociais e muitas outras. Muitas vezes precisamos de um Morpheus para nos guiar em como quebrar essas regras para que alcancemos o propósito da expressão. Alguém que nos mostre o caminho.</p><p>Entretanto:</p><blockquote>“Há uma diferença entre conhecer o caminho e trilhar o caminho”.</blockquote><p>Ou seja, além de conhecimento é necessário ação, com prática e disciplina.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*E3VLBpWpl24MBXsdr937wg.jpeg" /><figcaption>Temet Nosce (conhece-te a ti mesmo). Neo conhece o Oráculo.</figcaption></figure><p>Quanto mais nos conhecemos melhor conseguimos nos expressar pois nunca vemos além das escolhas que já fizemos. Tentamos apenas entende-las. E entender nossas escolhas é entender a nós mesmos.</p><p>Por isso escrevam estórias, componham músicas, pintem quadros, programem computadores ou utilizem qualquer outra forma de expressão, porque o mundo precisa conhecer você. Nós precisamos.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3b09502f7a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>