complexity-theory

Different decision tree algorithms with comparison of complexity or performance

三世轮回 提交于 2019-12-04 07:27:41
问题 I am doing research on data mining and more precisely, decision trees. I would like to know if there are multiple algorithms to build a decision trees (or just one?), and which is better, based on criteria such as Performance Complexity Errors in decision making and more. 回答1: Decision Tree implementations differ primarily along these axes: the splitting criterion (i.e., how "variance" is calculated) whether it builds models for regression (continuous variables, e.g., a score) as well as

B-Tree vs Hash Table

一曲冷凌霜 提交于 2019-12-04 07:26:04
问题 In MySQL, an index type is a b-tree, and access an element in a b-tree is in logarithmic amortized time O(log(n)) . On the other hand, accessing an element in a hash table is in O(1) . Why is a hash table not used instead of a b-tree in order to access data inside a database? 回答1: You can only access elements by their primary key in a hashtable. This is faster than with a tree algorithm ( O(1) instead of log(n) ), but you cannot select ranges ( everything in between x and y ). Tree algorithms

Are 2^n and 4^n in the same Big-Θ complexity class?

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:37:50
Is 2^n = Θ(4^n)? I'm pretty sure that 2^n is not in Ω(4^n) thus not in Θ(4^n), but my university tutor says it is. This confused me a lot and I couldn't find a clear answer per Google. chiwangc 2^n is NOT big-theta (Θ) of 4^n , this is because 2^n is NOT big-omega (Ω) of 4^n . By definition, we have f(x) = Θ(g(x)) if and only if f(x) = O(g(x)) and f(x) = Ω(g(x)) . Claim 2^n is not Ω(4^n) Proof Suppose 2^n = Ω(4^n) , then by definition of big-omega there exists constants c > 0 and n0 such that: 2^n ≥ c * 4^n for all n ≥ n0 By rearranging the inequality, we have: (1/2)^n ≥ c for all n ≥ n0 But

What is the difference between O(1) and Θ(1)?

↘锁芯ラ 提交于 2019-12-04 06:37:25
I know the definitions of both of them, but what is the reason sometimes I see O(1) and other times Θ(1) written in textbooks? Thanks. Big-O notation expresses an asymptotic upper bound, whereas Big-Theta notation additionally expresses a asymptotic lower bound. Often, the upper bound is what people are interested in, so they write O(something), even when Theta(something) would also be true. For example, if you wanted to count the number of things that are equal to x in an unsorted list, you might say that it can be done in linear time and is O(n), because what matters to you is that it won't

Why do we prefer not to specify the constant factor in Big-O notation?

泄露秘密 提交于 2019-12-04 06:25:41
问题 Let's consider classic big O notation definition (proof link): O(f(n)) is the set of all functions such that there exist positive constants C and n0 with |g(n)| ≤ C * f(n) , for all n ≥ n_0 . According to this definition it is legal to do the following ( g1 and g2 are the functions that describe two algorithms complexity): g1(n) = 9999 * n^2 + n ∈ O(9999 * n^2) g2(n) = 5 * n^2 + N ∈ O(5 * n^2) And it is also legal to note functions as: g1(n) = 9999 * N^2 + N ∈ O(n^2) g2(n) = 5 * N^2 + N ∈ O(n

Merging sorted arrays, what is the optimum time complexity?

北城余情 提交于 2019-12-04 06:07:53
I have m arrays, every array is of length n. Each array is sorted. I want to create a single array of length m*n, containing all the values of the previous arrays (including repeating values), sorted. I have to merge these arrays.. I think the optimum time complexity is m*n*log(m) Here's the sketch of the algorithm.. I create a support array H of lenth m, containing all the values of the first element of each array. I then sort this array (m log m), and move the min value to the output array. I then replace the moved value with the next one, from the array it was taken. Actually I don't

Why Bubble sort complexity is O(n^2)?

微笑、不失礼 提交于 2019-12-04 05:26:40
问题 As I understand, the complexity of an algorithm is a maximum number of operations performed while sorting. So, the complexity of Bubble sort should be a sum of arithmmetic progression (from 1 to n-1), not n^2. The following implementation counts number of comparisons: public int[] sort(int[] a) { int operationsCount = 0; for (int i = 0; i < a.length; i++) { for(int j = i + 1; j < a.length; j++) { operationsCount++; if (a[i] > a[j]) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } } } System.out

need help designing for search algorithm in a more efficient way

十年热恋 提交于 2019-12-04 05:17:45
I have a problem that involves biology area. Right now I have 4 VERY LARGE files(each with 0.1 billion lines), but the structure is rather simple, each line of these files has only 2 fields, both stands for a type of gene. My goal is: design an efficient algorithm that can achieves the following: Find a circle within the contents of these 4 files. The circle is defined as: field #1 in a line in file 1 == field #1 in a line in file 2 and field #2 in a line in file 2 == field #1 in a line in file 3 and field #2 in a line in file 3 == field #1 in a line in file 4 and field #2 in a line in file 4

In Complexity Analysis why is ++ considered to be 2 operations?

蹲街弑〆低调 提交于 2019-12-04 03:33:53
问题 In my Computer Science II class, the professor considers ++,--,*=, etc. to be 2 operations. However, at the Assembly level this is not really two operations. Can someone explain or is this just for the sake of simplicity? 回答1: I'd actually consider it to be 3 operations: read, increment (or whatever), write. That's assuming it's reading from some sort of shared memory into some sort of local storage (e.g. register or stack), operating on the local storage, then writing back. How many

What is complexity of size() for TreeSet portion view in Java

雨燕双飞 提交于 2019-12-04 03:01:56
问题 I'm wondering what is the time complexity of size() for portion view of TreeSet. Let say I'm adding random numbers to set (and I do not care about duplicities): final TreeSet<Integer> tree = new TreeSet<Integer>(); final Random r = new Random(); final int N = 1000; for ( int i = 0; i < N; i++ ) { tree.add( r.nextInt() ); } and now I'm wodering what is complexity for size() calls as: final int M = 100; for ( int i = 0; i < M; i++ ) { final int f = r.nextInt(); final int t = r.nextInt(); System