Algorithms and programs Flashcards
what is an algorithm?
set of sequential steps that are followed in order to complete a task.
how can you represent an algorithm?
pseudocode
flowcharts
what is a variable?
named location in the computer’s memory that a programmer can use to store data whilst the program is running.
what is the scope of a variable?
the time that a variable is accessible and if it is local or global
how to make your code understandable to other programmers?
self-documenting identifiers, annotation and program layout
function vs procedure
function is a subroutine that returns a value while a procedure is a subroutine that doesn’t
passing a parameter by value
a copy of the data is passed into the procedure and cannot be altered - avoids accidental value changes
passing a parameter by reference
a copy of the memory address is passed into the procedure - data in the calling environment can be changed by the subroutine.
recursive function
calls itself until a base case is met - allows the same operation to be carried out a number of times.
key validation checks
type check - correct data type
length check
range check - numeric values within certain range
format check - data conforms to set of rules
existence check
check digit
typical answer to big O of storage
O(1)
pros of linear search
easy to program
fast with small data sets
data doesn’t need to be sorted
linear search cons
not efficient if item at the end of the array
very slow with large data sets
binary search pros
fast for large set of numbers
divide and conquer so adding large numbers doesn’t incrementally increase search time
binary search cons
data must be sorted
more complex to program