<?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: Juancho J Barroso</title>
    <description>The latest articles on DEV Community by Juancho J Barroso (@juanchojbarroso).</description>
    <link>https://dev.to/juanchojbarroso</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%2F2030434%2Fac464b95-c2ad-489c-a0a5-3f69d06fb745.jpeg</url>
      <title>DEV Community: Juancho J Barroso</title>
      <link>https://dev.to/juanchojbarroso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juanchojbarroso"/>
    <language>en</language>
    <item>
      <title>Simple search vs Binary search</title>
      <dc:creator>Juancho J Barroso</dc:creator>
      <pubDate>Sun, 09 Feb 2025 22:36:30 +0000</pubDate>
      <link>https://dev.to/juanchojbarroso/simple-search-vs-binary-search-35g</link>
      <guid>https://dev.to/juanchojbarroso/simple-search-vs-binary-search-35g</guid>
      <description>&lt;p&gt;by Aditya Y. Bhargava&lt;/p&gt;

&lt;p&gt;This book is aimed at anyone who knows the basics of coding and wants to understand algorithms. Maybe you already have a coding problem and are trying to find an algorithmic solution.&lt;/p&gt;

&lt;h1&gt;
  
  
  1.  Introduction to #algorithms
&lt;/h1&gt;

&lt;p&gt;In this chapter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You get a foundation for the rest of the book.&lt;/li&gt;
&lt;li&gt;You write your first search algorithm (binary search)&lt;/li&gt;
&lt;li&gt;You learn how to talk about the running time of an algorithm (Big O notation).&lt;/li&gt;
&lt;li&gt;You’re introduced to a common technique for designing algorithms (recursion).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Binary search
&lt;/h2&gt;

&lt;p&gt;Binary search is an #algorithm; its input is a sorted list of elements. If an element you’re looking for is in that list, binary search returns the position where it’s located. &lt;/p&gt;

&lt;p&gt;Otherwise, binary search returns null.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple search vs Binary search
&lt;/h3&gt;

&lt;p&gt;Simple search (maybe stupid search would be a better term). With each guess, you’re eliminating only one number. If my number was 99, it could take you 99 guesses to get there!&lt;/p&gt;

&lt;p&gt;With binary search, you guess the middle number and eliminate half the remaining numbers every time. Let me explain: Same case (0-100) &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with 50. &lt;/li&gt;
&lt;li&gt;Too low, but you just eliminated half the numbers! &lt;/li&gt;
&lt;li&gt;Now you know that 1–50 are all  "too low" (You should skip all them)&lt;/li&gt;
&lt;li&gt;Next guess: 75. &lt;/li&gt;
&lt;li&gt;Too high, but again you cut down half the remaining numbers! (Skip 75 to 100)&lt;/li&gt;
&lt;li&gt;Next is 63 (halfway between 50 and 75).&lt;/li&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose you’re looking for a word in the dictionary. The dictionary has 240,000 words. In the worst case, how many steps do you think each search will take?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple search could take 240,000 steps.&lt;/li&gt;
&lt;li&gt;Binary search will take 18 steps.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;binary_search&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;low&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;high&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;low&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;high&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;low&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;high&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;guess&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt;   &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;guess&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;guess&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;high&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;low&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&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="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;binary_search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exercise:
&lt;/h3&gt;

&lt;p&gt;Suppose you have a sorted list of 128 names, and you’re searching through it using binary search. &lt;/p&gt;

&lt;p&gt;What’s the maximum number of steps it would take?&lt;/p&gt;

&lt;p&gt;The maximum number of steps binary search takes can be determined using the formula:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;log_2(n)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;where nn is the number of elements in the list. In this case, n=128n = 128:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;log_2(128) = 7&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, the maximum number of steps it would take to find a name in a sorted list of &lt;strong&gt;128 names&lt;/strong&gt; using binary search is &lt;strong&gt;7 steps&lt;/strong&gt;. 🚀&lt;/p&gt;

