{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CarrCh09v2 - C H A P T E R 9 The Efficiency of Algorithms...

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

View Full Document Right Arrow Icon
199 C H A P T E R 9 The Efficiency of Algorithms C ONTENTS Motivation Measuring an Algorithm’s Efficiency Big Oh Notation Formalities Picturing Efficiency The Efficiency of Implementations of the ADT List The Array-Based Implementation The Linked Implementation Comparing the Implementations P REREQUISITES Chapter 1 Java Classes Chapter 5 List Implementations That Use Arrays Chapter 6 List Implementations That Link Data O BJECTIVES After studying this chapter, you should be able to Determine the efficiency of a given algorithm Compare the expected execution times of two methods, given the efficiencies of their algorithms W ith amazing frequency, manufacturers introduce new computers that are faster and have larger memories than their recent predecessors. Yet we—and likely your computer science professors—ask you to write code that is efficient in its use of time and space (memory). We have to admit that such efficiency is not as pressing an issue as it was fifty years ago, when computers were much slower and their memory size was much smaller than they are now. (Computers had small memories, but they were physically huge, occupying entire rooms.) Even so, efficiency remains an issue—in some circumstances, a critical issue.
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
200 CHAPTER 9 The Efficiency of Algorithms This chapter will introduce you to the terminology and methods that computer scientists use to measure the efficiency of an algorithm. With this background, you not only will have an intuitive feel for efficiency, but also will be able to talk about efficiency in a quantitative way. Motivation 9.1 Perhaps you think that you are not likely to write a program in the near future whose execution time is noticeably long. You might be right, but we are about to show you some simple Java code that does take a long time to perform its computations. Imagine that we are defining a Java class to represent extremely large integers. Of course, we will need to represent the many digits possible in one of these integers, but that is not the subject of this example. We want a method for our class that adds two large integers—that is, two instances of our class—and a method that multiplies two large integers. Suppose that we have implemented the add method successfully and are about to design a multiply method. As you know, multiplication is equivalent to repeated addition. So if we want to compute the product 7562 times 423, for example, we could add 7562 to an initially zero variable 423 times. Remember that our add method works, so we can readily use it in our implementation of multiply . 9.2 Let’s write some simple Java code to test our idea. Realize that this code is simply an experiment to verify our approach of repeated addition and does not use anything that we might already have writ- ten for our class.
Image of page 2
Image of page 3
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