The Software Optimization Cookbook: High-Performance Recipes for IA-32 Platforms, Second Edition

Chapter 6: Algorithms

Overview

Choosing an appropriate algorithm is the most important factor in determining whether software will be slow or fast. A good algorithm solves a problem in a fast and efficient manner, while a poor algorithm, no matter how well implemented and tuned, is never as fast.

Algorithms to solve just about any problem are available from a variety of sources: the Internet, books, coworkers, professional journals. Determining which algorithm will be the best for your purpose can be tricky. Computational complexity, memory usage, data dependencies, and the instructions used to implement the algorithm all play a role in determining whether an algorithm will perform well or poorly. Spending some time up front experimenting with different algorithms often saves time later on.

Computational Complexity

Algorithm performance can be judged by using the computer science O-notation analysis for the typical, best, and worst cases. For example, of the many different algorithms for sorting data, which should you choose? The bubble sort is probably the simplest and slowest sorting algorithm. Its computational complexity is O( n 2), meaning that if the number of elements to be sorted doubles, the elapsed time to perform the sort quadruples. The quicksort algorithm on the other hand has a significantly better computational time complexity of O( n log n). Table 6.1 compares the two sorting algorithms for a small, medium, and large numbers of elements to be sorted. It shows the approximate number of operations the algorithms must perform based on their...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Sorting Equipment
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.