-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
The C++ Programmer's Mindset
By :
This chapter was all about algorithms. An algorithm is a set of instructions that tells a programmer, in a language-agnostic way, how to solve a particular problem. Algorithms have complexity, which is a description of how long the algorithm takes to complete its task based on the size of the inputs. For instance, an algorithm with linear complexity
has a running time proportional to the size of the argument, whereas an algorithm with constant complexity takes the same amount of time regardless of the size of the inputs. Designing efficient algorithms is one way to make your solutions faster. (Of course, reality is far more nuanced than this.)
Sometimes you won’t be able to find an algorithm with a lower complexity, but you might be able to change the design of the algorithm to make it more amenable to the hardware. Designing cache-aware algorithms minimizes the number of loads and stores to memory or arranges them so that these loads can have a dramatic impact...