<?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: martin_ndegwa</title>
    <description>The latest articles on DEV Community by martin_ndegwa (@ndegwa007).</description>
    <link>https://dev.to/ndegwa007</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%2F582881%2F35d5cd20-e451-4704-a7d4-0521d1a694fe.png</url>
      <title>DEV Community: martin_ndegwa</title>
      <link>https://dev.to/ndegwa007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ndegwa007"/>
    <language>en</language>
    <item>
      <title>Binary Search Algorithm</title>
      <dc:creator>martin_ndegwa</dc:creator>
      <pubDate>Sun, 18 Jun 2023 05:16:54 +0000</pubDate>
      <link>https://dev.to/ndegwa007/binary-search-algorithm-nc9</link>
      <guid>https://dev.to/ndegwa007/binary-search-algorithm-nc9</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is binary search algorithm?&lt;/strong&gt;&lt;br&gt;
Well, it's an algorithm :)&lt;br&gt;
An algorithm is a set of finite instructions or rules used to solve a particular problem. A binary search algorithm takes a sorted input of a list of elements, such as numbers. When the element you are searching for is in the list, the algorithm returns where it is located.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Binary Search?&lt;/strong&gt;&lt;br&gt;
Binary search is well suited for a large input of elements.It is more efficient than a linear search where a case of say 1024 elements would take 1023 steps (worst case) or so to get an element near the 1024 mark. A binary search would take &lt;strong&gt;log n&lt;/strong&gt; time to get an element from the same(worst case). &lt;strong&gt;log 1024 = 10&lt;/strong&gt; this means it would take 10 steps since 2 to the power of 10 is 1024. Simply &lt;strong&gt;log n&lt;/strong&gt; here means logarithmic time and it's computed as log n to the base of 2 in layman's terms think of it as "How many 2s do we multiply together to get 1024?"&lt;br&gt;
The time is shortened quite impressively right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let's see how it works&lt;/strong&gt;&lt;br&gt;
The code here is in Python, but the logic is the same for other programming languages. Okay, so binary search works only with a sorted list and you'll keep track of the part of the list to search through, at first it's the entire array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;low = 0
high = len(list) - 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each time you check the middle element;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mid = (low + high) / 2
guess = list[mid]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here your guess is that just maybe the element you are searching for is in the middle of your list, if the guess is too low, you'll adjust low accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;low = mid + 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if the guess is to high, you update high; Here is the full python code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""binary search"""
def binary_search(list: [int], num: int) -&amp;gt; int:
    """num is the searched number in the list"""
    low = 0
    high = len(list) - 1
    list.sort() # sort the list


    while(low &amp;lt;= high):
        # get the middle element
        mid = (low + high) // 2
        guess = list[mid]

        if guess == num:
            return mid
        if guess &amp;gt; num:
            high = mid - 1
        else:
            low = mid + 1
    return 0

if __name__ == '__main__':
    number_to_search = 5
    list = [1,8,9,3,4,6,5,10,7]
    print(binary_search(list, number_to_search))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code returns 3 which is the position of 5 in the 0-based index of the sorted list.&lt;br&gt;
