• kth.se
  • Student web
  • Intranet
  • kth.se
  • Student web
  • Intranet
Login
ID1021 HT22 (50321)
Introduction
Skip to content
Dashboard
  • Login
  • Dashboard
  • Calendar
  • Inbox
  • History
  • Help
Close
  • Min översikt
  • ID1021 HT22 (50321)
  • Assignments
  • Introduction
  • Home
  • Syllabus
  • Assignments
  • Course Evaluation

Introduction

  • Due 31 Aug 2022 by 18:00
  • Points 2
  • Submitting a file upload
  • File types pdf
  • Available 29 Aug 2022 at 8:00 - 2 Sep 2022 at 23:59
This assignment was locked 2 Sep 2022 at 23:59.

A soft start to see that you can measure timeand write a nice reprort. The report should be written using LaTeX and you do so either (recommended) by installing LaTeX locally on you laptop or, by using  Overleaf.  The advantage with Overleaf is that you will be up and running in five minutes and you see the result immediately. The down side is that you will not be able to use your regular editor and will have a some more work when integrating graphs etc.

  • arrays.pdf
  • template.tex

Proposal how to solve the first task:

import java.util.Random;

class Access {

    private static int access(int[] arr, int[] indx) {

	int loop = indx.length;
	
	int sum = 0;
	for (int i = 0; i < loop; i++) {
	    sum += arr[indx[i]];
	}
	return sum;
    }

    private static void time(int tries, int loop, int n) {

	Random rnd = new Random();

	int[] indx = new int[loop];
	for (int i = 0; i < loop ; i++) {
	    indx[i] =  rnd.nextInt(n);
	}

	int[] arr = new int[n];
	for (int i = 0; i < n ; i++) {
	    arr[i] =  i;
	}

	double min = Double.POSITIVE_INFINITY;
	double max = 0;	
	double sum = 0;
	
	for (int i = 0; i < tries; i++) {
	    double n0 = System.nanoTime();	
	    access(arr, indx);
	    double n1 = System.nanoTime();
	    double t = (n1 - n0);
	    if ( t < min )
		min = t;
	    if ( t > max )
		max = t;
	    sum += t;
	}
	System.out.printf("n: %6d \t min: %.2fns\t avg: %.2fns\t max: %.2fns\n", n, (min/(loop)), (sum/(tries*loop)), (max/(loop)));
    }
    
    public static void main(String[] arg) {

	int[] sizes = {200,400,800,1600,3200,6400,12800,25600};

	for ( int n : sizes) {
	    time(10000, 100000, n);
	}

    }
}
1661961600 08/31/2022 06:00pm
Please include a description
Additional comments:
Rating max score to > Pts
Please include a rating title

Rubric

Find rubric
Please include a title
Find a rubric
Title
You've already rated students with this rubric. Any major changes could affect their assessment results.
 
 
 
 
 
 
 
     
Can't change a rubric once you've started using it.  
Title
Criteria Ratings Pts
This criterion is linked to a learning outcome Description of criterion
threshold: 5 pts
Edit criterion description Delete criterion row
5 to >0 Pts Full marks blank
0 to >0 Pts No marks blank_2
This area will be used by the assessor to leave comments related to this criterion.
pts
  / 5 pts
--
Additional comments
Total points: 5 out of 5