Basic Concepts of Logic and Algorithms#
Logic was first introduced by Aristotle (384-322 BC).
Algorithm was introduced by the Mathematician: Abu Ja’far Muhammad ibn Musa al-Khwarizmi. A Persian scientist who wrote the book al-jabr wa’l-muqabala (rules of restoration and reduction) around 825 AD.
Definitions of Logic and Algorithm#
Definition of Logic#
- The science within the realm of philosophy that discusses the principles and laws of correct reasoning (Rakmat, 2013).
- The science that provides the principles that must be followed in order to think validly according to applicable rules (Mustofa, 2016).
Definition of Algorithm#
- A sequence of steps to solve mathematical and logical problems (Zarman & Wicaksono, 2020).
- A clear series of instructions to solve a problem (Rinaldi Munir, 2016).
- A limited set of instructions which, when executed, will complete a specific task (Sjukani, 2013).
Problem Solving Stages#

Example of an Algorithm#
How do you make Instant Noodles?
- Example 1
Start
- Boil water
- Put the noodles into the boiling water
- Pour the cooked noodles into a bowl
- Add the seasoning
- Stir evenly.
End
- Example 2
Start
- Boil water
- Put the noodles into the boiling water
- Add the seasoning
- Stir evenly
- Pour the cooked noodles into a bowl
End
Characteristics of an Algorithm#
- An algorithm must stop after executing a finite number of steps.
- Each step must be precisely defined and not ambiguous.
- An algorithm has zero or more inputs.
- An algorithm has zero or more outputs.
- An algorithm must be effective; every step must be simple enough that it can be done in a reasonable amount of time.
Algorithm#
How to write an Algorithm? There is no clear standard for writing algorithms; it depends on the problem and resources. Algorithms are not written to support a specific programming code. All programming languages share basic constructs. The basic constructs consist of:
- Loop / Repetition (
for,while) - Branching / Control Flow (
if–else)
Example: Algorithm to Add Two Numbers and Print the Result
Start
- Read numbers a and b
- Calculate a plus b, store in c
- Write the value of c
End
Writing Algorithms in Pseudocode#

Programming Languages#
A Program is a collection of instructions given to a computer to perform a task or job. To create a program, a programming language is needed.
A Programming language is a computer language used to write programs.
Examples of programming languages are: Assembly language, Fortran, Cobol, Pascal, C, C++, Basic, Prolog, PHP, Java, Python.
Based on their proximity (level), programming languages are grouped into 2 types, namely:
Low-level language A language designed so that each instruction is executed directly by the computer, without having to go through a translator. Example: machine language (a set of binary codes (0 and 1)).
High-level language This type of language makes programs easier to understand.
Examples: Pascal, Cobol, Fortran, Basic, Prolog, C, C++, PHP, Java, Python.
Python Programming Language#
Python is a high-level programming language designed by Guido van Rossum. Python is a programming language that is easy to understand because its syntax structure is neat and easy to learn.
Python is widely used to create application programs such as: GUI programs (desktop), Mobile Web Applications, Games, Hacking, and the Internet of Things (IoT).
Python is recommended for beginners who have never coded before.
C++, Java, and Python Programming Languages#
Printing the Word “Logika Algoritma”
Syntax in C++:
#include <iostream.h>
main() {
cout<<"Logika Algoritma"; }
return 0Syntax in Java:
Class LogicAlgorithmsApp
{
public static void main(String[] args)
{
System.out.println("Logic
Algorithms"); } }Syntax in Python:
print("Logic Algorithms")Algorithm Analysis Stages#
1. How to plan an algorithm.#
By determining a model or design to solve a problem as a solution, so there will be many variations of models taken to find the best one.
2. How to express an algorithm#
Determining the algorithmic model used to create an ordered sequence to obtain a solution to the problem. The algorithmic model can be expressed in pseudocode or a flowchart.
a. Pseudocode#
An informal way to describe an algorithm that follows the structure of a specific programming language.
b. Flowchart#
A diagrammatic representation of an algorithm that illustrates the logical flow of a problem.
The purpose of pseudocode is: Easier to be read by humans, easier to understand and easier to pour out ideas/thoughts.
Example : To calculate the Area of a Triangle
- Input Base Value
- Input Height Value
- Calculate Area = ( Base * Height ) / 2
- Print Area
Advanced Algorithm Analysis Stages#
3. How to validate an algorithm.#
The validity of an algorithm is achieved when a solution is obtained as the resolution of the problem.
4. How to Analyze an Algorithm#
Algorithm analysis by observing the execution time and the amount of memory used.
5. How to Test a Program from an Algorithm#
The algorithm is implemented into a programming language, for example: Python. The algorithm testing process involves two stages, namely: a. Debugging Phase and b. Profiling Phase
a. Debugging Phase#
namely the phase of the program execution process that will make corrections to errors.
b. Profiling Phase#
namely the phase that will work if the program is correct (has passed the debugging phase).





