Introduction to Basic Algorithms

An algorithm is a method of computation. It usually solves one specific computational task. Unlike a program, which runs directly on a computer, an algorithm is described in mathematical terms and is concerned more with the idea: think of it as an abstract program. One algorithm can be implemented in many different ways, and two different programs may use the same algorithm.

This chapter introduces some basic algorithms. When a computational task is general enough to come up in all kinds of problems, the algorithm that solves it gets called by many other algorithms, which makes it both important and fundamental. The more general an algorithm is, the simpler it tends to be, and the closer it is to an idea than to a program. The algorithms in this chapter are elegant and fun, and they turn up again and again in the more advanced material that follows.