Download presentation
Presentation is loading. Please wait.
Published byNaomi Washington Modified over 8 years ago
1
Copyright © 2009 Curt Hill Look Ups A Recurring Theme
2
Introduction Scenario: some kind of container class Each item contains two logical pieces: –Key – may be multiple properties –Data – Usually larger than key Basic operations: –Find with a key to get the data –Insert key and data –Delete with a key Copyright © 2009 Curt Hill
3
Auxillary Operations There are many other operations we could do as well Count items are in this container Clear the container Create and destroy Traverse or iterate Copyright © 2009 Curt Hill
4
Organization Details The organization of the ADT determines –The times needed for each of the operations –The characteristics of the key Examples: –Set has key only, no data –Vector Integer key Constant insertion, deletion and find Requires contiguous space –Tree Any type of key Log N insertion, deletion, find Copyright © 2009 Curt Hill
5
Two classes or one? Just because the key and data are separate does not always mean there are two types We merely overload the class to have the comparisons only deal with the key However in a vector there is no need to store the key (an integer) in the data –The position suffices Copyright © 2009 Curt Hill
6
Analysis of Algorithms When considering which data structure or which algorithm to use we should consider the ying and yang of efficiency –Space and speed They tend to be opposed –Decreasing one often increases the other We usually use what is called big O analysis Copyright © 2009 Curt Hill
7
Big O O is short for Order A very rough measure of efficiency, either space or speed Usually neglect all but the most important factors Thus if the running time is: 12 + 5.3X 2 + 32.9X where X is the number of data elements We reduce this to O(X 2 ) Copyright © 2009 Curt Hill
8
Common Os Constant time O(c) or O(1) –Array indexing is constant time Logarithmic time O(log 2 N) –Binary and tree searches Linear time O(N) –File scans, bad searches N log N, O(N log 2 N) – no other name –Good sorts N Squared O(N 2 ) –Bad sorts Polynomial O(N X ) –Expensive but doable Exponential O(e N ) –Intractable
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.