Cs 101 Final Term
Cs 101 Final Term
Lecture 88
1. Algorithm: Representation (Primitives)
What It Means:
• To represent algorithms, we need a clear and precise way to describe them.
• Using natural languages (like English) or pictures can cause confusion because:
• Words can have double meanings.
• The level of detail may not be enough.
Primitives:
• A primitive is a basic building block used to write algorithms.
• Each primitive has:
• Syntax: How it looks (its symbol).
• Semantics: What it means (its purpose).
• Example: "Air" has symbols (syntax) and means a gas (semantics).
Programming Languages:
• Programming languages use primitives and rules to create algorithms.
• Machine Language: Very basic and detailed, meant for computers but hard for humans to
use.
• Higher-Level Languages: Simplified and easier to understand for humans.
Lecture 89
2. Algorithm: Representation (Pseudocode)
What It Means:
• Pseudocode is a simple, informal way to write an algorithm.
• It doesn’t follow strict programming language rules but is still clear enough to understand.
Key Features:
1. Assignments: Storing a value for later use.
• Example:
RemainingFunds = CheckingBalance + SavingsBalance
Here, the total is divided by 366 if it’s a leap year, otherwise by 365.
Why Use Pseudocode:
• It’s easier to write and understand.
• Helps to plan algorithms before converting them into actual code.
Key Ideas
1. Clarity is Important: Algorithms should be written in a way that everyone understands.
2. Primitives: Basic tools that make writing algorithms easier and clearer.
3. Pseudocode: A flexible, simple way to describe how an algorithm works before writing
actual code.