📚

All Subjects

 > 

⌨️ 

AP Comp Sci P

 > 

📱

Big Idea 3: Algorithms and Programming

Mathematical Expressions

3 min read•november 16, 2020

minnachow

Minna Chow


AP Computer Science Principles ⌨️

Bookmarked 2.3k • 69 resources
See Units

An algorithm 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.

Sequencing

Every algorithm is created using three basic concepts: sequencing, selection, and iteration. These concepts are conveyed in code statements.
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 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.

Expressions

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.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-YY4sZN7LIa6L.png?alt=media&token=41d381f1-b288-4484-af78-19e9d40bd57b

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.

Was this guide helpful?

Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
Hours Logo
Studying with Hours = the ultimate focus mode
Start a free study session
🔍 Are you ready for college apps?
Take this quiz and find out!
Start Quiz
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
✏️Blogs
📝Exam Prep
Join us on Discord
Thousands of students are studying with us for the AP Computer Science Principles exam.
join now
💪🏽 Are you ready for the AP CSP exam?
Take this quiz for a progress check on what you’ve learned this year and get a personalized study plan to grab that 5!
START QUIZ