Skip to main content

Dynamic Programming in JAVA


  • String
    • Longest common subsequence
    • longest increasing subsequence
    • longest common substring
    • edit distance
  • Graphs
    • bellman ford
    • floyd's all pair shortest
  • chain matrix multiplication
  • subset sum
  • 0/1 knapsack
  • Travelling salesman problem

Comments

.

Popular posts from this blog

Solved: com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range.

This error usually comes when we try to insert data in a query where there is no index defined for it. Example :- String strQuery=“select * from location where city_id=? ”; The question mark will be the the first index if we want to insert data so if we call a function like- oPreparedStatement = oConnection.prepareStatement(strQuery); oPreparedStatement.setString(1,235); here we are sending 235 as a first parameter so it will work fine but as soon as we write something after it like oPreparedStatement.setString(2,”kanpur”) then it will throw “The index 2 is out of range” since there is no place to send this value in a query hence it will throw the same error. Here index defines the parameter for which there is no place in the query. To rectify this we need to write query like- String strQuery=“select * from location where city_id=? And city_name=? ”; then it will work fine. The cases in which these errors can occur is- 1)Query is co

Tree Traversal in JAVA (InOder/preOrder/postOrder)

Tree Traversal in JAVA (InOder/preOrder/postOrder):- Tree traversal can be done through three ways. 1)Inorder:- Go recursively to the left node. Read a node Go recursively to the right node. 2)Pre Order. Read a node Go recursively to the left node. Go recursively to the right node. 2)Post Order. Go recursively to the left node. Go recursively to the right node. Read a node public void inorder ( Node root ) { if ( root == null ) { return ; } inorder ( root . left ); System . out . print ( root . data + "," ); inorder ( root . right ); } public void preOrder ( Node root ) { if ( root == null ) { return ; } System . out . print ( root . data + "," ); preOrder ( root . left ); preOrder ( root . right ); } public void postOrder ( Node root ) { if ( root == null ) { return ; } postOrder ( root . left ); postOrder ( root . right ); Sy