Книга: A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 1
Назад: Binary Search vs. Linear Search
Дальше: Exercises

Wrapping Up

Often there’s more than one way to achieve a particular computing goal, and the algorithm you choose can seriously affect the speed of your code.

It’s also important to realize that there usually isn’t a single data structure or algorithm that is perfect for every situation. For example, just because ordered arrays allow for binary search doesn’t mean you should always use ordered arrays. In situations where you don’t anticipate the need to search the data much but, instead, to add data, standard arrays may be a better choice because their insertion is faster.

As we’ve seen, the way to analyze competing algorithms is to count the number of steps each one takes. In the next chapter, we’re going to look at a formalized way of expressing the time complexity of competing data structures and algorithms. Having this common language will give us clearer information that will allow us to make better decisions about which algorithms we choose.

Назад: Binary Search vs. Linear Search
Дальше: Exercises