time complexity ..in int and long (java)..plz help

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
public class TurboSort3 {

	public static void main(String args[]) throws IOException {
		BufferedReader br= new BufferedReader( new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(
				new BufferedWriter(
						new OutputStreamWriter(System.out)));
		String s= br.readLine();
		Integer test = Integer.parseInt(s);	
		long[] c= new long[test];
		int i=0;
		while(test>0) {
			int n = Integer.parseInt(br.readLine());
			c[i]=n;
			i++;
			test--;
		}
			
	Arrays.sort(c);
	
		for(int j=0;j<c.length;j++){
			pw.println(c[j]);
			}
		
		pw.close();
		
		}

}

This code takes time=5.29sec…and when I am using “int” instead of ‘long’ for the array ‘c’…that takes time = 10.01 sec…why is it taking different time reading ‘long’ and ‘int’…?? plz explain…

are you sure???

see these two submissions…intlong!!!

int - 5.21

long - 5.30

that is not a huge diff!!!

1 Like

yeah…I checked it out…In my program when I wrote ‘Integer’ not int for the array ‘c’…then it took 9.67 sec… http://www.codechef.com/viewsolution/2299592

Integer is a class. Something more than just int. It is a wrapper around an int.

Being a simple variable has its advantages over being an object of any class. I must anticipate that this must be the reason for the slow down, when using Integer. As @kunal361 points out, there is not much difference when using int and long.

1 Like

ok…thanks for the infomation…