1 / 16

5. Abstract Data Structures & Algorithms

5. Abstract Data Structures & Algorithms. 5.6 Algorithm Evaluation. 5.6.1 Big O Notation. Is efficiency the same as speed?. Efficiency. The efficiency of an algorithm depends on: the speed of the processor available memory how well the algorithm is written

gizi
Download Presentation

5. Abstract Data Structures & Algorithms

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. 5. Abstract Data Structures & Algorithms • 5.6 Algorithm Evaluation

  2. 5.6.1 Big O Notation

  3. Is efficiency the same as speed?

  4. Efficiency • The efficiency of an algorithm depends on: • the speed of the processor • available memory • how well the algorithm is written • Only the latter is under the programmer's control

  5. Speed vs memory • Usually a compromise between these two. • e.g. a linked list (dynamic) requires less memory that an array (static), but searching an array is faster if they are the same size.

  6. Processor speed • This is not usually measured in time, but in number of operations per second. • Often floating point operations per second (flops), or gigaflops, teraflops, etc. • Obviously depends on the number of elements you are processing (n)

  7. Memory • More cache makes the processor faster. • More IAS means • less time paging data in and out of virtual memory on the hard drive, and • more data/programs running simultaneously

  8. Algorithm speed • Difficult to predict - depends on circumstances • E.g. a linear search of an array: • best case scenario: 1 (it's the first element!) • worst case scenario: n (it's not there and you've wasted your time looking at n elements!) • average case scenario: n/2

  9. BigO notation • BigO notation assumes worst case • It is defined in terms of n, the number of elements being operated on. • You should know the BigO efficiency of a single operation, linear search (array or linked list), binary search, bubble and selection sort, quicksort

  10. Single operation • Only need one operation no matter what the arguments • E.g. reading a value from a random access file. • BigO efficiency for a single operation is O(1)

  11. Linear search • The time to search an array is proportional to the size of the array • BigO efficiency for a linear search is O(n)

  12. Binary search • Binary search is more complex, but the splitting in half each time is efficient on a logarithmic scale • Big O order is O(log n) • A binary search is much more efficient than linear with larger numbers of elements.

  13. Quicksort • Quicksort is the binary equivalent for sorting • Big O order is O(n log n) • More efficient than bubble or selection sort with larger numbers of elements

  14. Bubble sort • With a bubble sort and a selection sort, you have to compare each element with every other one, so the BigO order is O(n2) • Time requirements are proportional to the square of the size of the list (double the number of elements, quadruple the time taken)

  15. Sorting • In some circumstances, the efficiency of an algorithm may depend on the distribution of the data • E.g. a quicksort where the pivot is chosen too far away from the centre may deteriorate to O(n2).

  16. Other operations • An input or output is O(1) (single operation) • Sequential access of a data file is O(n) (it’s a linear search) • Direct access of a data file is O(1) (single operation) • Finding a specified element of an array is O(1).

More Related