<?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: Sesha-Savanth</title>
    <description>The latest articles on DEV Community by Sesha-Savanth (@seshasavanth).</description>
    <link>https://dev.to/seshasavanth</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%2F624850%2F62658cd3-75e5-4207-acc2-01d77bb736a4.png</url>
      <title>DEV Community: Sesha-Savanth</title>
      <link>https://dev.to/seshasavanth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seshasavanth"/>
    <language>en</language>
    <item>
      <title>Handling Exception in Java</title>
      <dc:creator>Sesha-Savanth</dc:creator>
      <pubDate>Sun, 24 Oct 2021 19:18:07 +0000</pubDate>
      <link>https://dev.to/seshasavanth/handling-exception-in-java-58l4</link>
      <guid>https://dev.to/seshasavanth/handling-exception-in-java-58l4</guid>
      <description>&lt;h1&gt;
  
  
  What is exception handling?
&lt;/h1&gt;

&lt;p&gt;An exception is an abnormal condition that disturbs the normal flow of the program. Exception handling is used in handling the runtime errors and maintains the continuity of the program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java exceptions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Checked&lt;/li&gt;
&lt;li&gt;Unchecked&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try Block
&lt;/h2&gt;

&lt;p&gt;The statements which throw an exception are to be placed under try block&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is suggested not to write unnecessary statements in the try block because the program terminates at a particular statement where an exception occurs.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Catch Block
&lt;/h2&gt;

