Unit 2 - Problem solving and theory of computation Flashcards
What is Structured programming?
Structured programming is a method of writing a computer program which uses:
Top-down analysis for problem-solving.
Modularization for program structure and organisation.
Structured code for the individual modules.
What is top-down analysis?
The program is divided into modules, which are called from the main program.
Any of the modules may be further broken down into smaller sub-tasks, with the smallest modules performing a single function.
A hierarchy chart may be used to show the overall program structure.
How does a hierarchy chart work?
Execution takes place from left to right, always at the lowest level component.
Selection and iteration are not shown in a hierarchy chart.
Any module shown below another module is part of the module above.
What are some benefits of structured programming?
Programs are more easily and quickly written:
Large programs are broken down into subtasks that are easier to program and manage.
Each module can be individually tested.
Modules can be re-used several times in a program.
Programs are more reliable and have fewer errors:
It is easier to find errors in small self-contained modules.
Programs take less time to test and debug.
Programs are easier to maintain:
A well-organised, modular program is easier to follow
It is easier to find which module needs to be changed
Self-contained modules mean that the change should not affect the rest of the program.
What is modular programming?
Subdividing a computer program into separate sub-programs
Why do we use modular programming?
Modular design and programming techniques are most useful for large, complex programs.
Some programs have thousands or even millions of lines of code.
What is the aim of structured programming?
Can be thoroughly tested and proved to be error free.
Are easy to understand and maintain.
Minimise duplication of effort.
Why are hierarchy charts used?
They’re a useful design tool for breaking down a large program into manageable chunks.
They’re useful for documentation purposes.
What is computational thinking?
The ability to think logically about a problem and apply techniques for solving it
What are some methods of problem solving?
Simulation
Enumeration – list all cases
Trial and error
Theoretical approach
Creative solution
What is simulation?
The process of designing a model of a real system in order to understand the behaviour of the system, and to evaluate various strategies for its operation.
What are the properties of a good algorithm?
Has clear and precisely stated steps that produce the correct output for any set of valid inputs.
Should allow for invalid inputs.
Must always terminate at some point.
Should execute efficiently, in as few steps as possible.
Should be designed in such a way that other people will be able to understand it and modify it if necessary.
What are some useful tools for designing algorithms?
Hierarchy charts – useful for identifying the major task, and breaking these down into subtasks
Flowcharts – useful for getting down initial ideas for individual subroutines
Pseudocode – will translate easily into program code
What are some examples of sorting algorithms?
Bubble sort and Merge sort.
How does bubble sort work?
To sort an array of n items, n-1 passes are made through the array, with each item being compared with the adjacent item and swapped if necessary.
What does ‘divide and conquer’ mean?
This involves finding a solution to a sequence of smaller, related problems until the instance is small enough to be solved directly.
How does a merge sort work?
Divide the unsorted list into n sublists, each containing one element
Repeatedly merge sublists to produce new sorted sublists until there is only one sublist remaining. This is the sorted list.
An example of a ‘divide and conquer’ algorithm.
What are some examples of searching algorithms?
Linear search and binary search.