Unit 3: Programming · What is programming?

Article

What computer science is

6 min read

A map app finds the fastest way home in less than a second. A game decides what the enemy does next. Nobody typed those answers in by hand. Someone wrote exact instructions, and a computer followed them. This unit teaches you to write and read instructions like that.

What computer science is

A computer is not clever. It cannot guess what you mean. It does exactly what its instructions say, one instruction at a time, very fast. Because of this, the hard part is not the computer. The hard part is writing instructions that are exact, in the right order, and correct.

Computer science is the study of how to solve problems using computers. It asks questions like these:

QuestionWhere you will meet it
How do we describe a solution in exact steps?This unit
How do we store information as bits?Unit 1
How do computers send data to each other?Unit 2
How fast is a solution, and can a computer solve this at all?Unit 4
How does computing change people's lives?Units 7 and 8

Computer science is not only typing code. A person who plans the steps, finds the mistakes or asks "is this fair to everyone?" is doing computer science too.

From a problem to a running program

Every program starts as a problem someone wants solved. There are four stages between the problem and the answer:

From problem to answer

  1. Problem

    what we want solved

    think
  2. Algorithm

    the steps, in plain words

    write it in code
  3. Program

    the steps in a programming language

    start it
  4. Run

    the computer follows every step

People do the first two stages. The computer does the last one.

An algorithm is a finite list of instructions that accomplishes a task. "Finite" means the list ends. An algorithm can be written in everyday words, in a picture, or in code. It is the idea of the solution.

Every algorithm is built from three ingredients: sequencing (steps done in order), selection (choosing between steps) and iteration (repeating steps). This lesson is about sequencing. Selection and iteration come later in the unit.

Check your understanding

Which sentence describes an algorithm?

A program is an algorithm written in a programming language, so a computer can follow it. A program is made of statements. A statement is one instruction. When the computer follows a program from the first statement to the last, we say the program runs (or executes).

Check your understanding

Mia writes the steps for finding the cost of 3 books in plain English. Then she writes the same steps in Python. Which one is the program?

Worked example: the cost of three books

Problem: each book costs 12 and you buy 3. What is the total?

Algorithm, in plain words:

  1. Start with the price of one book, which is 12.
  2. Multiply the price by 3.
  3. Show the answer.

Program, in Python:

price = 12
total = price * 3
print(total)

The program has three statements, and each one matches one step of the algorithm. The computer runs them from the top to the bottom and shows 36. You will write programs like this very soon.

The whole unit on one page

This unit fits on one map. Come back to it whenever you want to see where a lesson belongs.

Programming
  • What is programming?

    • algorithms and programs
    • DISPLAY
    • reading AP pseudocode
  • Variables

    • store a value under a name
    • change it as the program runs
  • Math

    • + - * / and MOD
    • tracing a program
    • ready-made procedures and constants
  • Strings

    • text in variables
    • joining and slicing text
  • Conditionals

    • IF and ELSE
    • Booleans
    • AND, OR and NOT
  • Logical equivalence

    • different code with the same meaning
    • simpler Boolean expressions
  • Procedures

    • name a group of steps
    • parameters
    • return values
  • Abstraction and libraries

    • use a procedure without its insides
    • libraries and APIs
  • Repetition

    • repeat a set number of times
    • repeat until
    • tracing loops
  • Lists

    • store many values
    • add and remove
    • go through a list

Common mistakes

  • "The computer understands what I mean." No. It follows the exact words you wrote. If a step is missing or in the wrong order, it does the wrong thing and does not warn you.
  • "An algorithm is the same as a program." An algorithm is the plan. A program is the plan written in a language a computer can follow. One algorithm can be written as many different programs, in different languages.
  • "Computer science means learning to code." Coding is one tool. Planning, testing and thinking about people matter just as much.
  • "An algorithm can go on forever." An algorithm has a finite number of steps, so it ends.

On the exam

The exam uses its own words: an algorithm is a finite set of instructions that accomplishes a specific task, and a program is a set of statements written in a programming language. It also says that every algorithm can be built from sequencing, selection and iteration. Questions often show a short plan and ask what it does, or ask you to tell an algorithm from a program. Most of the programming questions ask you to read a short piece of code and say what it does, so reading code carefully is the skill to practise.

Key words

Computer science: the study of how to solve problems using computers.

Algorithm: a finite set of instructions that accomplishes a specific task.

Program: a set of statements written in a programming language.

Statement: one instruction in a program.

Programming language: a language with exact rules that a computer can follow.

Run (execute): when the computer follows the statements of a program.

Sequencing: doing the steps one after another, in order.

Selection: choosing which steps to do.

Iteration: repeating steps.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.