2.3 - Algorithms Flashcards
Define an Algorithm
A set of steps must be followed, one after each other to solve a problem.
What are the 3 main components of an algorithm?
- Input
- Process
- Output
What are the qualitites of a good algorithm?
- has clear + precisly stated steps that produce the correct output for any set of valid inputs.
- allows for invalid inputs.
- must always terminate at soome point.
- should execute efficiently in as few steps as possible.
- designed so other people can understand + modify if necessary.
Define a statement
A single line of instruction in code.
Define efficiency
No. of assignment statements. Less lines = more efficient + less memory storage is used. Instructions proceed quicker.
What can cause execution time to be longer?
If the promblem size is bigger or there is a larger amount of data.
What is the equation for a linear function?
f(n) = an +b
a + b are constants
e.g. f(n) = 3n, f(n) = n + 5, f(n) = 6n + 1
What is the equation for a constant function?
f(1)
e.g f(2), f(100)
Define a constant function.
No matter how large n gets, f(1) stays the same.
What is the order of magnitde for a linear function?
O(n)
Define a linear function.
Everything increases in a straight line
What is the equation for a quadratic function?
f(n) = an∧(2) + bn + c
Define a quadratic function.
As n increases, the n∧(2) term increases much faster than either of the other terms.
What is a stack?
A stack is an abstract data type that serves as a collection of elements. An example of FILO. (Try to imagine FILO with books.)
What is the order of magnitude for a quadratic function?
O(n∧2)