<?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: Nihal Agarwal</title>
    <description>The latest articles on DEV Community by Nihal Agarwal (@nihalagarwal).</description>
    <link>https://dev.to/nihalagarwal</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%2F417612%2F3d42ebdc-d14f-421c-a1b9-3167fe652a28.jpeg</url>
      <title>DEV Community: Nihal Agarwal</title>
      <link>https://dev.to/nihalagarwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nihalagarwal"/>
    <language>en</language>
    <item>
      <title>Problem's faced in Dijkstra's Java Code || Leetcode</title>
      <dc:creator>Nihal Agarwal</dc:creator>
      <pubDate>Sun, 29 May 2022 22:51:41 +0000</pubDate>
      <link>https://dev.to/nihalagarwal/dijkstras-java-code-5can</link>
      <guid>https://dev.to/nihalagarwal/dijkstras-java-code-5can</guid>
      <description>&lt;p&gt;When I am solving questions on Dijkstra's, I had basically two-way (or Java template) to write code for Dijkstra's, but for some questions, problem solved by both ways (or Dijkstra's Java templates) (&lt;a href="https://leetcode.com/problems/network-delay-time/"&gt;https://leetcode.com/problems/network-delay-time/&lt;/a&gt;) are accepted and for some (e.g., &lt;a href="https://leetcode.com/problems/path-with-minimum-effort/"&gt;https://leetcode.com/problems/path-with-minimum-effort/&lt;/a&gt;), anyone is able to solve the question.&lt;/p&gt;

&lt;p&gt;For a graph (represented in Adjacency List):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;int[]&amp;gt;[] graph = new ArrayList[n]; // n represents number of nodes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. Dijkstra's - One way&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean[] vis = new boolean[n];
int[] dist = new int[n];
Arrays.fill( dist, Integer.MAX_VALUE );

PriorityQueue&amp;lt;Integer&amp;gt; q = new PriorityQueue&amp;lt;&amp;gt;( (a,b) -&amp;gt; dist[a] - dist[b] );
q.add( 0 ); // Starting node
dist[start] = 0;

 while( !q.isEmpty() )
 {
     int node = q.poll();

     if( vis[node] )
         continue;
     vis[node] = true;

     // traversing neighboours
     for( int[] nb : graph[node] )
     {
         int node2 = nb[0];
         int weight = nb[1];
         if( !vis[node2] &amp;amp;&amp;amp; dist[node2] &amp;gt; dist[node] + weight )
         {
             dist[node2] = dist[node] + weight;
             q.add( node2 );
         }
     }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Dijkstra's - Second way&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; boolean[] vis = new boolean[n];
 int[] dist = new int[n];
 Arrays.fill( dist, Integer.MAX_VALUE );

 PriorityQueue&amp;lt;int[]&amp;gt; q = new PriorityQueue&amp;lt;&amp;gt;( (a,b) -&amp;gt; a[1] - b[1] );
 q.add( new int[2] ); // Starting node
 dist[start] = 0;

 while( !q.isEmpty() )
 {
     int node = q.peek()[0];
     int dis = q.peek()[1];

     if( vis[node] )
         continue;
     vis[node] = true;

     // traversing neighboours
     for( int[] nb : graph[node] )
     {
         int node2 = nb[0];
         int weight = nb[1];
         if( !vis[node2] &amp;amp;&amp;amp; dist[node2] &amp;gt; dis + weight )
         {
             dist[node2] = dis + weight;
             q.add( new int[] { node2, dist[node2] } );
         }
     }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can anyone, help me to know which is the right way (1st or 2nd).&lt;/p&gt;

</description>
      <category>java</category>
      <category>dijkstra</category>
      <category>graph</category>
    </item>
    <item>
      <title>How to draw Triangle star pattern with MySQL without using Stored Procedure?</title>
      <dc:creator>Nihal Agarwal</dc:creator>
      <pubDate>Fri, 26 Jun 2020 16:59:00 +0000</pubDate>
      <link>https://dev.to/nihalagarwal/how-to-draw-triangle-star-pattern-with-mysql-without-using-stored-procedure-15nf</link>
      <guid>https://dev.to/nihalagarwal/how-to-draw-triangle-star-pattern-with-mysql-without-using-stored-procedure-15nf</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/62562281/how-to-draw-triangle-star-pattern-with-mysql-without-using-stored-procedure" rel="noopener noreferrer"&gt;
            How to draw Triangle star pattern with MySQL without using Stored Procedure?
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Jun 24 '20&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 2&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/62562281/how-to-draw-triangle-star-pattern-with-mysql-without-using-stored-procedure" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          2
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;&lt;a href="https://i.stack.imgur.com/1TJ7H.png" rel="nofollow noreferrer"&gt;Triangular pattern example&lt;/a&gt; The above pattern is for p(5). How to write a query to print the pattern P(n) (where n is Integer defining the number of rows) using &lt;strong&gt;MySQL&lt;/strong&gt; without using &lt;strong&gt;Stored Procedure&lt;/strong&gt;. I had one code example for &lt;strong&gt;MS SQL Server&lt;/strong&gt; i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;DECLARE @i INT = 20&lt;/code&gt;&lt;/pre&gt;…
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/62562281/how-to-draw-triangle-star-pattern-with-mysql-without-using-stored-procedure" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
  </channel>
</rss>
