8. algorithms Flashcards
recursive subroutine
defined in terms of itself and calls within itself.
the process of executing this subroutine is called recursion
3 characteristics of recursive routine
- stopping condition or base case must be included which when met means that the routine will not call itself and will start to ‘unwind’
- for input values other than stopping condition, the routine must call itself
- the stopping condition must be reached after a finite number of calls
in-order transversal
transverse the left subtree
visit the root node (middle)
visit the right subtree
post-order family
transverse the left subtree
transverse the right subtree
visit the root (right)
pre-order traversal
visit the root (left)
transverse the left subtree
transverse the right subtree
big O notation in order of efficiency
constant
logarithmic
linear
polynomial
exponential
factorial
constant
o(1)
no loops or recursion - what to look out for
e.g. accessing an element in array
linear straight line graph - what the graph looks like
logarithmic
o(log n)
1/2 data sets
e.g. binary search
similar to linear graph but with a bump at the start
linear
o(n)
a single loop
e.g. linear search
‘directly proportional’
polynomial
o(n^2)
nested loops
e.g. bubble sort
half a u
exponential
o(2^n)
recursion
e.g. recursion
half a u closer to y axis
o n log n
e.g. merge sort
permutations
the permutation of a set of objects is the number of ways of arranging the objects.
e.g. if you have 3 objects A B C, you can choose any of A B C to be the first object, you then have two choices for the second object.
formula for calculating the number of permutations of 4 objects is…
4 x 3 x 2 x 1, written as 4!, spoke as “four factorial”
constant time
same amount of time to execute regardless of the size of the input data set