<?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>Forem: Mohammadhu Faalil</title>
    <description>The latest articles on Forem by Mohammadhu Faalil (@faalilbary).</description>
    <link>https://forem.com/faalilbary</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%2F520744%2F57955dff-208c-4313-9e02-1bf21bb1b258.jpeg</url>
      <title>Forem: Mohammadhu Faalil</title>
      <link>https://forem.com/faalilbary</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/faalilbary"/>
    <language>en</language>
    <item>
      <title>Will Von Neumann Architecture be diminished in the future?</title>
      <dc:creator>Mohammadhu Faalil</dc:creator>
      <pubDate>Wed, 02 Jun 2021 14:13:30 +0000</pubDate>
      <link>https://forem.com/ucscmozilla/will-von-neumann-architecture-be-diminished-in-the-future-2844</link>
      <guid>https://forem.com/ucscmozilla/will-von-neumann-architecture-be-diminished-in-the-future-2844</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Computer architecture has undergone incredible changes in the past 20 years. One element that has remained constant throughout the years, is the von Neumann concept of computer design. It has been used in computers since it was published.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Von Neumann Architecture.&lt;/strong&gt;&lt;br&gt;
Von Neumann architecture was first published by John Von Neumann in 1945. His computer architecture design consists of a Control Unit, Arithmetic and Logical Unit (ALU), Memory unit, Registers and Inputs/Outputs. The basic structure of the Von Neumann Architecture is shown in the Figure below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FMs9ohSR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FMs9ohSR.png" alt="1."&gt;&lt;/a&gt;&lt;br&gt;
According to Von Neumann Architecture, CPU consists of two units, Control Unit and Arithmetic Logic Unit. The underlying principle of Von Neumann Architecture is that data and instructions are treated in the same manner which means that both data and instructions are addressable. It operates using for simple steps:- Fetch, Decode, Execute, Store, called the Machine Cycle  as shown in the diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fq2HUsjg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fq2HUsjg.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instructions are fetched from the memory by the CPU. The CPU then decodes and executes the instructions and once it is completed it is stored back in the memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Von Neumann Bottleneck.&lt;/strong&gt;&lt;br&gt;
Under this architecture, memory for instructions and data are unified and shared with one data bus and one address bus between processor and memory. Instructions and data have to be fetched in sequential order, known as the Von Neumann Bottleneck which limits the bandwidth of memory access. The processor is idle for a certain amount of time while memory is accessed. Though numerous solutions have been proposed and implemented in modern day including cache memory and branch predictor algorithms, these solutions have not been able to solve the root of the problem rather it had made the architecture more complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Has the world started to move away from the Von Neumann Architecture?&lt;/strong&gt;&lt;br&gt;
In the modern world, Harvard Architecture has become a challenge for the Von Neumann Architecture. Harvard architecture is a type of computer architecture that separates its memory into two parts so that data and instructions are stored separately. This architecture also has separate buses to transfer data and fetch data. This allows the CPU to fetch data and instructions simultaneously.&lt;br&gt;
Further, IBM researches introduced a new non Von Neumann Architecture called the True North Architecture inspired by the functions of the human brain. Here, it uses a memory controller like a neuron, with no CPU, to work on synaptic-like data sets in memory with no shuffling around whatsoever by virtue of harnessing the crystallization dynamic of phase-change memories .&lt;br&gt;
In addition to these, many other alternative architectures have come up in the world of today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
It is obvious working with Von Neumann Architecture is not suitable to work in the future and it will be diminished in the near future. Some companies have already started to work with the alternative architectures, and the rest of the world would most probably switch to the alternative architectures as the traditional Von Neumann Architecture will be unable to cater the needs of the future computers.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>neumann</category>
    </item>
    <item>
      <title>Automation in agricultural equipment and technology.</title>
      <dc:creator>Mohammadhu Faalil</dc:creator>
      <pubDate>Wed, 05 May 2021 13:42:53 +0000</pubDate>
      <link>https://forem.com/ucscmozilla/automation-in-agricultural-equipment-and-technology-10gg</link>
      <guid>https://forem.com/ucscmozilla/automation-in-agricultural-equipment-and-technology-10gg</guid>
      <description>&lt;p&gt;The agriculture industry in the modern era is developing by leaps and bounds. The rise in the global population has caused an increase in food demands which in turn incurs farming produce price increase, reconsidering trade policies, shifting supply chains, and reshaping traditional food delivery routes. Despite these challenges, the amount of agricultural workers is steadily declining.  Therefore the farmers are facing a critical juncture between wanting to produce more, higher-quality crops and finding the workers to plant, maintain, and harvest those crops. The necessity arose to focus on using technology to produce more food in order to meet the demand and the concept “Smart Farming” came into place which makes farm more efficient and automates the crop production cycle.&lt;/p&gt;

