big-o

Runtime of dynamic programming versus it's naive recursive counterpart

Runtime of dynamic programming versus it's naive recursive counterpart Question: The problem follows: You are playing a game where you start with n sticks in a pile (where n is a positive integer), and each turn you can take away exactly 1, 7, or 9 sticks from the pile (if there are fewer than 9 …

Total answers: 1

Time complexity of recursion of multiplication

Time complexity of recursion of multiplication Question: What is the worst case time complexity (Big O notation) of the following function for positive integers? def rec_mul(a:int, b:int) -> int: if b == 1: return a if a == 1: return b else: return a + rec_mul(a, b-1) I think it’s O(n) but my friend claims …

Total answers: 4

Big O notation : limited input

Big O notation : limited input Question: As an exercise, I am trying to set Monte Carlo Simulation on a chosen ticker symbol. from numpy.random import randint from datetime import date from datetime import timedelta import pandas as pd import yfinance as yf from math import log # ticker symbol ticker_input = "AAPL" # change …

Total answers: 1

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

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

Is O((b-a)/c) the time complexity of list[a:b:c] in python3?

Is O((b-a)/c) the time complexity of list[a:b:c] in python3? Question: According to https://wiki.python.org/moin/TimeComplexity, the complexity of "Get a Slice" from list is O(k) and k is the length of wanted slice. If there is a step parameter, the complexity will become O(k/step)? (i.e. O((b-a)/c) for list[a:b:c]) Asked By: shenlebantongying || Source Answers: Surely it is. …

Total answers: 1

What is the efficiency of python's list slicing?

What is the efficiency of python's list slicing? Question: I am wondering what is the efficiency of slicing lists in python? For Example: myList = [1, 2, 3, 4, 5] newList = myList[1:4] I’m looking for big-O notation (e.g. O(n)). Asked By: Wahid Bawa || Source Answers: It’s O(n) for lists, and most sequence types, …

Total answers: 1