time-complexity

What is the Time Complexity (Big-O) of a .replace() within a while loop?

What is the Time Complexity (Big-O) of a .replace() within a while loop? Question: I was debating an optimal approach with my peer to an algorithms question about how to count the unpaired parenthesis in a string. Here’s an excerpt for the problem description: A string of brackets is considered correctly matched if every opening …

Total answers: 1

Python string comparisons time complexity

Python string comparisons time complexity Question: I’m curious how Python performs string comparisons under the hood. For example if if s1 == s2: print(True) else: print(False) is the same as condition= True for x,y in zip(s1, s2): if x != y: condition = False print(condition) Perhaps under the hood python is able to use ord …

Total answers: 3

time & space complexity of list versus array operations

time & space complexity of list versus array operations Question: I’m trying to wrap my head around the space & time complexity of algorithms. I have two examples of different ways to modify each individual element in an array. I’m using Python and I’m curious if there’s a difference between the complexity of these two …

Total answers: 1

Expected execution time vs actual execution time in python

Expected execution time vs actual execution time in python Question: I have two different functions for solving the knapsack problem. The difference in these functions is that the v2 function uses less space over v1. From my time complexity analysis, the v2 function should not be faster than v1. However, after running my test cases …

Total answers: 1

Big O time complexity for nested for loop (3 loop)

Big O time complexity for nested for loop (3 loop) Question: def unordered pair(arrayA, arrayB): for i in range(len(arrayA)): for j in range(len(arrayB)): for k in range(0, 100000): print(arrayA[i] + arrayB[j]) I just started Big O and need help on this example. If I tried to get the time complexity for each line, I know …

Total answers: 2

What is the time complexity of a while loop that uses random.shuffle (python) inside of it?

What is the time complexity of a while loop that uses random.shuffle (python) inside of it? Question: first of all, can we even measure it since we don’t know how many times random.shuffle will shuffle the array until it reaches the desired outcome def sort(numbers): import random while not sort(numbers)==numbers: random.shuffle(numbers) return numbers Asked By: …

Total answers: 1