Python Number of Factors

Subscribers:
50,600
Published on ● Video Link: https://www.youtube.com/watch?v=AuXs6ivKPDQ



Duration: 10:00
259 views
7


dammit, I meant complement, not compliment :(

anyway, implementing the number of factors function while analyzing and improving the runtime of the solution.

In this video, we started off with a brute force solution, by checking every single number from 1 to n to see if its a factor of n. This is considered brute force because there is work being done that isn't necessary.

For each number, the last factor is always itself, and the factor before that will always be less than or equal to half of the number. Therefore, we could skip half the iterations after we get to number/2.

However, there is an even better way to solve the problem as every factor comes with a pair. Instead of checking all the numbers, we only need to check the numbers up to square root of the number. Therefore, we could write a much more efficient solution for our problem.

If n = 1,000,000 (1 million):
our first solution would take n iterations, so 1 million iterations.
our second solution would take half of n iterations, so 500k iterations.
our last solution would take square root of n iterations, so 1,000 iterations.

So, you can see that as n gets bigger, the number of iterations differ base on each of the 3 solutions, with our last solution being the most efficient.

Python Playlist:
https://youtube.com/playlist?list=PLnKe36F30Y4bcRomKi02sP9NR27KnBqCK

Subscribe for more coding tutorials 😄!







Tags:
python data structures
python data structures and algorithms
python run time
python run time complexity
python asymptotic analysis
asymptotic analysis
run time complexity
space complexity
big O
python big O
python worst case run time
worst case run time
run time complexity big O
big O run time complexity
python data structures run time
python data structures algorithms
python data structures space complexity
python big O runtime
big O big theta big omega