





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 1
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 2
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 3 Big O
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 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 )
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 7 Binary Search: Worst Case How many iterations are needed before we end up with no elements left to examine? Array length Iterations
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 8 Big O: Formal Definition Let T(n) = the number of operations performed in an algorithm as a function of n. T(n) = O(f(n)) if and only if there exists two constants, n 0 > 0 and c > 0, and a function f(n) such that for all n > n 0 , cf(n) ≥ T(n). n 0 T(n) n cf(n)
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 9 Example Again
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 10 More about Big O Big O gives us an upper-bound approximation on the complexity of a computation. We can say that the following computation is O(n^3 ):
A tighter bound would be O(n^2 ), but both are technically correct.
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 13 Traveling Salesperson
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 14 Traveling Salesperson A B D C G E F
15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 15 Traveling Salesperson
how to build a route 15-121 Introduction to Data Structures, Carnegie Mellon University - CORTINA 16 Comparing Big O Functions N (amount of data) Number of Operations
O(N log N) O(log N)