AlgorithmEfficiency.pdf

AlgorithmEfficiency.pdf - Algorithm Efficiency COMP 182...

This preview shows page 1 - 7 out of 25 pages.

Algorithm Efficiency COMP 182: Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2015
Image of page 1

Subscribe to view the full document.

All Correct Algorithms Are Not Created Equal When presented with a set of correct algorithms for a certain problem, it is natural to choose the most efficient one(s) out of these algorithms. (In some cases, we may opt for an algorithm X that’s a bit slower than algorithm Y, but that is much, much easier to implement than Y.) Efficiency: Time: how fast an algorithm runs Space: how much extra space the algorithm requires There’s often a trade-off between the two.
Image of page 2
It’s All a Function of the Input’s Size We often investigate the algorithm’s complexity (or, efficiency) in terms of some parameter n that indicates the algorithm’s input size For example, for an algorithm that sorts a list of numbers, the input’s size is the number of elements in the list. For some algorithms, more than one parameter may be needed to indicates the size of their inputs. For the algorithm IsBipartite, the input size is given by the number of nodes if the graph is represented as an adjacency matrix, whereas the input size is given by the number of nodes and number of edges if the graph is represented by an adjacency list.
Image of page 3

Subscribe to view the full document.

It’s All a Function of the Input’s Size Sometimes, more than one choice of a parameter indicating the input size may be possible For an algorithm that multiplies two square matrices, one choice is n, the order of the matrix, and another is N, the total number of entries in the matrix. Notice that the relation between n and N is easy to establish, so switching between them is straightforward (yet results in different qualitative statements about the efficiency of the algorithm). When the matrices being multiplied are not square, N would be more appropriate.
Image of page 4
It’s All a Function of the Input’s Size Question: For an algorithm that tests whether a nonnegative integer p is prime, what is the input size?
Image of page 5

Subscribe to view the full document.

Units for Measuring Running Time We’d like to use a measure that does not depend on extraneous factors such as the speed of a particular computer, dependence on the
Image of page 6
Image of page 7
  • Spring '15
  • Analysis of algorithms, Computational complexity theory, Asymptotic Analysis of Algorithms, terms of some parameter n

{[ 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