Please enable JavaScript.
Coggle requires JavaScript to display documents.
Problem solving and programming - Coggle Diagram
Problem solving and programming
Programming techniques
Programming constructs
Sequence
Code is executed line-by-line, from top to bottom
Branching
Particular block of code is run if a specific condition is met
Uses IF and ELSE statements
Iteration
Can be either:
Count-controlled
Block of code execute a certain number of times
Condition controlled
Block of code is executed while a condition is met
Uses FOR, WHILE or REPEAT UNTIL loops
Recursion
Programming construct in which a subroutine calls itself during its execution
Continues until a stopping condition is met
Advantages:
Can be represented in fewer lines of code
Easier to express some functions recursively e.g. factorial
Disadvantages:
Risk of stack overflow if memory runs out
Difficult to trace
Global and local variables
Variables can be defined with either global or local scope
Scope is the section of code in which the variable can be accessed
A local variable within a subroutine takes precedence over a global variable with the same name
Local variables:
Can only be accessed within the subroutine in which they were defined
Multiple local variables with the same name can exist in different subroutines
Are deleted once subroutine ends
Using local variables ensures subroutines are self-contained
Global variables:
Can be accessed across the whole program
Useful for values that need to be used by multiple parts of the program
Danger of being unintentionally edited
No deleted until program terminates, so require more memory
Modularity, functions and procedures
Modular programming is a technique used to split large, complex programs into smaller, self-contained modules
Easier to divide tasks between a team and manage projects
Simplifies the process of testing and maintenance, as each component can be dealt with individually
Improves reusability of components
Top down design/stepwise refinement:
Technique used to modularise programs
Problem is broken down into sub-problems, until each is represented as an individual, self-contained module which performs a certain task
Modules form blocks of code called subroutines
Functions and procedures:
Both named blocks of code that perform a specific task
Procedures do not have to return a value
Functions must always return a single value
Parameters can be passed into a subroutine either by value or by reference
Passing by value:
A copy of the value is passed to the subroutine and discarded at the end
Its value outside of the subroutine remains unaffected
Passing by reference:
Address of parameter is given to the subroutine
Value of the parameter will be updated at the given address
Use of an IDE
Program which provides a set of tools to make it easier for programmers to write, develop and debug code
Features of IDEs include:
Stepping
Variable watch
Breakpoint
Source code editor
Debugging tools
Use of object-oriented techniques
Object-oriented languages are built around the idea of classes
A class is a template for an object
Classes define the state and behaviour of an object
Object state is given by attributes while behaviour is defined by methods
An object is a particular instance of a class
Attributes cannot be directly edited in a technique called encapsulation
Top-down design applies encapsulation to modules, which are also built to be self-contained and reusable
Computational methods
Features that make a problem solvable by computational methods
Identifying if a problem can be solved using computational methods is the first stage of problem solving
A computable problem can be solved using an algorithm
Some computable problems are impractical to solve due to the resources (processing power, speed and memory) or time they need
Problem recognition
Stakeholders state what they require from the solution
Information used to clearly define the problem and system requirements
Problem may be defined by considering:
Strengths and weaknesses of current solution
Inputs, outputs, stored data and volume of data
Problem decomposition
Problems are broken down into smaller problems until each subproblem can be represented as a self-contained subroutine
Decomposition reduces problem complexity by splitting it up into smaller sections
Enables programmers to find sections that can be implemented using pre-coded modules or libraries
Makes the project easier to manage
Teams can be assigned different modules depending on specialisms
Modules can be designed, developed and tested individually before being combined
Makes it possible to develop modules in parallel, therefore deliver projects faster
Simplifies debugging process, as it is quicker to identify, locate and mitigate errors
Use of divide and conquer
Problem-solving technique that can be broken down into three parts:
Divide: Halves the size of the problem with every iteration
Conquer: Each subproblem is solved, often recursively
Merge: Solutions to the subproblems are then recombined
Applied to problem-solving in quick sort, merge sort and binary search
Simplifies complex problems very quickly
Excessive details are removed to simplify a problem
Problems may be reduced to form problems that have already been solved
This allows pre-programmed modules and libraries to be used
Levels of abstraction allow a complex project to be divided into simpler parts
Levels can be assigned to different teams and details about other layers hidden
Makes projects more manageable
Abstraction is used to represent real-world entities with computational elements
Problem solving strategies
Backtracking:
Problem-solving technique implemented using algorithms, often recursively
Methodically builds a solution based on visited paths found to be correct
If a path is found to be invalid, algorithm backtracks to the previous stage
Data mining:
Technique used to identify patterns or outliers in large sets of data collected from a variety of sources, termed big data
Spots trends or correlations between data which are not immediately obvious
Insights from data mining can aid predictions about the future
This makes data mining a useful tool in assisting business and marketing decisions
Heuristics:
Non-optimal. 'rule-of-thumb' approach to problem solving
Used to find an approximate solution when the standard solution takes too long to find
Solution found through using heuristics is not perfectly accurate or complete
Used to provide estimations for intractable problems, shortest path-finding problems, machine learning and language recognition
Performance modelling:
Mathematical methods used to test various loads on different operating systems
Provies cheaper, less time-consuming or safer method of testing applications
Useful for safety-critical computer systems, where a trial run is not feasible
Pipelining:
Process in which modules are divide into individual tasks, with different tasks being developed in parallel
Enables faster project delivery
Output of one process typically becomes the input of another, resembling a production line
Commonly used in RISC processors: different sections of the fetch decode execute cycle are performed simultaneously
Visualisation:
Data can be presented in a way that is easier for us to understand using graphs, trees, charts, etcc
Makes it possible to identify trends that were not otherwise obvious