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…int…long!!!

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…