CS ¡10: ¡ Problem ¡solving ¡via ¡Object ¡Oriented ¡ Programming ¡
Winter ¡2017 ¡
¡
Tim ¡Pierson ¡
260 ¡(255) ¡Sudikoff ¡
CS 10: Problem solving via Object Oriented Programming - - PowerPoint PPT Presentation
CS 10: Problem solving via Object Oriented Programming Winter 2017 Tim Pierson 260 (255) Sudikoff Day 7 Lists Part 2 Agenda 1. Growing
¡
260 ¡(255) ¡Sudikoff ¡
2 ¡
3 ¡
int[] numbers = new int[10]; ¡//array ¡of ¡int ¡0..9 ¡(NOT ¡10!) ¡ for (int i=0;i<10;i++) { numbers[i] = i*2; //set ¡each ¡element ¡to ¡i*2 ¡ }
4 ¡
5 ¡
6 ¡
7 ¡
8 ¡
9 ¡
10 ¡
11 ¡
12 ¡
13 ¡
14 ¡
Images: ¡thechessstore.com; ¡studyoffice.org ¡
15 ¡
16 ¡
O ¡gives ¡an ¡asympto>c ¡upper ¡bounds ¡ Run ¡Mme ¡is ¡O(n) ¡if ¡there ¡ exists ¡constants ¡n0 ¡and ¡c ¡ such ¡that: ¡
most ¡cn, ¡upper ¡bound ¡
performance ¡for ¡large ¡ n, ¡but ¡actual ¡ performance ¡could ¡be ¡ beuer ¡
“linear” ¡Mme ¡
Mme ¡
17 ¡
O ¡gives ¡an ¡asympto>c ¡upper ¡bounds ¡ Run ¡Mme ¡is ¡O(f(n)) ¡if ¡ there ¡exists ¡constants ¡n0 ¡ and ¡c ¡such ¡that: ¡
most ¡cf(n), ¡upper ¡ bound ¡
case ¡performance ¡for ¡ large ¡n, ¡but ¡actual ¡ performance ¡could ¡be ¡ beuer ¡
linear ¡funcMon ¡such ¡as ¡ n2 ¡
18 ¡
19 ¡
Ω ¡gives ¡an ¡asympto>c ¡lower ¡bounds ¡ Run ¡Mme ¡is ¡Ω(n) ¡if ¡there ¡ exists ¡constants ¡n0 ¡and ¡c1 ¡ such ¡that: ¡
least ¡c1n, ¡lower ¡bound ¡
performance ¡for ¡large ¡ n, ¡but ¡actual ¡ performance ¡can ¡be ¡ worse ¡
20 ¡
Θ ¡gives ¡an ¡asympto>c ¡>ght ¡bounds ¡ Run ¡Mme ¡is ¡Θ(n) ¡if ¡there ¡ exists ¡constants ¡n0 ¡and ¡c1 ¡ and ¡c2 ¡such ¡that: ¡
least ¡c1n ¡and ¡at ¡most ¡ c2n ¡
bounds, ¡which ¡means ¡ run ¡Mme ¡will ¡be ¡within ¡ a ¡constant ¡factor ¡
either ¡O ¡or ¡Θ, ¡called ¡ asymptoMc ¡notaMon ¡
21 ¡
22 ¡
23 ¡
24 ¡
25 ¡
26 ¡
for (int i=0; i<blobs.size(); i++) { blobs.get(i).step(); }
For (Blob b : blobs) { b.step(); }
27 ¡
¡
28 ¡