Tuesday, October 25, 2016

Sorting Using swap method

Sorting Using Swap method which takes only one arguments and swap with zero index.

Spiral Matrix


import java.io.*;


public class CircualrMatrix
    {
        public static void main(String args[])throws IOException
        {
        
        int[][] A = { { 1, 2, 3  }, { 5, 6, 7 }, { 9,10,11 } };
        spiralOrder(A);
        }
        
        public  static void spiralOrder(int[][] matrix)
        {
             if(matrix.length == 0)
                 return;
             // Initialize our four indexes
             int top = 0;
             int down = matrix.length - 1;
             int left = 0;
             int right = matrix[0].length - 1;
         
             while(true)
             {
                 // Print top row
                 for(int j = left; j <= right; ++j
                 System.out.print(matrix[top][j] + " ");
                 top++;
                 if(top > down || left > right) break;
                 //Print the rightmost column
                 for(int i = top; i <= down; ++i) System.out.print(matrix[i][right] + " ");
                 right--;
                 if(top > down || left > right) break;
                 //Print the bottom row
                 for(int j = right; j >= left; --j) System.out.print(matrix[down][j] + " ");
                 down--;
                 if(top > down || left > right) break;
                 //Print the leftmost column
                 for(int i = down; i >= top; --i) System.out.print(matrix[i][left] + " ");
                 left++;
                 if(top > down || left > right) break;
             }
         }

    }

Sunday, July 31, 2016

LCA - Lower Common Ancestor


  • http://www.java2blog.com/2016/04/lowest-common-ancestor-of-binary-tree.html

DFS and BFS


  • http://www.java2blog.com/2015/12/depth-first-search-in-java.html

  • http://www.java2blog.com/2015/12/breadth-first-search-in-java.html



Binary Search Tree

  • Binary Search Tree
    • http://www.tutorialspoint.com/data_structures_algorithms/binary_search_algorithm.htm

Serialize and De-Serialize Binary Search Tree


  • Serialize and De-Serialize Binary Search Tree
    • https://www.careercup.com/question?id=9253182
    • http://www.geeksforgeeks.org/618/