&lt;p&gt;In the modern world there are numerous technologies that are commonly being utilized in agriculture. The advent of Agricultural robots simply called as agribots was a turning point in the field of agriculture that has resulted in producing more and higher quality foods with less manpower.&lt;/p&gt;

&lt;p&gt;Traditional tractors have been replaced by automated tractors which can be controlled remotely or even pre-programmed to give full autonomy to a producer. &lt;a href="https://www.bearflagrobotics.com/"&gt;Bear Flag Robotics&lt;/a&gt; specializes in building driverless tractors which provides significant savings in labour and input costs.  They have the ability to control several tractors remotely, plan the machine’s route, get real-time reports and alerts – the work can be done without direct human intervention in the field.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lRZ2Ikz0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/raTt1iK.jpg%3F1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lRZ2Ikz0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/raTt1iK.jpg%3F1" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, robots developed for seeding and weeding are focused on the field’s specific area, and they work with great precision. This type of farming robot uses artificial intelligence and computer vision, which allows for a reduction of pesticides in the field and, subsequently, the production of high-quality food.&lt;/p&gt;

&lt;p&gt;Historically, the harvesting of crops by automated means is something unimaginable due to the delicate nature of fresh fruits and vegetables. But in the modern days it has changed. The commercial company &lt;a href="https://www.abundantrobotics.com/"&gt;Abundant&lt;/a&gt; has developed an apple picking robot which uses a vacuum instead of graspers or similar devices.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wRmPP4Nl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/1UR8asl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wRmPP4Nl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/1UR8asl.jpg" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to robots, drones too play a major role in the automation of agriculture. Drone devices can identify damaged crops via imagery and infrared analysis. Farmers receive this information immediately and can quickly react to the changing conditions. Also they can be used to water plants in the fields. The company &lt;a href="https://www.droneseed.com/"&gt;DroneSeed&lt;/a&gt; have developed drones to plant from air in the aim of reforesting lands after wildfires. These types of drones carries a module that “shoots” seeds at the set place and specific distance from each other. To make it possible, developers use compressed air – this way, seeds will not scatter around the field.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rGN9Iy7G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/CgH9QVM.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rGN9Iy7G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/CgH9QVM.jpg" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The benefits of automating traditional agriculture processes are monumental. Increase of productivity through automation has increased the yield as well as the rate of production which in turn has reduced the costs for customers. The routines tasks being automated using robots has reduced the labour cost as well as addressed the issue of labour shortage in the field of agriculture. Besides these, automation has decreased the usage of pesticide and fertilizer while also reducing greenhouse gas emissions.&lt;/p&gt;

&lt;p&gt;There are still certain factors that stop automation of agriculture from gaining momentum. The higher prices of the automated agricultural equipment and lack of technological knowledge stands as a great barrier for this adaptation. Besides, lack of infrastructure and internet connection in certain remote rural areas should not be forgotten. Steps has to be taken by the relevant authorities of the country to provide a helping hand to the farmers in order to fully utilize farm automation.&lt;/p&gt;

&lt;p&gt;Automation in agricultural equipment using the technological advancements has paved the way towards sustainable and more efficient agriculture.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>agriculture</category>
      <category>technology</category>
    </item>
    <item>
      <title>Bubble Sort </title>
      <dc:creator>Mohammadhu Faalil</dc:creator>
      <pubDate>Sun, 31 Jan 2021 13:30:27 +0000</pubDate>
      <link>https://forem.com/ucscmozilla/bubble-sort-2d5n</link>
      <guid>https://forem.com/ucscmozilla/bubble-sort-2d5n</guid>
      <description>&lt;p&gt;Bubble sort is the simplest sorting algorithm that sorts the array by repeatedly swapping the consecutive pair of adjacent elements if they are not sorted.&lt;/p&gt;

&lt;p&gt;The Algorithm for Bubble Sort is as follows :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bubble Sort (A,N)
1.Repeat Step 2 for I=0 to N-1
2.  Repeat for J=0 to N-I
3.    If A[J] &amp;gt; A[J+1]
4.    SWAP A[J] and A[J+1]
5.  [END OF INNER LOOP]
6.[END OF OUTER LOOP]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's have a pictorial representation of how  bubble sort will sort a given array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FVfbvMqM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FVfbvMqM.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we see once the first iteration has ended, the largest element has taken its correct place and after second iteration the second largest element will take up its sorted place and it will continue.&lt;/p&gt;

