Chapter 2

Algorithm Discovery and Design

By the end of this chapter, you will be able to explain the benefits of pseudocode over natural language or a programming language, Represent algorithms using pseudocode; Identify algorithm statements as sequential, conditional, or iterative; Define abstraction and top-down design, and explain their use in breaking down complex problems; Illustrate the operation of algorithms for: Multiplication by repeated addition, Sequential search of a collection of values, Finding the maximum element in a collection; and Find a pattern string in a larger piece of text

Presentation of algorithms

Natural language - everyday languages spoken by populations

Most familiar language

Complicated algorithms may lead to an unstructured, “free-flowing” style, complicating the ability to understand the parts of the algorithm

Many words and phrases have different possible interpretations

Formal cs language

Issue with details such as punctuation, grammar, and syntax

Pseudocode

The compromise between the two extremes

Set of english language constructs designed to resemble statements in a programming language but lacks the ability to run on a computer

Highly readable and no grammatical rules

Contains only statements with a well defined structure → easier visualization of how the algorithm works


Pseudocode Operations

Consists of three basic operations called computation, input, and output

Computations evaluate expressions and stores the results in variables

Variables are a named storage location that can hold data value

Input operations provide computations with data values from the outside world that may be used later on

Output operations return the results of computation(s) using the data provided


Sequential, Conditional, and Iterative Operations


The Flow of each Operation

.


How Each Operation Works

Schneider, G. Michael, and Judith L. Gersting. Invitation to Computer Science. Cengage Learning, 2019