Look for a good bonus quiz to test your performance (in particular, time-related performance)

I do introductory computer science once a week. I was hoping that at the end of my next lab I would strive for competition. I want to give them a code block as follows:

public class EfficientCode{

    public static void main(){
        long startTime, endTime, executionTime;
        startTime = System.currentTimeMillis();

        yourEfficientMethod():
        endTime = System.currentTimeMillis();
        executionTime = endTime – startTime;

    }

    public static void doSomething(){
        // you do this part.  
    }

}

They will implement the doSomething method, and the person with the fastest code will receive several bonus tags.

The problem is that the question should be somewhat simple. Students have a good idea: loops, if / else, strings, append, arrays, etc.

Here are my ideas on what the question might be:

  • find all the ideal numbers from 1 to 1,000,000. (The ideal number is the number where all the numerical factors add up with the number. Ie: 6 = 3 + 2 + 1)
  • find all primes from 1 to 1,000,000

, , , - .

+5
5

, , , - , , , , . , , , , Google.

, . , , , , . , -, , , . , . . , ( ) , , .

- , . , 2kb - . .

+1

" " , , .

Project Euler, . , " ", , . .:)

+7

.

-, - , . , , / .. , . , , , . ...

-, 15 , :

, 121212. . 1 . , 98167 + 23045. , , . 192 ...

+4

. ?

0

Sorting an array of numbers can also be a good idea, since there are a whole bunch of algorithms for it (insert, select, quick, heap, etc.) that have different performance characteristics. It will also give students the opportunity to learn about capitalization O notation, etc.

0
source

All Articles