This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Time Complexity of an Algorithm The time complexity of an algorithm is
the largest time required on any input
of size n. (Worst case analysis.)
O(n2): For any input size n n0, the algorithm takes
no more than cn2 time on every input.
(n2): For any input size n n0, the algorithm takes at
least cn2 time on at least one input.
(n2): Do both. CSE 2011
Prof. J. Elder  11  Last Updated: 1/7/10 10:14 AM Time Complexity of a Problem The time complexity of a problem is
the time complexity of the fastest
algorithm that solves the problem.
O(n2): Provide an algorithm that solves the problem in no more than
this time.
Remember: for every input, i.e. worst case analysis! (n2): Prove that no algorithm can solve it faster.
Remember: only need one input that takes at least this long! (n2): Do both.
CSE 2011
Prof. J. Elder  12  Last Updated: 1/7/10 10:14 AM Data Structures So Far
Linear Data Structures
Arrays
Linked Lists
Stacks
Queues
Priority Queues NonLinear Data Structures
Trees
Heaps
Hash Tables
CSE 2011
Prof. J. Elder  13  Last Updated: 1/7/10 10:14 AM Arrays CSE 2011
Prof. J. Elder  14  Last Updated: 1/7/10 10:14 AM Arrays
Array: a sequence of indexed components with
the following properties:
array size is fixed at the time of array’s construction
int numbers = new int [10];
array elements are placed contiguously in memory
address of any element can be calculated directly as its offset
from the beginning of the array
consequently, array components can be efficiently inspected or
updated in O(1) time, using their indices
randomNumber = numbers[5];
numbers[2] = 100; CSE 2011
Prof. J. Elder  15  Last Updated: 1/7/10 10:14 AM ...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures

Click to edit the document details