Algorithms definition : a set of small steps (tasks) to solve a problem
human ex :
- go to kitchen
- pick up the egg and oil
- heat up the pan
- make an omlete
computer ex:
- wrote an f(n) where n is the array
- create pi_array a variable which should store pi number of num index in n
- write a for loop that loop trough the value ,index on n in array
- with every iteration calculate the pi and add it to pi_array
- after ending the iteration return the pi_array
— Time Complexity : O(n) >
human ex :
- go to kitchen
- pick up the egg and oil
- heat up the pan
- make an omlete
computer ex:
- wrote an f(n) where n is the array
- create pi_array a variable which should store pi number of num index in n
- write a for loop that loop trough the value ,
- with every iteration calculate the pi and add it to pi_array
- after ending the iteration return the pi_array
— Time Complexity : O(n) >
O(1) : pi_array + n x O(1) : for loop + O(1) = O(n) => Time grows as input gets larger
Programming Notes ✍️
Algorithms definition : a set of small steps (tasks) to solve a problem human ex : - go to kitchen - pick up the egg and oil - heat up the pan - make an omlete computer ex: - wrote an f(n) where n is the array - create pi_array a variable which should…
some things to note :
- in time complexity calculation we doesn't calculate the memory allocation of something like f(n)
- with every loop in the function the (n) get's powerd by 1 something like : O(n2).
- in time complexity we measure the worst case scenario like if a constant time was 0.0100 we wrote it O(1) because it's never 1 is the worsest scenario.
- in time complexity calculation we doesn't calculate the memory allocation of something like f(n)
- with every loop in the function the (n) get's powerd by 1 something like : O(n2).
- in time complexity we measure the worst case scenario like if a constant time was 0.0100 we wrote it O(1) because it's never 1 is the worsest scenario.