5_onotation

# 5_onotation - AlgorithmAnalysis:BigONotation Bestcase...

This preview shows pages 1–11. Sign up to view the full content.

Algorithm Analysis: Big O Notation

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! Determine the running time of simple algorithms ! Best case ! Average case ! Worst case ! Profile algorithms ! Understand O notation's mathematical basis ! Use O notation to measure running time John Edgar 2
! Algorithms can be described in terms of ! Time efficiency ! Space efficiency ! Choosing an appropriate algorithm can make a significant difference in the usability of a system ! Government and corporate databases with many millions of records, which are accessed frequently ! Online search engines ! Real time systems where near instantaneous response is required From air traffic control systems to computer games John Edgar 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! There are often many ways to solve a problem ! Different algorithms that produce the same results e.g. there are numerous sorting algorithms ! We are usually interested in how an algorithm performs when its input is large ! In practice, with today's hardware, most algorithms will perform well with small input ! There are exceptions to this, such as theTraveling Salesman Problem John Edgar 4
! It is possible to count the number of operations that an algorithm performs ! By a careful visual walkthrough of the algorithm or by ! Inserting code in the algorithm to count and print the number of times that each line executes ( profiling ) ! It is also possible to time algorithms ! Compare system time before and after running an algorithm In Java: System.currentTimeMillis() ! More sophisticated timer classes exist John Edgar 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! It may be useful to time how long an algorithm takes to run ! In some cases it may be essential to know how long an algorithm takes on some system e.g. air traffic control systems ! But is this a good general comparison method? ! Running time is affected by a number of factors other than algorithm efficiency John Edgar 6
! CPU speed ! Amount of main memory ! Specialized hardware (e.g. graphics card) ! Operating system ! System configuration (e.g. virtual memory) ! Programming language ! Algorithm implementation ! Other programs ! System tasks (e.g. memory management) ! John Edgar 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! Instead of timing an algorithm, count the number of instructions that it performs ! The number of instructions performed may vary based on ! The size of the input ! The organization of the input ! The number of instructions can be written as a cost function on the input size John Edgar 8
public void printArray( int arr[]){ for ( int i = 0; i < arr.length; ++i){ System.out.println(arr[i]); } } John Edgar 9 Operations performed on an array of length 10 | declare and initialize i perform comparison, print array element, and increment i :10 times | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | make comparison when i = 10 Java

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! Instead of choosing a particular input size we will express a cost function for input of size n ! Assume that the running time, t , of an algorithm is proportional to the number of operations !
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 112

5_onotation - AlgorithmAnalysis:BigONotation Bestcase...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online