big-o

Python converting a list to set, big O

人盡茶涼 提交于 2020-05-13 13:37:52
问题 and thanks for help words = [....#Big list of words] words_set = set(words) I have hard time determine what is the complexity of set(words) when n=len(words). Is it O(n) since it moves on all the items of the list, or O(l(n-l)) when l is a single word length? Thanks for help! If there is a difference between WC and BC too. Edit: don't mind O(l(n-l)) it's mistake for repeating substring big O. 回答1: I don't understand your second option, but iterating a list is O(n) and you must iterate the

Simplifying the Big-O Complexity of this Exponential Algorithm

自闭症网瘾萝莉.ら 提交于 2020-05-11 06:50:20
问题 I have a counting algorithm for which I am trying to get a general big-o description. It is horribly nested and horribly exponential. Here it is: 1. For each T_i in T 2. For k = 1 to max_k 3. For each of 2^k*(n choose k) items 4. For each t in T_i 5. check if the item is in t...etc. Here is a line-by-line idea of each running time This is a simple partitioning and I'm going to just give it a constant c1. max_k is a small number, always less than n, perhaps around 4 or 5. I will use k below.

Java StringBuilder.setLength() - is time complexity O(1)?

被刻印的时光 ゝ 提交于 2020-05-08 03:15:46
问题 I'm planning to perform lots of deletes of the last character in StringBuilders. The solution to use sb.setLength(sb.length() - 1); looks good to me. However, since these deletions will be in a loop, I need to know complexity of it. The way I understand it is that this operation simply decrements some private attribute of my StringBuilder object and does not perform any copying/cloning/duplicating of the characters themselves, thus it is O(1) in time and should work fast. Am I right? 回答1:

Big O Notation for space complexity of converting a string to char array

吃可爱长大的小学妹 提交于 2020-04-30 04:33:56
问题 Given a string String str= "absdf"; of N length and if we convert the same string to char Array using - char [] arr=str.toCharArray();. Is it consider to be an extra space of O(N) or it will be O(1)? 回答1: It is O(N) as suggested by @andy, the implementation of String.toCharArray() is something like: public char[] toCharArray() { char result[] = new char[value.length]; // copy the contents return result; } 回答2: Time Complexity will be O(N) . Similar to creating a new Array equal to the length

Big O Notation for space complexity of converting a string to char array

别来无恙 提交于 2020-04-30 04:32:04
问题 Given a string String str= "absdf"; of N length and if we convert the same string to char Array using - char [] arr=str.toCharArray();. Is it consider to be an extra space of O(N) or it will be O(1)? 回答1: It is O(N) as suggested by @andy, the implementation of String.toCharArray() is something like: public char[] toCharArray() { char result[] = new char[value.length]; // copy the contents return result; } 回答2: Time Complexity will be O(N) . Similar to creating a new Array equal to the length

Find the median in two AVL BSTs in O(log(n))

只谈情不闲聊 提交于 2020-04-16 04:54:54
问题 So im attempting the classic problem of finding the median in two AVL BST's in O(log(n)) time. Given two AVLs, with a combined size of n (integers are distributed randomly i.e. one may have n-1 elements with the other having 1). I am currently trying to come up with an algorithm to solve this. Each node, besides holding its integer value and pointers to its parent and child nodes, holds the size of the subtree for the subtree rooted at it. I've approached it by initially finding the number of

Find the median in two AVL BSTs in O(log(n))

心不动则不痛 提交于 2020-04-16 04:54:44
问题 So im attempting the classic problem of finding the median in two AVL BST's in O(log(n)) time. Given two AVLs, with a combined size of n (integers are distributed randomly i.e. one may have n-1 elements with the other having 1). I am currently trying to come up with an algorithm to solve this. Each node, besides holding its integer value and pointers to its parent and child nodes, holds the size of the subtree for the subtree rooted at it. I've approached it by initially finding the number of

overall time complexity of the program?

帅比萌擦擦* 提交于 2020-04-16 02:05:44
问题 suppose you take 'n' inputs in an array(and for that you have to run a loop that iterates 'n' times for 'n' different locations), which would have O(n) complexity. And then you you try to perform operations that have O(log n) or less than O(n) time complexity. my question here is that does it really matter to have complexity of those operations less than O(n) since your whole program will have atleast O(n) time complexity. 回答1: Indeed, a program's time complexity could be dominated by the

Solving the recurrence T(n) = T(n / 2) + O(1) using the Master Theorem? [closed]

大兔子大兔子 提交于 2020-04-11 18:44:25
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to solve a recurrence relation to find out the complexity of an algorithm using the Master Theorem and its recurrences concepts, how can I prove that: T(n) = T(n/2)+O(1) is T(n) = O(log(n)) ? Any explanation would be apprecciated!! 回答1: Your recurrence is T(n) = T(n / 2) + O(1) Since the Master

Solving the recurrence T(n) = T(n / 2) + O(1) using the Master Theorem? [closed]

╄→гoц情女王★ 提交于 2020-04-11 18:43:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to solve a recurrence relation to find out the complexity of an algorithm using the Master Theorem and its recurrences concepts, how can I prove that: T(n) = T(n/2)+O(1) is T(n) = O(log(n)) ? Any explanation would be apprecciated!! 回答1: Your recurrence is T(n) = T(n / 2) + O(1) Since the Master