Algorithms Flashcards
(16 cards)
Define algorithm
A set of rules to solve a specific problem
Why are algorithms designed with no specific programming language
So that the algorithm can be implemented in whichever programming language the developer chooses to use later
Give 3 types of algorithm
Pseudocode
Structured English
Flowcharts
What is the difference between a variable and a constant
Variable
Value can change
Constant
Given one value which stays the same throughout a program
What are constants used for
Improve readability of code
save having to re-enter values in multiple places
Outline 5 ways in which a programmer may make a program easier to understand
- self documenting identifiers;
Variables, procedures, constants, buttons,
Code can be followed and reduces need for additional annotation
Annotation-
Comments can be added to record developmental process and logic
Layout-
Indentation to make nesting easier, iteration
Improved quality of software, maintain standards
Constants
Avoid using global variables where possible-
Outline the meaning behind a scope and lifetime of variables
Scope
The parts of the program in which the variable can be accessed
Lifetime
The duration of time for which the variable holds the value of the execution of a program
Describe the advantages of using subroutines
- makes program easier to understand by splitting into smaller chunks
- easier to test each procedure in isolation before using with the rest
-allows team working
- procedures can be re-used in future programs
- compile procedures and put them in subroutine libraries so they can be called from other programs
-
What is a parameter
Values that can be sent to a procedure and/or received from a procedure
Describe value parameters
Used to pass information into a procedure but don’t receive information
Sending a copy of the parameter to the procedure so any changes made are to the copy and not original
Outline 7 validation techniques
Range check- between min and max
Presence check- has been entered
Length check
Type check- correct type
Format check- m/yyy
Lookup check- confirmed
Check-digits- coded numbers for identification
Describe verification
Checking to see if the data entered is consistent
What is a factorial
Recursion
Factorial(n) = n x Factorial(n-1)
State 3 ways to identify a recursion
Calls itself
Has a terminating condition
When it calls itself it passes one or more parameters
Outline As and Ds for recursion
Requires less code and therefore more elegant
A natural way of thinking about the program
When it runs, it can use more memory bc it needs to keep track of each of the multiple calls to the procedures
Debugging can be more difficult because when an error occurs, it’s not easy to work out which level the error occurred