Unit01B - Algorithms A Look At Efficiency Order of...

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

View Full Document Right Arrow Icon
1 1 Algorithms A Look At Efficiency Order of Complexity: Big O Notation 1B 2 Big O Instead of using the exact number of operations to express the complexity of a computation, we use a more general notation called "Big O". Big O expresses the type of complexity function: Linear O(n) Quadratic O(n 2 ) Logarithmic O(log n) Log-Linear O(n log n) Exponential O(2 n ) Constant O(1) 3 Big O Let C represent a function for the number of comparisons needed for an algorithm as a function of the size of the input array(s). Search C(n) = n = O(n) Unique I C(n) = n 2 = O(n 2 ) Diff C(m,n) = mn + n = O(mn) If arrays are the same size: O(n 2 ) 4 More about Big O Consider a computation that performs 5n 2 + 3n + 9 operations on n data elements. The graph comparing the number of data elements to the number of computations will be quadratic . 5n 2 + 3n + 9 = O(n 2 ) Unique II Algorithm C(n) = n(n-1)/2 = O(n 2 ) 5 Example 5 public static int binarySearch(int[] list, int target) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Unit01B - Algorithms A Look At Efficiency Order of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online