Algorithms:
- Iterative factorial:
- Input: integer
- initialize factorial variable with 1
- for numbers in range 2 to input + 1 factorial += number
- return factorial
- Recursive factorial:
- Input: integer
- if input is 0 return 1
- else return factorial function with
$n - 1$ as argument n times
- Tail recursive factorial:
- Input: integer, accumulator = 1
- if input is 0 return accumulator
- else return factorial function with
$n - 1$ as argument n times
- Linear search:
- Input: array and element to be found
- iterate through the array and check if the element exists
- if found return the index of the element
- Binary search:
- Input: array and element to be found
- initialize lower and mid to 0 and high to the length of the array
- as long as low <= high
- mid = middle of the array
- if mid < element low becomes mid
- if mix > element high becomes mid
- if mid = element return mid