is a set of instructions used to accomplish a specific task or solve a problem.
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, which are parts of program code that express an action to be carried out.
Sequencing consists of steps in your algorithm that are implemented in the order they're written in. Once you execute one statement, you go on to the next one.
first_number = 7
second_number = 5
sum_value = first_number + second_number
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 Big Idea 3.
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.
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.