Introduction to Computer Algorithm: Data Structures, Complexity, and Optimization for Modern AI Systems

Basic Operations: The Building Blocks of Computation

Now that we've touched on variables and data types, let's dive into the fundamental actions our algorithms can perform: basic operations. These are the workhorses of computation, allowing us to manipulate data and make decisions. Think of them as the verbs in our algorithmic language.

The most common operations revolve around numbers, and these are often referred to as arithmetic operations. They allow us to perform calculations, which are central to many algorithmic tasks.

Here are the core arithmetic operations you'll encounter:

Addition: This is straightforward – combining two numbers to get their sum. In most programming languages, it's represented by the '+' symbol.

let sum = 10 + 5;
console.log(sum); // Output: 15

Subtraction: Finding the difference between two numbers. The symbol for subtraction is typically '-'.

let difference = 20 - 7;
console.log(difference); // Output: 13

Multiplication: Calculating the product of two numbers. The '*' symbol is commonly used for this.

チャプターへ戻る