This lecture for CSEN102: Introduction to Computer Science, given by Milad Ghantous, PhD, focuses on algorithms, their properties, and representation.
An algorithm is a step-by-step procedure for solving a problem or accomplishing a task. It's a set of well-defined instructions that, when executed, will produce a desired output and terminate in a finite amount of time.
Algorithms are at the heart of computer science and programming. They provide a blueprint for how to solve computational problems. Without well-designed algorithms, even the fastest computers would be inefficient. They enable:
Algorithms can be represented in various ways, each with its own advantages for clarity and precision:
A high-level description of an algorithm that uses a combination of natural language statements and programming-like constructs. It is not tied to a specific programming language, making it easy to understand for humans but not directly executable by computers.
Algorithm SumTwoNumbers
Input: Number1, Number2
Output: Sum
Step 1: Get Number1
Step 2: Get Number2
Step 3: Calculate Sum = Number1 + Number2
Step 4: Display Sum
End Algorithm
A graphical representation of an algorithm using standard symbols to depict the flow of logic, operations, and decisions. Flowcharts are good for visualizing the control flow but can become complex for large algorithms.
A flowchart would visually connect these symbols: Start -> Input Number1 -> Input Number2 -> Process: Sum = Number1 + Number2 -> Output Sum -> End.
Using clear, concise English statements to describe the steps of an algorithm. This is often the initial approach but can lack the precision needed for complex algorithms.
The most precise representation, where the algorithm is written in a specific programming language (e.g., C++, Python, Java) that can be executed directly by a computer.
A sequential algorithm is one where instructions are executed in a strict, linear order, one after another, from top to bottom. There are no branches, loops, or conditional jumps in a purely sequential algorithm. Most simple programs start with a sequential flow.
The "SumTwoNumbers" algorithm above is a sequential algorithm.
Thank you