1.9 Algorithms and Programming Flashcards
What is an algorithm?
A series of steps (sequence) to solve a specific problem.
State 3 methods of defining algorithms.
- Flowcharts
- Pseudocode
- Structured english
What is pseudocode? (2)
- A method of writing code without using syntax of any particular language.
- Shows the structure of a solution.
What is structured English?
A cross between pseudocode and written English.
What is a variable?
A named space in the memory that contains a single piece of data.
What is a constant?
The same as a variable except the data
cannot be changed in the program.
Name 3 techniques to make code readable.
- Indenting the code
- Writing annotations to explain the code to programmers
- Using appropriate identifiers
State 2 types of a variable.
- Local
- Global
What is a local variable? (2)
- Only exists until the subroutine in which it was created ends.
- Only visible in that subroutine.
What is a global variable?
Exists throughout the program and can be read/ written from any subroutine.
What is a parameter?
It is an item of data that is passed from one subroutine to another
What are the two ways of passing a parameter?
- Passing by value.
- Passing by reference
What is passing by value? (2)
- A copy of a value passed from one subroutine to another.
- The original value cannot be changed by the subroutine that receives it
What is passing by reference? (2)
- An actual variable is passed from one subroutine to another
- The original value can be changed by the subroutine that receives the variable
What is difference between 5 DIV 3 and 5 MOD 3?
5 DIV 3 = 1 i.e. integer division
5 MOD 3=2 i.e. remainder after division
What is sorting?
Placing data into a specified order .e.g. alphabetical, numerical or other
State 2 sorts.
- Bubble sort
- Insertion sort
How does Bubble Sort work? (4)
- A pass is made through the data, comparing each value with the following one, and swapping if necessary.
- It compares the 1st with 2nd, 2nd with 3rd and so on.
- When it has worked to the end it has completed one pass.
- A number of passes is made until the data is in order/ no swaps
When is Bubble sort most appropriate to use?
Works best on smaller, nearly sorted data.
How does Insertion Sort work? (4)
- Takes an element out the data and compared with a sorted list
- Items in the sorted list are moved up/ down to enable new items to be added in the correct place.
- It initially assumes only the first number is in the correct order.
- With each pass the number of items assumed correct increases by one.
When does insertion sort works best?
Works best on small, jumbled up files.
What is searching?
Locating an item in a data structure