I am a person far from mathematics, but it took to deal with the O-large function. I tried to write an example in python that would illustrate this function and at the same time be intuitive to a stranger.
As you can see, as the "experimental" function, I use the function of sorting the array by inserts. It has log N complexity, as can be seen by analyzing the console output.
Tell me please, did you succeed in illustrating O-large? Is my code below a good example? Can it be improved or corrected?
#!/usr/bin/env python3 import time from random import randint def insertion(data): for index_r in range(1, len(data)): value_r = data[index_r] index_l = index_r - 1 while index_l >= 0: if value_r < data[index_l]: data[index_l+1] = data[index_l] data[index_l] = value_r index_l -= 1 else: break return data def O(N): for n in (range(N)): arr = [randint(1, n) for i in range(n)] start_time = time.time() insertion(arr) final_time = (time.time() - start_time) print('X-axis: {0}, Y-axis: {1}'.format(n, final_time)) O(100000)
Она имеет log N сложность, в чём можно убедитьсяAlas, it does not. You can't be sure. - MBolog N, then immediately patent - get rich ;-) - MaxU