{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L8 - CSE 12 Basic data structures and object-oriented...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 12 : Basic data structures and object-oriented design Jacob Whitehill [email protected] Lecture Ate 11 Aug 2011 Thursday, August 11, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
More on performance analysis. Thursday, August 11, 2011
Background image of page 2
Asymptotic performance analysis Asymptotic performance analysis is a coarse but useful means of describing and comparing the performance of algorithms as a function of the input size n when n gets large. Asymptotic analysis applies to both time cost and space cost . Asymptotic analysis hides details of timing (that we don’t care about) due to: Speed of computer. Slight differences in implementation. Programming language. Thursday, August 11, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
O, Ω , and θ In order to justify describing the time cost T ( n ) =3 n +4 as just “linear” ( n ), we first need some mathematical machinery: We define a lower bound on T with Ω . We define an upper bound on T with O . We define a tight bound (bounded above and below) on T with θ . θ is important because it is more specific than O . (For example, technically, 3 n +4= O (2 n ).) Thursday, August 11, 2011
Background image of page 4
Abuse of notation When we say that 3 n +5 is “linear in n ”, what we really mean (mathematically) is that 3 n +5 is θ ( n ). Note : In computer science, we often say O where we really mean θ . This is a slight abuse of notation . We will use O in this course to mean θ . Thursday, August 11, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Asymptotic analysis assigns algorithms to different “complexity classes”: O (1) - constant - performance of algorithm does not depend on input size. O ( n ) - linear - doubling n will double the time cost. O (log n ) - logarithmic O ( n 2 ) - quadratic O (2 n ) - exponential Algorithms that differ in complexity class can have vastly different run-time performance (for large n ). Asymptotic performance analysis Thursday, August 11, 2011
Background image of page 6
Analysis of data structures Let’s put these ideas into practice and analyze the performance of algorithms related to ArrayList : add(o) , get(index) , find(o) , and remove (index) . As a first step, we must decide what the “input size” means. What is the “input” to these algorithms? Thursday, August 11, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Analysis of data structures Each of the methods (algorithms) above operates on the _underlyingStorage and either o or index . o and index are always length 1 -- their size cannot grow . However, the number of data in _underlyingStorage (stored in _numElements ) will grow as the user adds elements to the ArrayList . Hence, we measure asymptotic time cost as a function of n , the number of elements stored ( _numElements ). Thursday, August 11, 2011
Background image of page 8
Adding to back of list class ArrayList<T> { ... void addToBack (T o) { // Assume _underlyingStorage is big enough _underlyingStorage[_numElements] = o; _numElements++; } } What is the time complexity of this method? Thursday, August 11, 2011
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Adding to back of list class ArrayList<T> { ...
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}