Algorithms Flashcards
Define A Problem
A problem refers to anything that requires a computational solution
Define Problem Solving
This is the process or act of finding a solution to difficult or complex issues. Or The process of working through details of a problem to reach a solution.
Identify all the steps in the problem solving process:
- Identify & Define the Problem
- Analyze the Problem
- Identify Possible Solutions
4.Select & Develop the Best Solution
- Test algorithm
- Coding and implementation
Define the term Algorithm
A set of sequential steps usually written in Ordinary Language used to solve a given problem
Define the term narrative
A narrative is a detailed worded representation of an algorithm. It is explicit in its depiction of the steps that must be followed to produce the desired results.
List and explain the properties of an algorithm
FINITE: Must terminate.
UNAMBIGUOUS: Must be clearly stated.
EFFECTIVE: Must be easy to convert to program statement
GENERAL: Must be complete to solve specific problems for any relative input data
INPUT/OUTPUT: Must take zero, one or more quantities as input and produce one or more output values.
What is a psuedocode?
Pseudocode: A pseudocode is a step by step solution to a problem which is written using English-like statements and mathematical notations to explain the logics in solving a problem. Pseudocodes do not conform to any particular programming language’s syntax; they must however, be written in such a way as to allow them to be translated line by line into source code.
Define the term ‘flow chart’
A flowchart is a pictorial representation of the sequence of instructions required to solve a problem.
Explain and give an example of the ‘repeat until’ loop
The repeat until loop is the type of loop that keeps on carrying out a command or commands UNTIL a given condition is satisfied, the condition is given with the UNTIL command, for example:-
PROBLEM: To wash a car
ALGORITHM:
1 REPEAT
2 wash with warm soapy water
3 UNTIL the whole car is clean
Explain and give an example of the ‘while’ loop
In this type of loop the condition is given along with the WHILE command and the loop keeps on carrying out a command or commands until an END WHILE command is given.
example:
PROBLEM: To ask for a number more than 10, then stop when such a number is given
ALGORITHM:
1 WHILE number given is less than 10
2 ask for a number more than 10
3 END WHILE
Explain the ‘for loop’
A FOR loop keeps on carrying out a command or commands, FOR a given number of times. In this type of loop the number of times it is repeated must be known. The commands to be repeated are sandwiched between the FOR and END FOR commands.
For example:-
PROBLEM: To print the numbers from 10 to 20
ALGORITHM:
1 FOR number = 10 to 20
2 Print number
3 END FOR
Example 2:-
PROBLEM: To print the 13 times table from 1 x 13 to 10 x 13
ALGORITHM:
1 FOR z = 1 to 10
2 Print 13 x z
3 END FOR
List and explain Properties of algorithms
Finiteness: The algorithm must always terminate after a finite
number of steps.
Definiteness: Each step must be precisely defined; the
actions to be carried out must be rigorously and unambiguously
specified for each case.
Input: An algorithm has zero or more inputs, taken from
a specified set of objects.
Output: An algorithm has one or more outputs,
which have a specified relation to the inputs.
Effectiveness: All operations to be performed must be
sufficiently basic that they can be done exactly and in finite length.
List and explain characteristics of a good algorithm
Precision– the steps are precisely stated (defined).
Uniqueness– results of each step are uniquely defined and only depend on the input and the result of the preceding steps.
Finiteness– the algorithm stops after a finite number of instructions are executed.
Input– the algorithm receives input.
Output– the algorithm produces output.
Generality– the algorithm applies to a set of input