chapter 1: Algorithms pp Flashcards
Definition
An algorithm
is a set of instructions that leads to a deterministic
result in a finite time, once it is correctly executed.
A written set of instructions is called a program or algorithm.
What does an Algorithm consist of?
A computer algorithm is a set of instructions in which we also findstructures and subprograms.:
- Instructions for (declaring and) initializing variables (i.e.assigning initial value)
- Input/output instructions
- Conditional structures:
1) Sequences
2) Iterations
3) Loops - Subprograms:
1) procedures
2) functions
variable is characterized by:
The address
represents the physical place in memory for where the value of a variable is stored. Without these variables, one would have to remember the addresses in memory itself
primitive types
These are types that are an integral part of the programming language.
The instruction type(..)
allows us to find the type of a variable
at a specific point in time in Python.
The type “Character”
(a single character) is usually shown between singlequotation marks (for example, ’a’, ’6’, ’&’). So the value 6 differs fundamentally from the value ‘6’
However, in Python this type does not exist and is seen as a variant of the type str. In Python one can use both single and double quotes for the type str.
The structure of an Algorithm (and therefore every program) consists of three parts:
-> The name of the Algorithm:
It is important to choose the name as clearly as possible, since our programs do not yet have real functionality, the names will be meaningless for the time being.
-> A section in which the variables are declared.:
Since Python is a language with dynamic types, declaring variables is not necessary. Since declaring variables is indispensable in programming languages with static type
checking (such as Java), I choose to teach you this healthy habit by obliging you to document the data type.
-> A set of instructions and operations.
A variable is usually created in two steps:
- First it is declared
- A value is then assigned to the variable by means of an assignment.
initialization.
Assigning an initial value to a newly declared variable is called initialization. The initialization (with a default value) ensures that if the memory reserved at the time of declaration is not empty, the program will not produce unexpected results.
a variable is declared:
- This means that her name and data type are chosen.
- The declaration ensures that the variable becomes part of the program, and
- that a place of the correct size is reserved in the computer memory for storing a value.
- At the time of the declaration, the memory is theoretically empty.
sequential execution.
Algorithms are read and executed from top to bottom, line by line.
This state of the algorithm is defined
as
- the value of all variables at a given time of execution
- the next instruction to be carried out.