<jupyter_start><jupyter_text>Big-O Examples<jupyter_code>#O(1) Constant

def func_constant(values):
    print(values[0])
lst = [1, 2, 3]
func_constant(lst)
#O(n) Linear

def func_lin(lst):
    
    for val in lst:
        print(val)
func_lin(lst)
#O(n^2) Quadratic

def func_quad(lst):
    
    for item_1 in lst:
        for item_2 in lst:
            print(item_1, item_2)
lst = [1, 2, 3, 4, 5]
func_quad(lst)
def print_once(lst):
    
    for val in lst:
        print(val)
print_once(lst)
def print_2(lst):
    
    for val in lst:
        print(val)
        
    for val in lst:
        print(val)
print_2(lst)
def comp(lst):
    
    print(lst[0]) #O(1)
    
    
    ##### O(n/2) . . . O( 1/2 * n)
    midpoint = int(len(lst)/2)
    
    for val in lst[:midpoint]:
        print(val)
    #####
    
    
    for x in range(10): #O(10)
        print('Hello World!')
comp(lst) #O(1 + n/2 + 10) or O(n) 
def matcher(lst, match):
    
    for item in lst:
        if item == match:
            return True
        
    return False
matcher(lst, 1) #Best case is O(1)
matcher(lst, 11) #Worst case is O(n) 
def create_list(n):
    
    new_list = []
    
    for num in range(n):
        new_list.append('new')
        
    return new_list
create_list(10)
def printer(n):
    
    for x in range(10): #Time Complexity is O(n)
        print('Hello World!') #Space Complexity is O(1)
printer(6)<jupyter_output>Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
{'fraction_non_alphanumeric': 0.13328998699609884, 'fraction_numerical': 0.026657997399219768, 'mean_word_length': 2.3096774193548386, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '508005', 'license': 'MIT', 'n_tokens_mistral': 625, 'n_tokens_neox': 606, 'n_words': 164, 'path': 'Python for Algorithms, Data Structures, & Interviews/Algorithm Analysis and Big O/Introduction to Algorithm Analysis and Big O.ipynb', 'repo_name': 'Xelepam/Python_Scripts', 'size': '1538'}