&lt;p&gt;It's time to write the code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   void bubbleSort(int arr[],int n)
    {
     int i, j,temp;

        for(i = 0; i &amp;lt; n-1; i++)
        {
            for (j = 0; j &amp;lt; n-i-1; j++)
            {
                if (arr[j] &amp;gt; arr[j+1])
                 temp=arr[j];
                 arr[j]=arr[j+1];
                 arr[j+1]=temp;
            }
        }           
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Consider an array of 6 elements is sorted using the bubble sort algorithm. Even if the array is sorted after second or third iteration, the loop will continue until the 6th iteration. This is merely a waste of time. So, the computer scientists have found out a way to optimize this algorithm by using another variable &lt;strong&gt;swapped&lt;/strong&gt; which will check whether a swapping takes place in the inner for loop. If there are no swapping inside the inner loops, it means array is already sorted and we can jump out of the for loop instead of executing all the iterations.&lt;/p&gt;

&lt;p&gt;The optimized implementation of bubble sort algorithm is as follows :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void bubbleSort(int arr[],int n)
        {
         int i, j,temp;
         int swapped=0;

            for(i = 0; i &amp;lt; n-1; i++)
            {
                for (j = 0; j &amp;lt; n-i-1; j++)
                {
                    if (arr[j] &amp;gt; arr[j+1])
                    {
                     temp=arr[j];
                     arr[j]=arr[j+1];
                     arr[j+1]=temp;
                     // if swapping occurs update swapped to 1
                     swapped =1
                     }
                }
                //If the value of swapped is 0 after all the iterations of the inner loop
                //then break out
                if(swapped==0)
                {
                    break;
                }

            }           
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Complexity Analysis of Bubble Sort&lt;/strong&gt;&lt;br&gt;
 In bubble sort we have seen there are N-1 comparisons in first pass, N-2 in second pass and so on. Therefore, to compute the complexity of bubble sort, we need to calculate the number of comparisons. It can be shown as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f(n) = (n – 1) + (n – 2) + (n – 3) + ..... + 3 + 2 + 1
f(n) = n (n – 1)/2
f(n) = n^2/2 + O(n) = O(n^2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The time complexity of the bubble sort algorithm can be summarized as,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Worst Case Time Complexity [ Big-O ]:  &lt;strong&gt;O(n^2)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  Best Case Time Complexity [Big-omega]:  &lt;strong&gt;O(n)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  Average Time Complexity [Big-theta]:  &lt;strong&gt;O(n^2)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main advantage of the Bubble sort algorithm is the simplicity of the algorithm.&lt;/p&gt;

&lt;p&gt;By going through the above blog post, I am pretty sure that you have gained a sound knowledge on Bubble Sort Algorithm. If you have any queries or need more clarifications, feel free to drop in comments.&lt;br&gt;
Thank You.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>bubblesort</category>
      <category>dsa</category>
      <category>computerscience</category>
    </item>
    <item>
      <title> Insertion Sort</title>
      <dc:creator>Mohammadhu Faalil</dc:creator>
      <pubDate>Wed, 30 Dec 2020 13:30:17 +0000</pubDate>
      <link>https://forem.com/ucscmozilla/insertion-sort-1onb</link>
      <guid>https://forem.com/ucscmozilla/insertion-sort-1onb</guid>
      <description>&lt;p&gt;Insertion Sort is an in place comparison based sorting algorithm, which is commonly used in Computer Science. This algorithm is just similar to the way we sort a deck of cards while playing bridge. The main idea behind insertion list is that it inserts each item into its proper place  in the final sorted array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does Insertion Sort Work ?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The array of values to be sorted is divided into two parts. One stores the sorted values while the other consists of the unsorted values.&lt;/li&gt;
&lt;li&gt;This algorithm continues until the unsorted part is empty.&lt;/li&gt;
&lt;li&gt;Assume there are n elements in the array. Initially the first element is in the sorted part while the rest in the unsorted part.&lt;/li&gt;
&lt;li&gt;During each iteration, the first element in the unsorted part is picked and inserted into the correct position in the sorted array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The way in which a given array is arranged using Selection Sort Algorithm is depicted in the following diagram.&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FGkVObib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/TJsyy21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FGkVObib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/TJsyy21.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pseudo Code for Selection Sort&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERTION-SORT(A)
   for i = 1 to n
    key ← A [i]
        j ← i – 1
     while j &amp;gt; = 0 and A[j] &amp;gt; key
        A[j+1] ← A[j]
        j ← j – 1
    End while 
    A[j+1] ← key
  End for 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation of Selection Sort in C&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void Insertion_Sort ( int A[ ] , int n) 
{
     for( int i = 0 ;i &amp;lt; n ; i++ ) {
    //storing current element whose left side is checked for its correct position //

      int key = A[ i ];    
      int j = i;

       /* check whether the adjacent element in left side is greater or
            less than the current element. */

          while(  j &amp;gt; 0  &amp;amp;&amp;amp; key &amp;lt; A[ j -1]) {

           // moving the left side element to one position forward.
                A[ j ] = A[ j-1];   
                j= j - 1;

           }
         // moving current element to its  correct position.
           A[ j ] = key;       
     }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Complexity of Insertion Sort&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time Complexities&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best Case Complexity : O (n)&lt;/strong&gt;&lt;br&gt;
 This occurs when the array is already sorted. The outer loops runs n number of times while the inner loop does not run at all. Therefore, there are only n number of comparisons such that complexity is linear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Worst Case Complexity : O (n^2)&lt;/strong&gt;&lt;br&gt;
 The worst case occurs when the elements in the array are in the reversed order. Here, the first element of the unsorted part has to be compared with every elements in the sorted part. Therefore it has a quadratic running time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Average Case Complexity : O(n^2)&lt;/strong&gt;&lt;br&gt;
 It occurs when the elements in the array is in neither ascending nor descending order.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt;&lt;br&gt;
    Space Complexity is O(1)  as an extra variable key is used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Insertion Sort&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It requires less memory space (only O(1) of additional memory space)&lt;/li&gt;
&lt;li&gt;It is easy to implement.&lt;/li&gt;
&lt;li&gt;It is efficient to use on small sets of data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By reading the above blog post, I hope you would have gained a sound knowledge on Insertion Sort.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>sorting</category>
      <category>dsa</category>
      <category>tutorial</category>
    </item>
    <item>
      <title> Selection Sort</title>
      <dc:creator>Mohammadhu Faalil</dc:creator>
      <pubDate>Wed, 25 Nov 2020 13:30:05 +0000</pubDate>
      <link>https://forem.com/ucscmozilla/selection-sort-3hf7</link>
      <guid>https://forem.com/ucscmozilla/selection-sort-3hf7</guid>
      <description>&lt;p&gt;Sorting refers to the operation or technique of arranging and rearranging sets of data in some specific order in order to make it easy for us to use those data. There are many sorting algorithms used to put the elements of a list in a certain order, which can be either numerical order or any user defined order. Some of the widely used sorting algorithms are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Selection Sort&lt;/li&gt;
&lt;li&gt;Insertion Sort&lt;/li&gt;
&lt;li&gt;Bubble Sort&lt;/li&gt;
&lt;li&gt;Merge Sort&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here, I will be discussing about the Selection Sort Algorithm.&lt;/p&gt;

&lt;p&gt;Selection Sort is a simple sorting algorithm which can be easily understood even by a beginner. In Selection Sort, an array is divided into two parts as :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The sorted part at the right end.&lt;/li&gt;
&lt;li&gt;The unsorted part at the left end.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Firstly, the sorted part is empty while the entire list takes the unsorted part. The minimum element in the unsorted part is found and swapped with leftmost element in unsorted part. And then onwards that element becomes part of the sorted array. With time, the sorted part expands and the unsorted part shrinks. Finally, when the unsorted part becomes empty, we have achieved the sorted array.&lt;br&gt;
The way how an array is sorted in Selection Sort Algorithm is given in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r8b1GuFX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/jhx3XIM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r8b1GuFX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/jhx3XIM.png" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Pseudo Code for Selection Sort&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. for i=1 to i=n-1
2. min=i
3. for j=i+1 to j=n
4.  if A[j]&amp;lt;A[min], then
5.    min=j
6. end for
7. if min≠i then , interchange A[i] and A[min]
8. end for
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation of Selection Sort in C&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//arr is the name of the array to be sorted
// n is the size of the array

void SelectionSort(int arr[], int n) 
{ 
    int i, j, min; 

    for (i = 0; i &amp;lt; n-1; i++) 
    { 
        // Find the minimum element in the unsorted part of the array
        min = i; 
        for (j = i+1; j &amp;lt; n; j++) 
          if (arr[j] &amp;lt; arr[min]) 
            min = j; 

        // Swap the found minimum element with the first element of the unsorted array
            int temp = arr[i];  
            arr[i] = arr[min];  
            arr[min] = temp; 
    } 
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Complexity of Selection Sort&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In first pass, finding the element with the smallest value calls for scanning all n elements; thus, n–1 comparisons are required in the first pass. Then, the smallest value is swapped with the&lt;br&gt;
element in the first position. In Pass 2, finding the second smallest value requires scanning the remaining n – 1 elements and so on. Therefore,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(n – 1) + (n – 2) + ... + 2 + 1
= n(n – 1) / 2 = O(n2) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So, we can see the time complexity of Selection Sort is the same irrespective of the original order of the elements in the given array.&lt;br&gt;
When we see the space complexity, it is 0(1) as an extra variable temp is used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Selection Sort&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is very simple and easy to implement.&lt;/li&gt;
&lt;li&gt;It can be used to sort very small data sets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To sum up, Selection Sort is a simple sorting algorithm that is easy to understand and the knowledge on Selection Sort algorithm will help us to have a strong introduction into learning  other sorting algorithms.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>selectionsort</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
