<?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: Igiraneza Honorine</title>
    <description>The latest articles on DEV Community by Igiraneza Honorine (@honorine22).</description>
    <link>https://dev.to/honorine22</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%2F699069%2Fbd7e108b-e28e-46af-b95a-4efa6a2a8b38.png</url>
      <title>DEV Community: Igiraneza Honorine</title>
      <link>https://dev.to/honorine22</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/honorine22"/>
    <language>en</language>
    <item>
      <title>Merge Sort (Simple way to understanding Merge Sort)</title>
      <dc:creator>Igiraneza Honorine</dc:creator>
      <pubDate>Sat, 03 Sep 2022 13:45:10 +0000</pubDate>
      <link>https://dev.to/honorine22/merge-sort-simple-way-to-understanding-merge-sort-gfc</link>
      <guid>https://dev.to/honorine22/merge-sort-simple-way-to-understanding-merge-sort-gfc</guid>
      <description>&lt;p&gt;We are provided with an array with items and break down this array until each item is separated with each other and sorted. After that, they are merged to return the combined array of items sorted. That’s what merge sort is going to be doing. &lt;br&gt;
So simple! Let’s get started without further ado.&lt;/p&gt;

&lt;p&gt;We start comparing items with each other, if an item is less than another, it goes to the combined array and increment index of the array of that smaller item.&lt;/p&gt;

&lt;p&gt;Diagrams below explain well the algorithm used to quickly sort with merge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hD1XBauk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr8r7y97ghtefz0j2vy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hD1XBauk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr8r7y97ghtefz0j2vy8.png" alt="Image description" width="462" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hMZoHZC2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rreakex6v380cgyqttwd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hMZoHZC2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rreakex6v380cgyqttwd.png" alt="Image description" width="880" height="837"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l_9LB6bO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcgkscf2qr1c3mqezh9t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l_9LB6bO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcgkscf2qr1c3mqezh9t.png" alt="Image description" width="880" height="747"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ckJ-FMXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs1ea8uhv43vcsvfu785.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ckJ-FMXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs1ea8uhv43vcsvfu785.png" alt="Image description" width="880" height="349"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function merge(array1, array2) {
    let combined = []
    let i = 0
    let j = 0
    while(i &amp;lt; array1.length &amp;amp;&amp;amp; j &amp;lt; array2.length) {
        if(array1[i] &amp;lt; array2[j]) {
            combined.push(array1[i])
            i++
        } else {
            combined.push(array2[j])
            j++
        }
    }
    while(i &amp;lt; array1.length) {
        combined.push(array1[i])
        i++
    }
    while(j &amp;lt; array2.length) {
        combined.push(array2[j])
        j++
    }
    return combined
}

function mergeSort(array) {
    if(array.length === 1) return array

    let mid = Math.floor(array.length/2)
    let left = array.slice(0,mid)
    let right = array.slice(mid)

    return merge(mergeSort(left), mergeSort(right))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test Merge sort by calling this function: mergeSort([1,3,7,8,2,4,5,6])&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>sorting</category>
      <category>mergesort</category>
    </item>
    <item>
      <title>The easiest way to understanding Quick Sort🔥</title>
      <dc:creator>Igiraneza Honorine</dc:creator>
      <pubDate>Thu, 01 Sep 2022 16:14:18 +0000</pubDate>
      <link>https://dev.to/honorine22/the-easiest-way-to-understanding-quick-sort-3lhg</link>
      <guid>https://dev.to/honorine22/the-easiest-way-to-understanding-quick-sort-3lhg</guid>
      <description>&lt;p&gt;Quick sort has been an algorithm I was afraid of learning😢, pretending that it is too hard and require too much time to understand it, but now here I am explaining to you how straight forward it is using a short article written for it. Simple recursive function is required to fully understand quick sort.&lt;/p&gt;

&lt;p&gt;The first thing to know is that we use pivot point while comparing to other items in order to get the left side and right side of pivot and repeat the process. With that information we can get started.&lt;/p&gt;

&lt;p&gt;Here I use  pivotIndex variable to compare item on that index with other items, swapIndex variable to track index which will be swapped with small item found on the left side of pivot, and variable i to loop through all items and know which current item we are comparing to the pivot.&lt;/p&gt;

&lt;p&gt;swapIndex is initially set at the same index of pivotIndex. Whenever item smaller than pivot item is found, we increment 1 to swapIndex and swap item on swap index with current item we are on while looping with i. After that we swap pivot item with item on swap index.&lt;/p&gt;

&lt;h1&gt;
  
  
  Swap function
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function swapFn(array, firstIndex, secondIndex) {
    let temp = array[firstIndex]
    array[firstIndex] = array[secondIndex]
    array[secondIndex] = temp
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the algorithm that we use recursively to sort elements with Quick sort.&lt;br&gt;
Quick Sort algorithm&lt;br&gt;
Step 1: Start &lt;br&gt;
Step 2: Declare variables pivotIndex, swapIndex and i. &lt;br&gt;
Step 3: Initialize variables pivotIndex←0 swapIndex← pivotIndex, i= pivotIndex +1&lt;/p&gt;

&lt;p&gt;Step 4: Repeat the steps until i≤array.length-1 &lt;br&gt;
        if array[i] is less than array[pivotIndex] then&lt;br&gt;
            swapIndex++&lt;br&gt;
            swapFn(array[swap], array[i])&lt;br&gt;
    swapFn(array[swapIndex], array[pivotIndex])&lt;br&gt;
Step 5: OUTPUT swapIndex&lt;br&gt;
Step 6: Stop&lt;/p&gt;

&lt;h1&gt;
  
  
  Swap Index where pivot will be swapped function
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function pivotFn(array, pivotIndex=0, endIndex=array.length-1) { 
    let swapIndex = pivotIndex
    for (let i = pivotIndex + 1; i &amp;lt;= endIndex; i++) {
        if (array[i] &amp;lt; array[pivotIndex]) {
            swapIndex++
            swapFn(array, swapIndex, i)
        }
    }
    swapFn(array, pivotIndex, swapIndex)
    return swapIndex
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow along this diagram to see how it works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---oVazodp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emc9b6yq1twz3e3o5sh9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---oVazodp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emc9b6yq1twz3e3o5sh9.png" alt="Image description" width="794" height="1123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---F2eBWQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0z5z26ap8laqnhsbf6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---F2eBWQ3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0z5z26ap8laqnhsbf6n.png" alt="Image description" width="794" height="1123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;function quickSort(array, left=0, right=array.length-1) {&lt;br&gt;
    if(left &amp;lt; right) {&lt;br&gt;
        let pivotIndex = pivot(array, left, right)&lt;br&gt;
        quickSort(array, left, pivotIndex-1)&lt;br&gt;
        quickSort(array, pivotIndex+1, right)&lt;br&gt;
    }&lt;br&gt;
    return array&lt;br&gt;
}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test Quick sort by calling this function: quickSort([4,6,1,7,3,2,5])&lt;/p&gt;

&lt;p&gt;To sum up, We’ve got the left side with red color and the right side with green color. We do the same above process to both sides by comparing items with the pivot and swap if item is less than the pivot and then swap the pivot with the swap index.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>sorting</category>
      <category>quicksort</category>
    </item>
  </channel>
</rss>
