<?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: Vaishnavi Sharma</title>
    <description>The latest articles on DEV Community by Vaishnavi Sharma (@vaishnavisharma10_).</description>
    <link>https://dev.to/vaishnavisharma10_</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%2F614939%2F0813bd59-6ea4-44ee-8eb8-702c3445e47a.jpeg</url>
      <title>DEV Community: Vaishnavi Sharma</title>
      <link>https://dev.to/vaishnavisharma10_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vaishnavisharma10_"/>
    <language>en</language>
    <item>
      <title>Kruskal's Algorithm</title>
      <dc:creator>Vaishnavi Sharma</dc:creator>
      <pubDate>Mon, 14 Jun 2021 07:42:03 +0000</pubDate>
      <link>https://dev.to/vaishnavisharma10_/kruskal-s-algorithm-h4m</link>
      <guid>https://dev.to/vaishnavisharma10_/kruskal-s-algorithm-h4m</guid>
      <description>&lt;p&gt;Kruskal's Algorithm finds a minimum spanning tree of an undirected edge-weighted graph. If the graph is connected, it finds a minimum spanning tree(MST). &lt;br&gt;
It is a greedy algorithm in graph theory as in each step it adds the next lowest-weight edge that will not form a cycle to the minimum spanning tree.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fap2qte80r86j8rp5f32b.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fap2qte80r86j8rp5f32b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets Code :D&lt;/p&gt;

&lt;p&gt;But first lets read the step wise guide :)&lt;/p&gt;

&lt;p&gt;What we need?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Class Edge :- Properties : 
i) Source     ii) Destination    iii) Weights&lt;/li&gt;
&lt;li&gt;Array of type Edge of size e (number of edges) - Input from user&lt;/li&gt;
&lt;li&gt;Array output of type Edge of size e - 1 (the required MST)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;STEPS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take input.&lt;/li&gt;
&lt;li&gt;Sort the input array in increasing order according to their weights.&lt;/li&gt;
&lt;li&gt;Create a parent array of size n (number of vertices) as -
parent[n] = { 0, 1, 2, 3, ...}&lt;/li&gt;
&lt;li&gt;Initialize count as 0.&lt;/li&gt;
&lt;li&gt;while ( count &amp;lt; n - 1){
 e edge is between two vertices - v1 and v2
 parent of v1 is let, v1P and parent of v2 
 is let, v2p.
 If parent is same, next iteration.
 Else
    count + 1, update parent[]
}&lt;/li&gt;
&lt;li&gt;At last you'll get minimum spanning tree and then print the output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Easy?&lt;/p&gt;

&lt;p&gt;Below is the code for Kruskal's Algorithm in C++&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feorufn774d0dzh6s2i7z.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feorufn774d0dzh6s2i7z.PNG" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa18nk0xsf9uav2bw0vnd.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa18nk0xsf9uav2bw0vnd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you enjoyed :)&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Merge Sort, Its not hard!</title>
      <dc:creator>Vaishnavi Sharma</dc:creator>
      <pubDate>Sun, 23 May 2021 09:57:46 +0000</pubDate>
      <link>https://dev.to/vaishnavisharma10_/merge-sort-its-not-hard-566h</link>
      <guid>https://dev.to/vaishnavisharma10_/merge-sort-its-not-hard-566h</guid>
      <description>&lt;p&gt;Merge sort works on the principle of divide and conquer algorithm. It is one of the most efficient sorting algorithm. The top down merge sort approach uses recursion. We break/divide the array into subparts (till single element).&lt;br&gt;&lt;br&gt;
This sorting algorithm recursively sorts the subparts and then merges them into a single sorted array.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgn9gqg87suoixw5fed45.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgn9gqg87suoixw5fed45.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 4 important points where all the process of merge sort takes place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the middle element of the array.&lt;/li&gt;
&lt;li&gt;Call mergeSort function for the first half.&lt;/li&gt;
&lt;li&gt;Call mergeSort function for the second half.&lt;/li&gt;
&lt;li&gt;Merge the two halves into a single sorted array, and yes, this 
is the answer!
Ain't that easy? it is!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is the function mergeSort() in C++ language:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7x3dpu4c4igpigl8o196.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7x3dpu4c4igpigl8o196.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time Complexity:&lt;/p&gt;

&lt;p&gt;Total T(n) work is done which is divided as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;k amount of constant work,&lt;/li&gt;
&lt;li&gt;T(n/2) work for 2 halves,&lt;/li&gt;
&lt;li&gt;Merge two halves = k1n,&lt;/li&gt;
&lt;li&gt;Copy elements to input array = k2n, So, 
T(n) = k + T(n/2) + T(n/2) + k1n + k2n
T(n) = 2T(n/2) + Kn    {K here is the sum of all constants - k, k1, k2}&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The recurrence relation that we'll get-&lt;br&gt;
T(n) = 2T(n/2) + Kn&lt;br&gt;
After solving this recurrence relation, we'll come to the conclusion that the time complexity for merge sort is-&lt;br&gt;
O(nlogn)&lt;/p&gt;

&lt;p&gt;Space Complexity:&lt;/p&gt;

&lt;p&gt;Space complexity is the maximum space required at any point of time during execution of a program.&lt;br&gt;
In merge sort, we use recursion on half part of the array, So the calling will be done as (n is size of the array): &lt;br&gt;
n -&amp;gt; n/2 -&amp;gt; n/4 -&amp;gt; n/8 ... and so on&lt;br&gt;
that is, logn function waiting in the call stack.&lt;br&gt;
-&amp;gt; klogn space for storing functions&lt;br&gt;
-&amp;gt; kn for array&lt;br&gt;
So the maximum space required is kn,&lt;br&gt;
Space Complexity will be O(n).&lt;/p&gt;

&lt;p&gt;I hope now you can do problems on merge sort :)&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
