Skip to content

stefan-bordei/python-runtime-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Runtime analysis done in Python3.

Algorithms:

  1. Iterative factorial:
  • Input: integer
  • initialize factorial variable with 1
  • for numbers in range 2 to input + 1 factorial += number
  • return factorial
  1. Recursive factorial:
  • Input: integer
  • if input is 0 return 1
  • else return factorial function with $n - 1$ as argument n times
  1. Tail recursive factorial:
  • Input: integer, accumulator = 1
  • if input is 0 return accumulator
  • else return factorial function with $n - 1$ as argument n times
  1. 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
  1. 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

About

Runtime analysis done in Python3.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors