<?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 Nemwel Onsando on Medium]]></title>
        <description><![CDATA[Stories by Nemwel Onsando on Medium]]></description>
        <link>https://medium.com/@nemwel.onsando?source=rss-d23e3f4fe706------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4L1EZgX0l3WG9uM2XFB_gQ.jpeg</url>
            <title>Stories by Nemwel Onsando on Medium</title>
            <link>https://medium.com/@nemwel.onsando?source=rss-d23e3f4fe706------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:02:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nemwel.onsando/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[Beginner’s guide on how to create a free Open Campus ID]]></title>
            <link>https://medium.com/@nemwel.onsando/beginners-guide-on-how-to-create-a-free-open-campus-id-7d86afe129c6?source=rss-d23e3f4fe706------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d86afe129c6</guid>
            <category><![CDATA[internships]]></category>
            <category><![CDATA[open-camous]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[risein]]></category>
            <dc:creator><![CDATA[Nemwel Onsando]]></dc:creator>
            <pubDate>Mon, 08 Apr 2024 13:42:52 GMT</pubDate>
            <atom:updated>2024-04-08T18:35:33.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*r2rb6JfiMYdIXRoxmVTPsA.png" /></figure><p>Do you remember that sinking feeling of textbooks stacked a mile high and lectures going over your head?<strong> <em>Ugh, I have been there too!</em></strong> But what if learning could be different, and imagine of a world where education is engaging, personalized, and actually rewarding?</p><p>This is where Open Campus comes in, as a revolutionary project built on blockchain technology that promises to transform learning. Open your doors to a world of engaging content, personalized learning paths, and even potential rewards — all unlocked with your very own Open Campus ID!</p><p>For a moment, I would like you to think of your Open Campus ID as your digital learning companion. A free profile that 1) grants you access to awesome educational resources, 2) that empowers you to track your progress like a champ, and 3) which holds your key to future rewards. Pretty cool, huh?</p><p>See this guide as your trusted companion as you embark on your Open Campus adventure. We are going to explore together two ways of claiming your Open Campus ID — whether you’re a crypto whiz or prefer a simpler approach of using your email address.</p><p>If you’re comfortable with crypto wallets and have an interest in exploring all features, choose the crypto wallet method. However, if you prefer a quicker signup option, simply use your existing email address. I’ll walk you through both methods in detail next.</p><p><strong>Part 1: How to claim your ID with a Crypto Wallet</strong></p><ol><li>Create a Crypto Wallet:<br>Here I am going to show you step by step how to connect your <strong>MetaMask</strong> wallet to open campus, but will not delve into how to create it. Kindly click on this link <a href="https://metamask.io/"><strong><em>https://metamask.io/</em></strong></a> and setup your wallet. Ones done proceed to step 2.</li><li>Connecting your wallet to Open Campus ID<br> Head over to the Open Campus ID website:<a href="https://id.opencampus.xyz/"> https://id.opencampus.xyz/</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qnw4sBIx06NysDRd" /></figure><p>3. Click on <strong><em>claim yours now </em></strong>button or<strong><em> sign in / sign up </em></strong>on the top right on the open campus home page. You will be taken to the following screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y_bFCLZkNeMMd-2u" /></figure><p>4. Click on the<strong><em> Connect walle</em></strong>t button to connect your crypto wallet. You will be taken to the following screen which displays a list of available wallets you can connect to open campus ID. In this demo we are going to use MetaMask</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/0*6doVt2dOXoweCiat" /></figure><p>5. Ensure your MetaMask wallet is fully set up. Click on the MetaMask link from Connect a Wallet window above. This takes to the screen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*Hmx75ydZ3MS10yTm" /></figure><p>6. At this point, open campus will try to check if the metamask extension is installed or not. This was installed when you set up your MetaMask Wallet. Go ahead and enter your password and click on the<strong><em> unlock button</em></strong>. If all goes well,you will be taken to the following screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*cPaew4X-Wq4_hnyc" /></figure><p>7. The above screen list the accounts attached to your wallet. Click on the checkbox to select the account you want to use (<em>if the account is the only one in the wallet, it will be selected automatically as shown on the screen above</em>),then click on the <strong><em>Next button</em></strong>. This takes you to the final screen (shown below) that seeks permission to access information from your account by open campus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/0*KlqeMZJfwk5mMwti" /></figure><p>8. We are almost done. Before you click on the Connect button, remember your Wallet information will be visible from open campus, So be sure you want to connect the account you have chosen to connect. Otherwise,click on the <strong><em>Connect button</em></strong>. Here you will be taken to the final stage where you must <strong><em>sign a message</em></strong> from your wallet as proof of authorizing this connection request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*v7_TJejedb6z8-ws" /></figure><p>9. When you click <strong><em>on the Sign message button</em></strong>, the screen shown below comes up with details of the Sign-in request, This will only be active within a short window of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/0*dQavoL9Xb3xF2oFB" /></figure><p>10. To complete the connect wallet process,click on the <strong><em>Sign-in button</em></strong>. This takes you to the next stage of creating your open campus ID linked to your wallet. Go ahead and click on Sign-in button that brings up the screen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aJe8TdV2S_9v94uP" /></figure><p>11. We are now on the home stretch to claiming your open campus ID with a few steps to go. As shown in the screen above the process is straight forward. Choose a name that is going to be your open campus ID as shown in the create your ID section. If this name has not been taken or used by another user, you will be allowed to move to the next step.Let’s do it and click next.</p><p>12. Lastly provide your personal information and follow the on the screen prompts to finish creating your ID. It is as simple as a confirmation click.</p><p><strong>Part 2: How to Claim your ID with an Email Address:</strong></p><ol><li>Visit the Open Campus ID website:<a href="https://id.opencampus.xyz/"> https://id.opencampus.xyz/</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*81aPRx-703bIMme-" /></figure><p>2. Look for an option to <strong><em>sign up </em></strong>button<strong><em> </em></strong>on the <strong><em>top right of the page </em></strong>or click on “<strong>claim yours now” </strong>button to use your email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vzck6gbaer26lr14" /></figure><p>3. Enter your valid email address and click on the <strong><em>sign up </em></strong>button. An email will be sent to the address you have entered. Go to your inbox,open the email from open campus and follow (<strong><em>see image below)</em> </strong>the instructions to confirm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*0dyqi6cjDSuNa_uO" /></figure><p>4. Upon your email being verified,you should see the following screen on your browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hTLMPFWSpSPBA8xt" /></figure><p>5. You can now close the above window and go back to the one you entered your email address.And Voila! You have your open campus ID</p><p><strong>Congratulations! </strong>You’re Officially an Open Campus Citizen!</p><p>I have shown you how to claim or create your Open Campus ID using two different methods. You can now go on to explore the platform, access a treasure trove of educational resources, and manage your learning journey like a pro.</p><p><strong>Bonus: Blockchain Explained (Simply!)</strong></p><p>Blockchain technology might sound like something out of a <strong>sci-fi</strong> movie, but it’s actually a pretty cool way of storing information securely. <em>Imagine a big public record book </em>where everyone can see what’s<em> written, but none can erase or change</em> it. That’s how blockchain works, making your Open Campus ID super safe and reliable.</p><p>That’s it for now. See you in other upcoming articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d86afe129c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the potential of Decentralized Finances (DeFis)]]></title>
            <link>https://medium.com/@nemwel.onsando/exploring-the-potential-of-decentralized-finances-defis-b362a4aa6ccc?source=rss-d23e3f4fe706------2</link>
            <guid isPermaLink="false">https://medium.com/p/b362a4aa6ccc</guid>
            <dc:creator><![CDATA[Nemwel Onsando]]></dc:creator>
            <pubDate>Sat, 06 Apr 2024 14:55:15 GMT</pubDate>
            <atom:updated>2024-04-06T15:49:38.454Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Ppz5ychZnt0eXcPD" /></figure><p>I want you to imagine a financial system that empowers you to borrow, lend, and even invest your money directly, without depending on banks. This is what <strong><em>Decentralized Finance (aka DeFi),</em></strong> a revolutionary concept that has begun to revolutionize the way we think about money, promises you.</p><p><strong>1. Introduction</strong></p><p>Traditionally, when you want or wish to borrow money, you may go to a bank. When you want to invest your money, you may use a stockbroker. These institutions act as intermediaries, connecting people who need money with those who have surplus cash.</p><p><strong><em>DeFi</em> </strong>leverages on a technology, <strong><em>called blockchain</em></strong>, which allows you to eliminate the need of a middleman or a central authority as an intermediary whenever you transact. Liken a <strong><em>blockchain</em></strong> as a giant public record book, where all transactions are stored securely and transparently. DeFi applications are built on top of blockchains, which allow you and me to connect directly with each other to conduct financial transactions.</p><p><em>You can dig for precise definition of DeFi, how it works and even get some uses cases </em><a href="https://smartvalor.com/ru/news/defi-basics"><em>here</em></a></p><p><strong>2. Opportunities of DeF</strong>is</p><p>DeFi offers a myriad of opportunities and use cases, which I’m going to walk you through in the subsequent sections below.</p><p>2.1 <strong><em>Borrowing and lending made easy</em></strong></p><p><strong><em>DeFi</em></strong> enables you to borrow cryptocurrencies directly from other users, at lower interest rates than traditional bank loans. In a similar manner, you can as well lend out your own crypto holdings and earn interest on them.</p><p>2.2 <strong><em>Investing for yields</em></strong></p><p><strong><em>DeFi</em></strong> platforms offer innovative ways to earn returns on your cryptocurrency holdings. An example is <em>yield farming</em>, which refers to a strategy involving lending or staking crypto assets to get rewards in the form of an <strong><em>annual percentage yield (APY)</em></strong><a href="https://www.investopedia.com/terms/a/apy.asp"> <strong><em>here </em></strong></a>.</p><p>Or in a layman language ” <em>Think of a group pool where people contribute their cryptocurrencies. The pooled funds are then used to generate returns which are eventually shared amongst the participants.”</em></p><p>2.3 <strong><em>Taking control of your investment</em></strong></p><p>Unlike traditional banks, <strong><em>DeFi </em></strong>allows you to hold your own cryptocurrencies in a digital wallet, explained in details<strong><em> </em></strong><a href="https://crypto.com/university/crypto-wallets?utm_source=crypto.com+university&amp;utm_medium=referral&amp;utm_campaign=how+to+use+defi&amp;utm_content=different+crypto+wallet+options"><strong><em>here</em></strong></a><strong><em> </em></strong>. A wallet stores the <em>public and private keys</em> you require to buy cryptocurrencies and provide digital signatures that are used to authorize each transaction. This gives you total control over the management of your finances without relying on banks.</p><p>2.4 <strong><em>Financial inclusion</em></strong></p><p>DeFi has the potential of providing financial services to anyone with an internet connection including the so called <strong><em>“ unbanked”</em></strong> ones. This is beneficial to those who live in countries that have limited access to traditional financial systems.</p><p><strong>3. Risks of DeFi</strong></p><p>As much as <strong><em>DeFi</em></strong> sounds like a compelling new future for finance, it does present concerning drawbacks and risks to the <strong><em>“would-be”</em></strong> participants, some of which we are going to discuss hereafter.</p><p>3.1 <strong><em>Smart contract risks</em></strong></p><p>DeFi applications rely on smart contracts. These are computer programs (<strong><em>call codes</em></strong>) stored on a blockchain. Unlike the traditional contracts,smart contracts are self-executing, supervised by other computers (also known as nodes) on a network and only perform tasks after they are converted into code. Hence, they automate agreements between users.</p><p>For instance a smart contract can be used to hold borrowed funds until the loan is fully repaid. However, if there’s a bug ( mistake like wrong computation logic) in a smart contract you end up losing your funds. This is the reason why it’s important to be cautious and only use <strong><em>DeFi</em></strong> platforms with a reputable track record and well-audited smart contracts.</p><p>Why not explore additional facts about smart contracts <a href="https://coincryption.com.au/learn-crypto/what-are-smart-contracts/"><strong><em>here</em></strong></a><strong><em> </em></strong>?</p><p><strong>3.2 Market volatility</strong></p><p>Cryptocurrencies are known for being volatile, meaning their prices can fluctuate significantly in a short period. This volatility can also impact DeFi applications built on top of them. The value of your DeFi investments could go down quickly, so it’s crucial to be aware of the risks involved before investing. You can observe such volatility <a href="https://crypto.com/price"><strong><em>here</em></strong></a></p><p><strong>3.3 Regulatory uncertainty</strong></p><p>Being a relatively new technology, governments around the world are in the process of figuring out how best they can regulate <strong><em>DeFi</em></strong>. This uncertainty is causing challenges for users and businesses who are operating or wish to operate in the DeFi space.</p><p><strong>3.4 Liquidity risks</strong></p><p>Liquidity refers to how easily you can buy or sell an asset. Some of the DeFi platforms have lower liquidity which makes it difficult to quickly convert DeFi holdings back into cash. It’s important to understand the liquidity of a DeFi platform before investing</p><p><strong>3.5 Outright scams</strong></p><p>Plenty of fraudsters are looking to snare new crypto investors enticed by yields that may drastically outpace those on offer at traditional financial institutions. A high yield may well be too good to be true.</p><p><strong>3.6 Gas fee and Cost</strong></p><p>Interacting with smart contracts requires what’s called a gas fee, like a token to make a machine run. Multiple steps along the way could easily run up costs, and that could prove especially costly for those with modest bankrolls. It is not uncommon that a ‘round trip’ can cost well over $200 in gas fees depending on the nature of the transaction</p><p><strong>4. Conclusion</strong></p><p>DeFi offers a glimpse into the future of decentralized finance, where individuals shall have control over their money and access to a wider range of financial services. However, it’s also important to be aware of the risks involved such as smart contract vulnerabilities, cryptocurrency volatility, scams, gas cost, regulatory uncertainty and liquidity risks. By understanding the nature of the risks involved and taking appropriate mitigation measures, you can navigate the DeFi landscape with ease and confidence.</p><p>As DeFi continues to evolve and reshape the financial landscape, understanding both opportunities and challenges therein, empowers you to make informed decisions whether DeFi is right for you or otherwise.</p><p>That’s it for now. I shall appreciate your feedback and comment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*TLY6LNZdgTbDvdFl.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b362a4aa6ccc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures and Algorithms 102: Javascript Binary Search Algorithm]]></title>
            <link>https://medium.com/@nemwel.onsando/data-structures-and-algorithms-102-javascript-binary-search-algorithm-ee8aed7aea58?source=rss-d23e3f4fe706------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee8aed7aea58</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[datastrucutre]]></category>
            <dc:creator><![CDATA[Nemwel Onsando]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 00:36:41 GMT</pubDate>
            <atom:updated>2024-04-08T19:48:57.147Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FzhTvCf0A9JTC4wh.png" /></figure><h3>Introduction</h3><p>In my previous article <a href="https://dev.to/nemwelo/data-structure-and-algorithm-4gid">Data Structures and Algorithms 101</a> you can read an introduction to what is data structures and algorithms.</p><p>In this article I will deep dive into Binary search algorithm. Searching algorithms falls into either sequential or interval search.Linear and binary searches are the commonly two simple as well as easy to implement algorithms.</p><p>Binary search is faster than linear search(where search is done in a sequence on every element). Here, am going to walk you through binary search algorithm and:</p><ul><li>define what is a binary search</li><li>how to implement it</li><li>where it can be used</li></ul><h3>What is binary search algorithm?</h3><p>Binary search algorithm is a divide-and-conquer algorithm that divides elements in a sorted array roughly into half every time it checks for the target element we are searching.Simply put,we divide the problem into simpler problems until it becomes simple enough to solve them directly.</p><h3>How do we implement a binary search?</h3><p>You can implement most of the algorithms in two ways:</p><p><strong>Iterative version</strong> of the algorithm involves a loop which repeats some steps until the stopping condition is met whereas <strong>recursive version</strong> uses a function that calls itself. I will be covering iterative version in this article.</p><p>We begin by implementing a function in JavaScript that search element value and returns its index:</p><pre>       const binarySearch = (elements, value) =&gt; {<br>       // Add other code<br><br>          }</pre><p>Assuming we have a sorted array,set the lower( <strong>startIndex</strong>) and upper( <strong>endIndex</strong>) boundaries at the appropriate ends of the sequence:</p><pre> const arr =  [0,5,12,23,34,35,46,47,58];<br> const binarySearch = (elements,value) =&gt; {    <br>       let startIndex = 0;<br>       let endIndex = arr.length - 1;<br><br>         }   </pre><p>Now we will identity the middle element to see if it has the value we want to search.We calculate this middle value ( <strong>middleIndex</strong>) by taking the average of both boundaries:</p><pre>  let middleIndex = Math.floor((startIndex + endIndex) / 2 );</pre><p>Here, you notice I have used the <strong>Math.floor()</strong> function to help handle an <strong>odd</strong> and <strong>even</strong> number of element in the bounded range by flooring the result.</p><p>Now,we compare that middle element with the value we are looking for as a key:</p><ul><li><strong>When the key is less than the middle element,we search in the left half</strong></li><li><strong>when the key is more than the middle element,we search in the right half</strong></li><li><strong>However,when the key is equal to the middle element,our search target is found and we return the index of the middle element</strong></li></ul><p>Let us update our code to reflect the above steps:</p><pre>const arr =  [0,5,12,23,34,35,46,47,58];<br>const binarySearch = (elements,value) =&gt; {<br>      let startIndex = 0;<br>      let endIndex = arr.length - 1;<br>      let middleIndex = Math.floor((startIndex + endIndex) / 2 );<br>      if (elements[middleIndex] === value) {<br>         return `Target value ${value} was found at index ${middleIndex}`;<br>         } else if (elements[middleIndex] &lt; value) {<br>             startIndex = middleIndex + 1;<br>           } else {<br>              endIndex = middleIndex - 1;<br>         }     <br> }</pre><p>To keep going,you enclose the above steps in a loop which will stop when the lower( <strong>startIndex</strong>) boundary overtakes the upper( <strong>endIndex</strong>) one.This can easily be achieved by adding a while loop our code as below:</p><pre>const arr =  [0,5,12,23,34,35,46,47,58];<br>const binarySearch = (elements,value) =&gt; {<br>      let startIndex = 0;<br>      let endIndex = arr.length - 1;<br>      while (startIndex &lt;= endIndex) { <br>        let middleIndex = Math.floor((startIndex + endIndex) / 2 );<br>        if (elements[middleIndex] === value) {<br>             return `Target value ${value} was found at index ${middleIndex}`;<br>             } else if (elements[middleIndex] &lt; value) {<br>                 startIndex = middleIndex + 1;<br>             } else {<br>                 endIndex = middleIndex - 1;<br>            }     <br>        }<br> }</pre><p>In other words,you can iterate as long as the lower boundary is below or equal to the upper one.Otherwise,there was no match found and the function returns <strong>undefined</strong> implicitly( <strong>lam returning a message informing the user that there was no match found in our array</strong>). Our code should now look as below:</p><pre>&#39;use strict&#39;<br><br>const arr =  [0,5,12,23,34,35,46,47,58];<br><br>const binarySearch = (elements,value) =&gt; {<br>    let startIndex = 0;<br>    let endIndex = arr.length - 1;<br><br>    while (startIndex &lt;= endIndex) {<br>        let middleIndex = Math.floor((startIndex + endIndex) / 2);<br>        if(elements[middleIndex] === value) {<br>            return `Target value ${value} was found at index ${middleIndex}`;<br>        }else if(elements[middleIndex] &lt; value) {<br>            startIndex = middleIndex + 1;<br>        }else {<br>            endIndex = middleIndex - 1;<br>        }<br>     }<br>  return `Target value ${value} was not found in [${elements}]`;<br>}<br><br>console.log(`Result of binary search results: ${binarySearch(arr,35)}`);</pre><p>To ensure your array is always sorted,add the following code:</p><pre>let sortedArr = arr.sort((a,b) =&gt; {<br>        return a - b;<br>});</pre><p>With this addition our code should look as below:</p><pre>&#39;use strict&#39;<br><br>const arr =  [0,5,12,23,34,35,46,47,58];<br><br>const binarySearch = (elements,value) =&gt; {<br>    let startIndex = 0;<br>    let endIndex = arr.length - 1;<br><br>    while (startIndex &lt;= endIndex) {<br>        let middleIndex = Math.floor((startIndex + endIndex) / 2);<br>        if(elements[middleIndex] === value) {<br>            return `Target value ${value} was found at index ${middleIndex}`;<br>        }else if(elements[middleIndex] &lt; value) {<br>            startIndex = middleIndex + 1;<br>        }else {<br>            endIndex = middleIndex - 1;<br>        }<br>     }<br>  return `Target value ${value} was not found in [${elements}]`;<br>}<br><br>let sortedArr = arr.sort((a,b) =&gt; {<br>        return a - b;<br>});<br><br>console.log(`Result of binary search results: ${binarySearch(sortedArr,35)}`);</pre><h3>Sample iteration simulation from our binary search function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/0*TcVVyqunkPSFctAy.png" /></figure><h3>Where we can use binary search algorithm</h3><p>Unlike other search algorithms, binary search can be used beyond just searching. For example, it allows for set membership testing, finding the largest or smallest value, finding the nearest neighbor of the target value, performing range queries, and more.</p><h3>The Efficiency of Binary Search</h3><p>The time complexity of the Binary Search is <strong>O(log2n)</strong>, where <strong>n is the number of elements</strong> in the array. This is far better compared to the <strong>Linear Search</strong>, which is of <strong>time complexity O(n)</strong>. Like many other search algorithms, Binary Search is an in-place algorithm. That means that it works directly on the original array without making any copies.</p><p>We have to keep in mind however, that <strong>Binary Search only works on sorted arrays</strong>. The sorting step itself, if using an efficient sorting algorithm, has a complexity of <strong>O(nlogn)</strong>. This means that in most cases, if the array is small, or if we need to search it only once, a <strong>brute-force (e.g. Linear Search)</strong> algorithm might be better.</p><p>Given this, Binary Search really shines when we need to make repeated searches on large arrays. As previously mentioned, we needed <strong>only 3 comparisons</strong> (comparisons being the most intensive tasks of all search algorithms), for my array of <strong>8 elements</strong>. However, if we had an array of <strong>10,000,000 elements</strong>, we would only need to check <em>24 elements, i.e. 0.0002%</em>_ of the entire array.</p><h3>Conclusion</h3><p>In this article, we have taken a look at Binary Search. It’s simple, intuitive and efficient logic and implementation make it a very popular algorithm to demonstrate the divide-and-conquer strategy. Your feedback(s) are highly welcome and shall help me improve on this article or extend my understanding of algorithms.</p><p><em>Originally published at </em><a href="https://dev.to/nemwelo/data-structures-and-algorithms-102-javascript-binary-search-algorithm-1n14"><em>https://dev.to</em></a><em> on July 1, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee8aed7aea58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>