You can try out the code with larger inputs and see the beauty of it. Alright that's it, Happy Coding!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>python</category>
      <category>datastructures</category>
      <category>programming</category>
    </item>
    <item>
      <title>What happens when you type www.google.com and hit enter on your keyboard?</title>
      <dc:creator>martin_ndegwa</dc:creator>
      <pubDate>Fri, 12 May 2023 09:03:44 +0000</pubDate>
      <link>https://dev.to/ndegwa007/what-happens-when-you-type-wwwgooglecom-and-hit-enter-on-your-keyboard-kfb</link>
      <guid>https://dev.to/ndegwa007/what-happens-when-you-type-wwwgooglecom-and-hit-enter-on-your-keyboard-kfb</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;h2&gt;Introduction.&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Uniform Resource Locator(URL), which is a reference to that web resource, identifies the place on a computer network where a web resource is located and how it can be retrieved. Let's look at what happens when you type in a URL, like &lt;a href="https://www.google.com"&gt;https://ww.google.com&lt;/a&gt;, in your browser and press Enter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;A URL&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mhTv72de--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jyrtejlwbhl6ofijk1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mhTv72de--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jyrtejlwbhl6ofijk1y.png" alt="dns lookup" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the (URL), the first word stands for Hypertext Transfer Protocol Secure "&lt;strong&gt;HTTPS&lt;/strong&gt;." It is an internet protocol that communicates with the server to handle the browser's request. The domain &lt;strong&gt;google.com&lt;/strong&gt;&lt;br&gt;
 includes the &lt;strong&gt;"www"&lt;/strong&gt; subdomain. The URL is first sent to a Domain Name Server (DNS), a computer with a database of public &lt;strong&gt;IP&lt;/strong&gt; addresses and the &lt;strong&gt;hostnames&lt;/strong&gt; that correspond to them. The initial action that takes place when you search for any URL in the browser is referred to as a &lt;strong&gt;DNS query&lt;/strong&gt;. The reason is that, unlike &lt;strong&gt;IP&lt;/strong&gt; addresses, &lt;strong&gt;hostnames&lt;/strong&gt; are strings with a domain name suffix that the servers cannot understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;TCP/IP connection&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eveULBt7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qyr0mlp8456eyo4pixd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eveULBt7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qyr0mlp8456eyo4pixd.png" alt="type_the_url" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Now that we have the corresponding &lt;strong&gt;IP&lt;/strong&gt; address to our domain name, the next process is a &lt;strong&gt;TCP&lt;/strong&gt; three-way handshake between both the browser &lt;strong&gt;(client)&lt;/strong&gt; and server: &lt;strong&gt;synchronize&lt;/strong&gt; (a.k.a. SYN), and &lt;strong&gt;acknowledge&lt;/strong&gt; (a.k.a. ACK). The client here sets an initial SYN sequence number; the server also has its own sequence number, which increments the client’s SYN. The server then sends back a (SYN/ACK) packet to the client and awaits the client's ACK by incrementing its SYN.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;HTTPS/SSL&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the &lt;strong&gt;TCP/IP&lt;/strong&gt; connection has been established, the browser proceeds to communicate with the server using a secure protocol (HTTPS). This protocol defines different types of requests &lt;strong&gt;(e.g., GET, POST, and PUT)&lt;/strong&gt;, which are secured by a security protocol called &lt;strong&gt;Secure Sockets Layer&lt;/strong&gt; that encrypts and decrypts the data from the client to the server infrastructure at the &lt;strong&gt;load balancer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;Load Balancer&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The load balancer distributes website user requests across a number of servers when there is a high volume of requests in order to avoid a &lt;strong&gt;single point of failure&lt;/strong&gt; (SPOF) or downtime. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;The Firewall, also known as the Great Wall&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The firewall analyzes incoming traffic using pre-established rules and filters traffic from untrusted or shady sources to prevent attacks from hackers who can intercept user traffic. Users are permitted to connect to a web server that will be assigned by the &lt;strong&gt;load balancer&lt;/strong&gt; if their requests are not malicious or suspicious.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;Web Server and Application Server&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zgiYsYDA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tk6tr3okv3kbkf26z66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zgiYsYDA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tk6tr3okv3kbkf26z66.png" alt="web servers" width="800" height="669"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s do a recap. First, we started by doing a &lt;strong&gt;DNS&lt;/strong&gt; query, which helps get an &lt;strong&gt;IP&lt;/strong&gt; address associated with the domain name of our website. The &lt;strong&gt;IP&lt;/strong&gt; address is sent back to our browser client, which sends the IP address to the server, where a &lt;strong&gt;TCP/IP&lt;/strong&gt; connection is established. When this is done, the browser can now communicate with the server through the &lt;strong&gt;HTTPS&lt;/strong&gt; protocol. The encryption and decryption of data between the server and the client are done through a standard security protocol called &lt;strong&gt;Secure Sockets Layer&lt;/strong&gt; (SSL). The &lt;strong&gt;load balancer&lt;/strong&gt; can then serve the web server with users’ requests if the firewall allows the incoming traffic.&lt;br&gt;
Let’s define a &lt;strong&gt;web server&lt;/strong&gt;. A web server is a software and hardware system that only handles &lt;strong&gt;HTTP&lt;/strong&gt; and &lt;strong&gt;HTTPS&lt;/strong&gt; requests and serves static content like simple &lt;strong&gt;HTML&lt;/strong&gt; pages, plain text files, and images.&lt;br&gt;
The application server, on the other hand, runs behind a web server and in front of a &lt;strong&gt;database management system&lt;/strong&gt; (DBMS). Its main purpose is to generate dynamic content support for an application’s development and delivery, thus providing the business logic behind the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;Data Management&lt;/h2&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database Management System&lt;/strong&gt; (DBMS), A program that allows the interaction with a database (an organized collection of structured information or data stored in a computer system) to define, manipulate, retrieve, and manage the data according to the request&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;/strong&gt;&lt;br&gt;
This is the entire process when you type &lt;a href="https://www.google.com"&gt;https://google.com&lt;/a&gt; and hit enter. It might look like a lot, but this happens within a few seconds, and you get dynamic content served to your browser through a secured &lt;strong&gt;HTTPS&lt;/strong&gt; connection. I hope the explanation is easy to understand. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>database</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
