{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

5_onotation - AlgorithmAnalysis:BigONotation Bestcase...

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

View Full Document Right Arrow Icon
Algorithm Analysis: Big O Notation
Image of page 1

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

View Full Document Right Arrow Icon
! 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
Image of page 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
Image of page 3

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

View Full Document Right Arrow Icon
! 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
Image of page 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
Image of page 5

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

View Full Document Right Arrow Icon
! 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
Image of page 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
Image of page 7

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

View Full Document Right Arrow Icon
! 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
Image of page 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
Image of page 9

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

View Full Document Right Arrow Icon
! 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 !
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern