Algorithms and Programming: Essential Concepts
Algorithms: Definition and Characteristics
An algorithm is a finite and orderly sequence of unambiguous instructions that solves a given problem.
Characteristics of Algorithms
- Each step should be perfectly defined.
- Each step must be executed in a finite time.
- There must be a set of initial data.
- There must be a set of output data.
Loop or Cycle
A set of instructions that are repeated a finite number of times is associated with a portion of the instructions. A condition determines when the loop terminates. A loop can be nested inside another, and several loops may exist at the same level, but they should never intertwine.
Programming
In computer programming, it is a process by which the source code of a computer program is written (in a programming language), refined, and tested. Computer programs contain the elements that make up the software, which is the set of instructions that run the hardware of a computer to perform a particular task.
Programming Languages
A programming language is a set of symbols and syntactic and semantic rules that define its structure and the meaning of its elements and expressions. It is used to control the physical and logical behavior of a machine.
Reserved Words
In programming languages, a reserved word is a word that has a special grammatical meaning for that language and cannot be used as an identifier in that language.
Program Concept
A program is a set of orders that transform input into understandable output.
How does it achieve results?
By using algorithms that detail the steps to achieve those results. Input data is transformed into output data through algorithms.
In practice, data has more or less complex structures.
Algorithms + Data Structures = Programs
The difference between an algorithm and a program is that the latter generally implements an algorithm by translating it into a particular programming language. An algorithm is a finite, orderly, and unambiguous sequence of instructions that solve a given problem. This sequence of instructions can then be repeated as often as necessary within the same program or during multiple program executions.
Elements of a Program
- Each of the orders of a program that include constants, variables, operators, and expressions are called sentences or instructions.
- Types of Sentences
- Input/Output: Enable communication between peripherals and main memory.
- Assignment: Assign values to variables.
- Control: Allow breaking the script of a program. They use conditional branching based on a question that admits only two answers.
- Declaration: Can reserve areas of memory to accommodate data.
- Procedures: This is a form defined by the programmer, where a set of statements are grouped into a unit.
- Types of Control
- Sequence: Two or more sentences are executed one after the other.
- Selection or Alternative: One statement or another can be executed depending on the value of a condition.
- Iteration: The repetition of one or more statements a given number of times.
Module Definition
Characteristics
- Consists of one or more statements (sentences) that are physically together.
- Can be referred to by a name.
- Can be called from different points of a program.
- Can be a program, a function, or a subroutine.
Counter
A counter is a variable that accumulates the number of times it is executed. A counter is often referred to when the increment of the variable is 1 by 1.