&lt;p&gt;It is used to handle the exception by declaring the type of exception within the parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single or multiple catch blocks can be used after each single try block.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax of try-catch :'
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; try{    
   //code that may throw an exception    
    }catch(Exception_class_Name ref){} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Program using Try-Catch :
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class TryCatch {

public static void main(String[] args) {  
    try  
    {  
    int arr[]= {2,4,6,8};  
    System.out.println(arr[10]);    
    }  

    catch(ArrayIndexOutOfBoundsException e)  
    {  
        System.out.println(e);  
    }  
    System.out.println("Program continues"); 
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;java.lang.ArrayIndexOutOfBoundsException: 10&lt;br&gt;
Program continues&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Program Using multiple catch blocks :
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Multiple {

public static void main(String[] args) {  

       try{    
            int a[]=new int[5];    

            System.out.println(a[10]);  
           }    
           catch(ArithmeticException e)  
              {  
               System.out.println("Arithmetic Exception occurs");  
              }    
           catch(ArrayIndexOutOfBoundsException e)  
              {  
               System.out.println("ArrayIndexOutOfBounds Exception occurs");  
              }    
           catch(Exception e)  
              {  
               System.out.println("Parent Exception occurs");  
              }             
           System.out.println("Program Continues");    
}  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;ArrayIndexOutOfBounds Exception occurs&lt;br&gt;
Program Continues&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally Block
&lt;/h2&gt;

&lt;p&gt;The block of statements that are used to execute the important code. It is always executed whether an exception is handled or not.&lt;/p&gt;

&lt;h4&gt;
  
  
  Program using finally block :
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Finally{

public static void main(String args[]){

try{

int data=25/0;

System.out.println(data);

}

catch(ArithmeticException e){
System.out.println(e);
}

finally{
System.out.println("finally block is always executed");
}

System.out.println("Program continues");

}

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;java.lang.ArithmeticException: / by zero&lt;br&gt;
finally block is always executed&lt;br&gt;
Program continues&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Floyd-Warshall Algorithm</title>
      <dc:creator>Sesha-Savanth</dc:creator>
      <pubDate>Thu, 06 May 2021 11:11:24 +0000</pubDate>
      <link>https://dev.to/seshasavanth/floyd-warshall-algorithm-dk8</link>
      <guid>https://dev.to/seshasavanth/floyd-warshall-algorithm-dk8</guid>
      <description>&lt;p&gt;The Floyd-Warshall algorithm is used for finding all pairs shortest path. This algorithm is used to find the shortest path between every pair of vertices in a given edge graph.&lt;/p&gt;

&lt;p&gt;Let &lt;strong&gt;G = (V,E)&lt;/strong&gt; be a directed graph with &lt;strong&gt;n&lt;/strong&gt; vertices. Let cost be a cost adjacency matrix for G such that &lt;strong&gt;cost(i,i) = 0, 1&amp;lt;=i&amp;lt;=n.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost(i,j) = length or cost of edge (i,j)&lt;/strong&gt;, if(i,j) ∈ E(G)  and cost(i,j)= ∞  if (i,j) ∉ E(G)&lt;/p&gt;

&lt;p&gt;All-pairs shortest path problems is to determine a matrix A such that A(i,j) is the length of a shortest path from i to j&lt;/p&gt;

&lt;p&gt;Let &lt;strong&gt;k&lt;/strong&gt; be the highest intermediate vertex between i to j path, then i to k path is a shortest  path in graph &lt;strong&gt;G&lt;/strong&gt; going through no vertex with index greater than k-1. Similarly k to j path is a shortest path in graph &lt;strong&gt;G&lt;/strong&gt; going through no vertex with index greater than k-1.&lt;/p&gt;

&lt;p&gt;First we need to find highest intermediate vertex &lt;strong&gt;k&lt;/strong&gt;  then we need to find the two shortest paths from  i to k and k to j.&lt;/p&gt;

&lt;p&gt;Then we use A^k(i,j) to represent the length of a shortest path from i to j going through no vertex of index greater than &lt;strong&gt;k&lt;/strong&gt;, we obtain&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A^0(i,j)=cost(i,j)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If it goes through highest intermediate vertex &lt;strong&gt;k&lt;/strong&gt; then&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A^k(i,j) = A^k-1(i,k)+A^k-1(k,j)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If it does not then highest intermediate vertex is&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A^k(i,j) = A^k-1(i,j)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To get a recurrence for $A^{k}$(i,j) we need to combine both &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A^k(i,j) =min{ A^k-1(i,j), A^k-1(i,k)+A^k-1(k,j)}, where k&amp;gt;=1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_noM0yF2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz7xh2qxamobhcw0pyd7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_noM0yF2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz7xh2qxamobhcw0pyd7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: For selected intermediate vertex the path that belongs to that vertex remains same&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0nNYWQf2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zk54rp3v7nldq8qdtwz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0nNYWQf2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zk54rp3v7nldq8qdtwz8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By taking the above matrix we can get  $A^{1}$ matrix.&lt;/p&gt;

&lt;p&gt;A^1(2,3) = min{A^0(2,3),A^0(2,1)+A^0(1,3)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;$A^{1}$(2,3) = min{2,8+∞} = 2&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A^1(2,4) = min{A^0(2,4),A^0(2,1)+A^0(1,4)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A^1(2,4) = min{∞,8+7} = 15&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A^1(3,2) = min{A^0(3,2),A^0(3,1)+A^0(1,2)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A^1(3,2) = min{∞,5+3} = 8&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A^1(3,4) = min{A^0(4,3),A^0(3,1)+A^0(1,4)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A^1(3,4) = min{1,5+7} = 1&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A^1(4,2) = min{A^0(4,2),A^0(4,1)+A^0(1,2)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;$A^{1}$(4,2) = min{∞,2+3} = 2&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A^1(4,3) = min{A^0(4,3),A^0(4,1)+A^0(1,3)}&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A^1(4,3) = min{∞,2+∞} = 2&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zqo1L9ia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tchn7kohh17ndwji9795.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zqo1L9ia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tchn7kohh17ndwji9795.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Similarly;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jNuZvUii--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s107bcw6fztbsn93mamm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jNuZvUii--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s107bcw6fztbsn93mamm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b1kn9nXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hjgdj5mrr37cexoipnk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b1kn9nXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hjgdj5mrr37cexoipnk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rgeKRXjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7suc62nx80ahwnkx6kj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rgeKRXjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7suc62nx80ahwnkx6kj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm&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;for(k=1;k&amp;lt;=n;k++)
{
  for(i=1;i&amp;lt;=n;i++)
  {
    for(j=1;j&amp;lt;=n;j++)
    {
      if(a[i][j]&amp;gt;a[i][k]+a[k][j])
      {
        a[i][j] = a[i][k]+a[k][j];
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Program
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;
void floyd(int a[4][4], int n)
{
    for(int k=1;k&amp;lt;=n;k++)
    {
        for(int i=1;i&amp;lt;=n;i++)
        {
            for(int j=1;j&amp;lt;=n;j++)
            {
                if(a[i][j]&amp;gt;a[i][k]+a[k][j])
                {
                    a[i][j]=a[i][k]+a[k][j];
                }
            }
        }
    }
    printf("All Pairs Shortest Path is :\n");
        for(int i=1;i&amp;lt;=n;i++)
        {
            for(int j=1;j&amp;lt;=n;j++)
            {
                printf("%d ",a[i][j]);
            }
            printf("\n");
        }
}
int main()
{
    int cost[4][4] = {{0, 3, 999, 4}, {8, 0, 2, 999}, {5, 999, 0, 1}, {2, 999, 999, 0}}; 
    int n = 4;

    floyd(cost,n);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;enter no of vertices :4&lt;br&gt;
The Cost of Adjacency Matrix is :&lt;br&gt;
0 3 9999 7&lt;br&gt;
8 0 2 9999&lt;br&gt;
5 9999 0 1&lt;br&gt;
2 9999 9999 0&lt;br&gt;
All Pairs Shortest Path is :&lt;br&gt;
0 3 5 6&lt;br&gt;
5 0 2 3&lt;br&gt;
3 6 0 1&lt;br&gt;
2 5 7 0&lt;/em&gt;&lt;/p&gt;

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