&lt;p&gt;Suppose you double the size of the list. What’s the maximum number of steps now?&lt;/p&gt;

&lt;p&gt;If you &lt;strong&gt;double&lt;/strong&gt; the size of the list from &lt;strong&gt;128 to 256&lt;/strong&gt;, the maximum number of steps required by binary search is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;log_2(256) = 8&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, with &lt;strong&gt;256 names&lt;/strong&gt;, the maximum number of steps needed is &lt;strong&gt;8&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This demonstrates the power of binary search—every time the list size &lt;strong&gt;doubles&lt;/strong&gt;, the number of steps increases by just &lt;strong&gt;1&lt;/strong&gt;! 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  Big O notation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Big O notation is special notation that tells you how fast an algorithm is.&lt;/li&gt;
&lt;li&gt;Big O notation lets you compare the number of operations. It tells you how fast the algorithm grows.&lt;/li&gt;
&lt;li&gt;Run time of algorithms is expressed in Big O notation.&lt;/li&gt;
&lt;li&gt;Algorithm speed isn’t measured in seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;![[Screenshot 2025-02-09 at 21.52.48.png]]&lt;/p&gt;

&lt;h3&gt;
  
  
  Some common Big O run times
&lt;/h3&gt;

&lt;p&gt;Here are five Big O run times that you’ll encounter a lot, sorted from fastest to slowest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;O(log n), also known as log time. Example: Binary search.&lt;/li&gt;
&lt;li&gt;O(n), also known as linear time. Example: Simple search.&lt;/li&gt;
&lt;li&gt;O(n * log n). Example: A fast sorting algorithm, like quicksort (coming up in chapter 4).&lt;/li&gt;
&lt;li&gt;O(n2). Example: A slow sorting algorithm, like selection sort (coming up in chapter 2).&lt;/li&gt;
&lt;li&gt;O(n!). Example: A really slow algorithm, like the traveling salesperson (coming up next!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Salesperson problem.
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You have a salesperson.&lt;/li&gt;
&lt;li&gt;The salesperson has to go to five cities.&lt;/li&gt;
&lt;li&gt;He adds up the total distance and then picks the path with the lowest distance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s called the traveling salesperson problem.&lt;/p&gt;

&lt;p&gt;This is a famous problem in computer science, because its growth is appalling and some very smart people think it can’t be improved. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are 120 permutations with 5 cities&lt;/li&gt;
&lt;li&gt;It will take 120 operations to solve the problem for 5 cities. &lt;/li&gt;
&lt;li&gt;For 6 cities, it will take 720 operations (there are 720 permutations). &lt;/li&gt;
&lt;li&gt;For 7 cities, it will take 5,040 operations!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>grokkingalgorithms</category>
      <category>algorithms</category>
      <category>typescript</category>
    </item>
    <item>
      <title>API Docs: The Unsung Hero of the API Economy - part 1</title>
      <dc:creator>Juancho J Barroso</dc:creator>
      <pubDate>Fri, 22 Nov 2024 00:05:30 +0000</pubDate>
      <link>https://dev.to/juanchojbarroso/api-docs-the-unsung-hero-of-the-api-economy-4hj3</link>
      <guid>https://dev.to/juanchojbarroso/api-docs-the-unsung-hero-of-the-api-economy-4hj3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is the first post in a series I’m starting about API docs, APIs, and Product. This idea came from my master’s final project (TFM) during my internship at &lt;a href="https://salsa.dev" rel="noopener noreferrer"&gt;Salsa&lt;/a&gt;, where I got to work with talented engineers. I’m excited to share my research in a more engaging way than just reading a thesis. Plus, writing this will help me improve my skills and keep learning more about the tech world. Stay tuned for more posts!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  API Docs &amp;amp; API Economy
&lt;/h2&gt;

&lt;p&gt;APIs have revolutionized the way we build software. By enabling the shift from clunky monolithic apps to sleek cloud-based microservices, they’ve opened the door to a whole new world of agility and innovation. The “API economy,” where companies are no longer just creating products for users but are also building for other companies. These businesses play two roles: &lt;strong&gt;API consumers&lt;/strong&gt; and &lt;strong&gt;API producers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The goal? Build faster, innovate smarter, and deliver value with fewer resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Secret Sauce of API Success: Documentation
&lt;/h2&gt;

&lt;p&gt;Imagine companies like &lt;a href="https://docs.stripe.com/api" rel="noopener noreferrer"&gt;Stripe&lt;/a&gt;, &lt;a href="https://www.twilio.com/docs" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt;, or &lt;a href="https://docs.salsa.dev/docs" rel="noopener noreferrer"&gt;Salsa&lt;/a&gt;—big players in the digital infrastructure game. They’ve embraced APIs not just as tools but as the very &lt;strong&gt;foundation of their products.&lt;/strong&gt; APIs have become building blocks, empowering developers to create faster, more efficiently, and with fewer resources. But there’s a twist: &lt;/p&gt;

&lt;p&gt;APIs are not just for tech experts anymore; they are now important for businesses. In this new world, the key to success is definitely good documentation.&lt;/p&gt;

&lt;p&gt;Yes, you read that right. &lt;strong&gt;Documentation&lt;/strong&gt; isn’t just a sidekick—it’s the hero of the story. A well-crafted API doc isn’t just a user manual; &lt;strong&gt;it’s a deal closer.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Here’s the truth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bad documentation = Frustration 😡
&lt;/li&gt;
&lt;li&gt;Good documentation = Trust 🛠️&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bad documentation is like a GPS with missing streets—it’s frustrating and makes people turn back. Good documentation, on the other hand, can win over even the most skeptical developers. It builds trust, simplifies integration, and makes your product stand out in an increasingly crowded market.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Developers Want (and Why Your Docs Might Be Failing)
&lt;/h2&gt;

&lt;p&gt;Developers are busy, so your documentation needs to work &lt;em&gt;for them&lt;/em&gt;. This means:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;developer portal&lt;/strong&gt; that’s easy to navigate.
&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;sandbox environment&lt;/strong&gt; for testing APIs directly in the browser.
&lt;/li&gt;
&lt;li&gt;Real-world examples that show how to solve common problems.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚨🚨 Why? Because developers—your new customers—rely on it to understand, evaluate, and ultimately decide whether your product is worth integrating.🚨🚨&lt;/p&gt;

&lt;p&gt;But what does &lt;em&gt;great&lt;/em&gt; API documentation actually look like? (I’ll dive deeper into that in my next post!)&lt;/p&gt;

&lt;h2&gt;
  
  
  Docs: A Living Part of Your Software Lifecycle
&lt;/h2&gt;

&lt;p&gt;Good documentation isn’t static. It needs to evolve with your product, integrating seamlessly into modern software practices like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code reviews&lt;/strong&gt; to keep examples accurate.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version control&lt;/strong&gt; for tracking changes.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD pipelines&lt;/strong&gt; to ensure updates are delivered in real-time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By treating documentation as part of the development lifecycle, you’re not just helping developers—you’re creating a better product experience for everyone.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Great documentation doesn’t just happen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why This Matters More Than Ever
&lt;/h2&gt;

&lt;p&gt;In the API economy, your competition isn’t just about features or pricing—it’s about the experience you deliver. If your documentation makes life easier for developers, they’ll be more likely to adopt your API, recommend it to others, and build amazing things with it.  &lt;/p&gt;

&lt;p&gt;On the flip side, poor documentation can ruin even the best product. Don’t let that happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If your business depends on APIs, it’s time to give your docs the attention they deserve. Make them clear. Make them useful. Make them part of your process. &lt;/p&gt;

&lt;p&gt;Because in today’s world, &lt;strong&gt;great docs aren’t optional—they’re your competitive advantage.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;What’s your take on API documentation? Have you come across any examples that stood out—for better or worse? Let me know in the comments! 👇&lt;/p&gt;

</description>
      <category>api</category>
      <category>documentation</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
