π

All Subjects

Β >Β

β¨οΈΒAP Comp Sci P

Β >Β

π±Big Idea 3: Algorithms and Programming

3 min readβ’november 16, 2020

Minna Chow

Sound familiar? The definition of an algorithm is very close to the definition of a program. That said, there are some major differences. The key difference is that an algorithm represents the problem-solving *logic*, while a program is* how you carry it out*. Programs execute algorithms.

Going back to our cake metaphor from Big Idea 1, an algorithm would represent the *steps* you take to make the cake while a program would represent the *written recipe* that the baker, or computer, uses to make the cake.

Algorithms can be expressed in a wide range of ways. They can be formally written out in a programming language like C+ or Java (or a block-based language like Scratch!) for a computer to execute, written out in Pseudocode or a natural language like English, or even drawn out in a diagram.

Your computer will only do* exactly* what you tell it to, so it's important to make sure you're being clear and detailed when transferring your algorithms from your head to a program.

Every algorithm is created using three basic concepts: **sequencing, selection, **and **iteration.** These concepts are conveyed in** code statements**.

```
first_number = 7
second_number = 5
sum_value = first_number + second_number
print (sum_value)
```

Each of these statements are run in sequential order: the computer reads and processes them one after the other.

We'll talk more about selection and iteration later in the guide.

Like you learned in math class, an **expression** is a statement that returns only one value.

It can consist of a value, a variable, an operator or a procedure call that returns a value.

Programs work with arithmetic operators: your good old fashioned addition, subtraction, multiplication and division signs.

Here are the operators in College Board's Pseudocode.

The arithmetic operators in Python are the same, except MOD is represented by the % sign.

You'll notice the addition of a new operator known as the **MOD** operator. This is short for the Modulo operator. In the a MOD b format, a is divided by b and MOD gives you what the remainder would be. For example, 13 MOD 3 would return 1 because 13 divided by 3 can be written as 4 remainder 1.

π Code.org has created a visual to represent how MOD works known as the Modulo Clock.

Evaluating an expression is done through an order of operations specified by the programming language you're working with. It's generally going to be PEMDAS, like it is in mathematics. In College Board's Pseudocode, the MOD operator has the same precedence as the multiplication and division operators. (PEMMDAS?)

βDon't forget that, in the PEMDAS system, it's multiplication **or** division and addition **or** subtraction, depending on what order they're written in the equation. Liberal use of parentheses can help make some of this less confusing.

Join Fiveable for free

Create a free account to bookmark content and compete in trivia

Browse Study Guides By Unit

πΉBig Idea 1: Creative Development

βοΈBig Idea 2: Data

π±Big Idea 3: Algorithms and Programming

π₯Big Idea 4: Computer Systems and Networks

β¨οΈBig Idea 5: Impact of Computing

βοΈFrequently Asked Questions

πExam Prep