Книга: Practical Programming, Fourth Edition
Назад: Exercises
Дальше: Searching a List

Chapter 13
Searching and Sorting

A huge part of computer science involves studying how to organize, store, and retrieve data. There are many ways to manage and process data, and it is essential to develop an understanding of how to evaluate the effectiveness of each approach. This chapter introduces you to some tools and concepts that you can use to tell whether a particular approach is faster or slower than another.

Almost all problems
have more than one
correct solution

As you know, there are many solutions to each programming problem. If a problem involves a large amount of data, a slow algorithm will mean the problem can’t be solved in a reasonable amount of time, even with a potent computer. This chapter includes several examples of both slower and faster algorithms. Try running them yourself; experiencing just how slow (or fast) something is has a much more profound effect on your understanding than the data included in this chapter.

Searching and sorting data are fundamental parts of programming. In this chapter, you’ll see several algorithms for searching and sorting lists, and then you’ll use them to explore what it means for one algorithm to be faster than another. As a bonus, this approach will give you another set of examples of how there are many solutions to any problem, and that the approach you take to solving a problem will dictate which solution you come up with.

Назад: Exercises
Дальше: Searching a List