SHEN’S CLASS NOTES-191 1Chapter Four Algorithms 4.1 Introduction An algorithm is a well-defined computational procedure to solve a computational problem (or problem for short). An algorithm must be correct. A good algorithm must be readable, time-efficient, space- efficient. A problem defines the requirements that valid output values must satisfy for a given set of input values. Usually, we are only interested in those problems that allow infinitely many different sets and sizes of input values.
has intentionally blurred sections.
Sign up to view the full version.
SHEN’S CLASS NOTES-191 2For example, the sorting problem takes nnumbers as input set and requires the nnumbers be arranged in descending or ascending order as the valid output, where the ncan be any positive integer. For a particular set of input values, the problem is referred as an instance of the problem. Therefore, a problem must contain infinitely many instances. Solving a problem is to find a valid output for any given input, which is done by an algorithm. Relationship Between an Algorithm and A programA program is a piece of code written in a particular language such as Pascal, C, C++, Java, or even some assembly language. Therefore, programs are language dependent or even machine dependent. A program can often be viewed as a detailed implementation of an algorithm with some limitations such as memory capacity, the largest number allowed, the largest size of an array, etc.