Download presentation
Presentation is loading. Please wait.
Published byMekhi Delany Modified over 10 years ago
1
Design and Analysis of Algorithms Review on time complexity, “in place”, “stable” Haidong Xue Summer 2012, at GSU
2
Time complexity of algorithms Execution time? – Pros: easy to obtain; Cons: not accurate Number Instructions? – Pros: very accurate; Cons: calculation is not straightforward Number of certain operations? – Pros: easy to calculate, generally accurate; Cons: not very calculate Asymptotic Notations Pros? Cons?
3
Time complexity of algorithms In the worst case for(int i=0; i<A.length; i++) C1: cost of “assign a value ” C2: cost of “<” C3: cost of “increment by 1” C4: cost of “==” C5: cost of “return” C1 + (length+1)*C2+ length*C3 length*C4 0*C5 C5 Assuming C4 >> C1, C2, C3, C5 Worst case T(n) = n*C4 = (n) Worst case T(n) = C1+C2+ C5 + n(C2+C3+C4)+ = (n)
4
“in place” and “stable” in sorting algorithms AlgorithmWorst TimeExpected TimeExtra MemoryStable Insertion sortO(1) (in place)Can be Merge sortO(n)Can be Quick sortO(1) (in place)Can be Heap sortO(1) (in place)No 23313 5 23313 5 2 3 31 3 5 Stable Not stable
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.