Saturday, 2 April 2016

Best ways to tackle Big data in R

Big data contains millions of data that can be processed using R.Even though R provides few packages to support big data, extra effort is needed.Map reduce algorithms can be created using R for analysing data (Refer:The Art of R Programming - O'Reilly Media).
The original data set size could increase and lead to a bigger object during the analysing process.

I have listed out best ways to handle big data in R.

  • Divide and conquer 
Large datasets could be  divided into smaller subsets and then each of these smaller subsets are worked upon.And faster solutions and different strategies can be obtained through parallel processing of these smaller subsets of data.

  • Memory and hardware
Every data object is stored in memory by R.Therefore for better performance, machines should have higher capacity of  memory. 8TB along with 64-bits machines are best suitable to work with R.Another way is to make use of the packages such as "ff" and "ffbase".These packages doesn't store data in memory." Scale R" provides a variety of a algorithms for analysing data.

  • Incorporating programming languages like Java or c++
Sometimes, components of a program in R can be integrated with high level languages such as Java (or)  c++ for efficient and better performance. rJava combines R and Java and regarded as connection packages (refer: Advanced R development by Hadley Wickham).Renjin is an open source project with consists of altered R interpreter within JVM.Oracle R also uses R-interpreter with variety of Mathematicals functions and libraries.


Saturday, 26 March 2016

Difference between Arrays and Arraylists and Best ways to print int array,byte array,array of strings,two dimensional array and also array of array in Java

Arrays for data structure which acts as a containers that holds collections of variables of same type, in other words ,size collection of elements of the same data type. Variables stored in arrays are in continues memory locations.Before the advent of arraylists , arrays were used by programmers to store huge amount of variables 
Let us first see the differences between array lists and arrays :

  • Arraylists are dynamic in size where the size of an arraylist can grow when new elements are added while arrays are fixed in size.
  •  Arrays contains both objects as well as primitives whereas array list contains only objects.
  • Loops such as For loops are used iterate elements and iterators can be used in arralylists.
  • Arraylists ensures type safety through generics whereas arrays are homogeneous.
  • Elements are added by assignment operators and add() method is used in Arraylists to add elements. 
  • Arrays are mutli-dimensional where as Arraylists are single dimensional.
In order to consturct an array , you should new , then type of array and then specify the size of that array using open and closed  brackets. For example :
new int[6] //here type of array is int and size is 6.


Now let us see the different ways to print int array,byte array,array of strings,two dimensional array and also array of array.
  • Printing int array : 
We can use Arrays.toString(int array), for example : 
int [] odd = {3,5,7};
System.out.printing("odd numbers are"+Arrays.toString(odd));

  • Printing byte array :
Converting String into a byte array is commonly used employed in Java Cryptography Extension encryption. To convert byte array into string , create a string object and delegate the byte array to it.For example : 
String example="hello";
bytes[] bytes = example.getBytes();
String s = new String(bytes);
System.out.println("text decrypted:"+s);
  • Print an array of strings :
There are two ways of printing array of strings. One way is use a FOR loop, for example:
String [] cars=new Strings[3];
cars[0]="Ferrari";
cars[1]="maruthi";
cars[2]="Datsun";
for(int i=0;i<cars.length;i++)
{
System.out.println(cars[i]);

Another way is to use Arrays.toString().
  • Printing two dimensional array:
Here we use Arrays.deepToString, for example: 
String [][] greetings={{"hi","good morning "},{"hello"," good evening "}};
System.out.println(" planets"+Arrays.deepToString);

  • Printing array of array:
Array of same type can be stored into another array. Arrays.deepToString is used to print array of array , for example :

String []arr1=new String [] {"hi","hello"};
String []arr2=new String [] {"how are you"};
String [][] arrayOfArray=new String[][]{arr1,arr2};
System.out.println(Arrays.deepToString));


Friday, 29 January 2016

Difference between arguments and parameters in Java

Parameter is defined in the method header whereas an argument is the instance passed to the method during run-time.
public class Parameters and Arguments {

    public static int divide(int a, int b) { //a, b are parameters here
         a=5;
         b=5;
        return a%b;

    }

    public static void main(String[] args) {
        int x=divide(a, b); //a, b are arguments here
        System.out.println(x);
    }

}
Here a and b are formal parameters which is declared in the method's header. 
Whereas the a and b becomes arguments in the point of invocation.

Wednesday, 27 January 2016

Possible reasons for outOfMemory error and run time and compile time errors in java

outOfJava Heap space : Java is allowed for limited usage memory. Java is divided into two regions namely, Permanent generation and Heap Space. The size for these two regions are set by JVM. OutOfMemory occurs when you add more data to heap space when it is full.
Reasons :
  • Memory leaks: When you don't specify the memory by yourself. The JVM uses the Garbage collection (GC), here the unused items are cleared in memory and again made ready in other words it automatically checks for unused items and removes them.Memory leaks occurs when GC fails to recognize the unused items and fails to remove them.Thus the java heap space increases indefinitely.


Compile time error -Occurs when the code does not follow the Java semantics and syntactic rules
  •  a class tires to extend more than one class 
  • overloading or overriding is not correct
  • referring to a out scope variable
  • inner class has the same name with enclosing class name
  • when class is not abstract but the methods in it are abstract
  • a private member of class A is referenced by  another class B
  • when creating an instance of an abstract class
  • when change the value of the final member
  • when two class or instance have same name
  • missing brackets
  • missing semicolons
  • access to private fields in other classes
  • missing classes on the classpath (at compile time)
Runtime error -
  • using variable that are actually null (may cause NullPointerException)
  • using illegal indexes on arrays
  • accessing ressources that are currently unavailable (missing files, ...)
  • missing classes on the classpath (at runtime)

Thursday, 21 January 2016

Hash table in java

Hashtables are efficient implementation of array data structure (an associative array) that stores key/value pairs and searched by the key value.It uses a floating-point value, a string, another array, or a structure as the index. A hashtable has 2 elements, a key set and a value set.And find a way to represent and keys should always map to the appropriate.Next use a hash function that is perfect for you.A hash function depends upon the criteria, could be anything.
C language is not provided with keyed arrays , in order to access an element is by its index number.
Eg:- students[66];
I have provided the hashtable code in java :
public class HashEntry {
      private int key;
      private int value;

      HashEntry(int key, int value) {
            this.key = key;
            this.value = value;
      }     

      public int getKey() {
            return key;
      }

      public int getValue() {
            return value;
      }
}

public class HashMap {
      private final static int TABLE_SIZE = 100;

      HashEntry[] table;

      HashMap() {
            table = new HashEntry[TABLE_SIZE];
            for (int i = 0; i < TABLE_SIZE; i++)
                  table[i] = null;
      }

      public int get(int key) {
            int hash = (key % TABLE_SIZE);
            while (table[hash] != null && table[hash].getKey() != key)
                  hash = (hash + 1) % TABLE_SIZE;
            if (table[hash] == null)
                  return -1;
            else
                  return table[hash].getValue();
      }

      public void put(int key, int value) {
            int hash = (key % TABLE_SIZE);
            while (table[hash] != null && table[hash].getKey() != key)
                  hash = (hash + 1) % TABLE_SIZE;
            table[hash] = new HashEntry(key, value);
      }
}

Wednesday, 20 January 2016

Best Java Tools For Every Java Programmers

Java is  an Object-oriented language,robust and mainly employed for creating web applications, server handling, user-end API development. The use-case and importance of Java is huge. In-order to master java practice is vital.There are many tools but I have listed most important tools.

  • Spring Framework:-The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications.
  • Hibernate:- Its an object-relation mapping framework.
  • JClarity:-Mainly used for monitoring performance.
  • SparkJava:- Light weight web application framework.
  • Thymleaf:-Java XML/XHTML/HTML5 template engine.
  • JSF and JSP.
  • Grails:-Web application framework.
  • Elastic search:- provides tools to integrate existing applications to power their interactions with incoming data
                                                                                                                               R.Udendran M.tech cse



Tuesday, 19 January 2016

Advanced Data structures and Algorithms.

What is the next stage after learning basic data structures and algorithms ?
I have a collection of data structures and algorithms which are regarded as advance data structures and algorithms. I have provided advance data structures and algorithms for parallel computing too.
  • In Balanced binary search trees :AVL trees ,red black trees ,B/B+ trees.
  • In heap:Binomial heaps,Fibonacci heaps and operations,disjoint set representation.
  • In hashing:Double hashing and Universal hashing.
  • In graph algorithms :DFS ,BFS and connected Components
 Kruskal and prim algorithms - shortest path problem - Dijkstra’s and bellman - ford algorithms -Johnson’s algorithm for sparse graphs - flow networks - ford fukerson algorithm - maximum bipartite matching.
  Parallel algorithms :-
  • PRAM models - EREW, ERCW, CREW and CRCW and relation between various models handling read and write conflicts and work efficiency
  • Brent's theorem
  • Parallel merging, sorting, and connected components
  •  list rank
  •  Euler tour technique
  •  Parallel prefix computation
  • Deterministic symmetry breaking 
Pattern matching:- finite automata based methods - Rabin Karp algorithm - Knuth Morris Pratt algorithm - Boyer Moore heuristic - computational geometry - two dimensional problems - line segment intersection convex hull - Graham’s scan - Jarvis’s march technique - closest pair of points in a set