1 / 14

Computational Complexity

Computational Complexity. Time Complexity Space Complexity. Measuring the Performance of algorithm. Two important measures Time Complexity Space Complexity. Running Time of Algorithm. = How much time the algorithm uses in terms of input size

bozica
Download Presentation

Computational Complexity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Complexity Time Complexity Space Complexity

  2. Measuring the Performance of algorithm Two important measures • Time Complexity • Space Complexity

  3. Running Time of Algorithm = How much time the algorithm uses in terms of input size = # of certain operations used in the algorithm where each operation take a constant time. Like: multiplications, additions, comparisons, assignments, shifts, …etc ≠ # of seconds or minutes used by algorithm, because this depends on machine and technology (O.S., Prog. language, …etc)

  4. Input Size vs. Input Type • The running time is expressed in terms of input size and we concentrate our analysis on large inputs. • Input types (arrays, lists, strings, integers, ..etc) is not an issue here.

  5. Algorithm Running Time • Should be machine & technology independent. • Should concentrate on the asymptotic times (large input size). • Should concentrate on the main largest term (order of growth) and ignore the smaller ones. • Sometimes we may even ignore the 1st constant (multiplicative) factor. • The constant factors or the other smaller terms are important when comparing two algorithms of the same order of running time. • Asymptotic Notations are used to describe asymptotic behavior of algorithm.

  6. Examples of Running Times (RT) • Worst-case RT of Linear Search = θ(n) • Worst-case RT of Binary Search = θ(log n) • Average however is still = θ(log n) • RT of Selection Sort = n(n-1)/2 = θ(n2) • RT of Insertion Sort = Ω(n) and O(n2) • Average however is still = θ(n2) • RT of Bottom Up Merge Sort = θ(n log n) • # of comparisons = RT

  7. Complexity of Running Time • Could be • Logarithmic = θ(log n) • Linear = θ(n) • Quadratic = θ(n2) • Cubic = θ(n3) • Polynomial = θ(nk) … all are efficient.

  8. How to compute the RT • Ugly: by going through the code & counting iterations and operations • Beautiful: by doing smart abstract analysis based on the idea of the algorithm

  9. Space Complexity • Is defined to be the extra space used by the algorithm beside the space allocated to hold the input • I.e., it is the work space used by the algorithm measured by the number of cells or words.

  10. EXamples • Linear Search uses θ(1) (extra) space • And so is Binary Search, ,Selection Sort, and Insertion Sort • Merge Sort however uses θ(n) extra space

  11. Optimal Algorithms • These are algorithms whose worst-case performances meet the best-case performance of any algorithm that solves the same problem • Optimal RT = min { RT of A : A algorithm solves the problem}

  12. EXample • Merge Sort is optimal among all comparisons-based sorting algorithms, because it uses θ(n log n). • Theorem: Any comparisons-based sorting algorithm uses Ω(n log n) cmps. • There are however other non-cmp-based sorting algorithm that do better.

  13. Worst-case vs. Average-case • Which one is better • low worst-case with high average or • low average with high worst-case? • The average is the average!

  14. Input Size = n • Sorting & searching: n = # of elements in the array • Graphs: n, m = # of vertices & edges • Integer Multiplications: n = # of bits • Cryptography: n = # of bits

More Related