(2) Algorithms I Flashcards
Definition of Algorithm
A procedure for a systematic and stepwise problem solution.
- abstracts from concrete implementation
- computational procedure that takes input and produces an output
- well defined execution order
- solves a class of problems (not a single problem)
Characteristics of algorithms
- independent of particular programming languages
- independent of particular software
- creative: different algorithms can solve a problem
How can we transfer an algorithm to machine language?
Compiler or Interpreter
Definition Compiler
- computer program
transforms complete program in a programming language in a program in machine language - object code can be executed
How does a Compiler work?
- Scans the entire program first, then translate the entire program and executes the translated program
- Source code is translated exactly once
Definition Interpreter
- Computer program
- Takes one statement at a time of a programming language and translates it into machine language
How does an Interpreter work?
- Scans one statement at a time and translates it
- Directly executes every translated statement
- Source code might need to be translated several times
What are pros and cons of a Compiler and an Interpreter?
Compiler:
+ more efficient -> only one translation of entire program necessary
+ program may be optimised after translation
- for every source code change, program has to be entirely retranslated
Interpreter:
+ fast Response to changes in the program
- repeated translations of statements
- execution is very time consuming
How are programs and data fundamentals designed in Java?
Program: Statements
- number of statements
- represent flow of control
- operate data
Data: Variables
- refer to memory addresses where data is stored
- symbolic identifiers commonly used
- variables are given by their name
Variable Definition
A variable is a symbolic reference to some memory cell. An alias (name) is used to address the variable.
What is a constructed Java type?
- List of same-type elements (array)
- Combination of different types (record)
Definition Array
Collection of elements of the same data type.
- array element is accessed via its index
- arrays may be multi-dimensional
What are the default values of an int array and string array?
int: default value is 0
string: no default value (empty fields)
An algorithm is a sequence of steps with…
- No parallel execution of steps.
- Every step is executed exactly once. No neglection, no repetition.
- The execution order corresponds exactly to the order defined by
the statements. - The execution of the last step of the algorithm completes the algorithm.
Definition Control Structure
A control structure is an instruction which allows to manipulate the order of execution such that the flow differs from the implicitly specified sequential order (restricted to a single thread of execution).