complexity-theory

Combat strategy for ants

梦想与她 提交于 2019-12-03 09:00:55
问题 This question refers to the Google-sponsored AI Challenge, a contest that happens every few months and in which the contenders need to submit a bot able to autonomously play a game against other robotic players. The competition that just closed was called "ants" and you can read all its specification here, if you are interested. My question is specific to one aspect of ants : combat strategy. The problem Given a grid of discrete coordinates [like a chessboard] and given that each player has a

convex hull algorithm for 3d surface z = f(x, y)

故事扮演 提交于 2019-12-03 08:52:07
I have a 3D surface given as a set of triples (x_i, y_i, z_i), where x_i and y_i are roughly on a grid, and each (x_i, y_i) has a single associated z_i value. The typical grid is 20x20 I need to find which points belong to the convex hull of the surface, within a given tolerance. I'm looking for an efficient algorithm to perform the computation (my customer has provided an O(n³) version, which takes ~10s on a 400 point dataset...) There's quite a lot out there, didn't you search? Here are a couple with O( n log h ) runtime, where n is number of input points and h is number of vertices of the

Why is the Big-O complexity of this algorithm O(n^2)?

社会主义新天地 提交于 2019-12-03 08:04:28
问题 I know the big-O complexity of this algorithm is O(n^2) , but I cannot understand why. int sum = 0; int i = 1; j = n * n; while (i++ < j--) sum++; Even though we set j = n * n at the beginning, we increment i and decrement j during each iteration, so shouldn't the resulting number of iterations be a lot less than n*n ? 回答1: During every iteration you increment i and decrement j which is equivalent to just incrementing i by 2. Therefore, total number of iterations is n^2 / 2 and that is still

Finding the closest fibonacci numbers

对着背影说爱祢 提交于 2019-12-03 08:03:55
问题 I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations. I need to compute for a given number N, the interval [P, Q], where P is the biggest fibonacci number that is <= to N, and Q is the smallest fibonacci number that is >= to N. Currently, I am using a map to record the value of the fibonacci numbers. A query normally involves searching all the fibonacci numbers up to N, and it is not very time efficient, as it involves a

Cyclomatic Complexity in piece of code with multiple exit points

走远了吗. 提交于 2019-12-03 08:01:08
I have this method that validates a password: /** * Checks if the given password is valid. * * @param password The password to validate. * @return {@code true} if the password is valid, {@code false} otherwise. */ public static boolean validatePassword(String password) { int len = password.length(); if (len < 8 || len > 20) return false; boolean hasLetters = false; boolean hasDigits = false; for (int i=0; i<len; i++) { if (!Character.isLetterOrDigit(password.charAt(i))) return false; hasDigits = hasDigits || Character.isDigit(password.charAt(i)); hasLetters = hasLetters || Character.isLetter

Directed maximum weighted bipartite matching allowing sharing of start/end vertices

谁说我不能喝 提交于 2019-12-03 07:48:21
问题 Let G (U u V, E) be a weighted directed bipartite graph (i.e. U and V are the two sets of nodes of the bipartite graph and E contains directed weighted edges from U to V or from V to U). Here is an example: In this case: U = {A,B,C} V = {D,E,F} E = {(A->E,7), (B->D,1), (C->E,3), (F->A,9)} Definition: DirectionalMatching (I made up this term just to make things clearer): set of directed edges that may share the start or end vertices. That is, if U->V and U'->V' both belong to a

Analyzing an algorithm with recurrence T(n) = T(n - 1) + T(n - 2) + T(n -3)?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 06:23:32
问题 So, someone posted this question earlier, but essentially no effort was put into it, it was poorly tagged and then closed. Nonetheless, I think it could have been a good question. I'm posting because according to the OP, my answer (posted in a comment) did not agree with the solution. So, I'm trying to figure out what I'm doing incorrectly (assuming that the answer that he has in indeed correct): We have: T(N) = T(N-1) + T(N-2) + T(N-3) where N > 3. He didn't have a base case listed, but

Big O for worst-case running time and Ω is for the best-case, but why is Ω used in worst case sometimes?

假装没事ソ 提交于 2019-12-03 06:23:22
问题 I'm confused, I thought that you use Big O for worst-case running time and Ω is for the best-case? Can someone please explain? And isn't (lg n) the best-case? and (nlg n) is the worst case? Or am I misunderstanding something? Show that the worst-case running time of Max-Heapify on a heap of size n is Ω(lg n). ( Hint: For a heap with n nodes, give node values that cause Max-Heapify to be called recursively at every node on a path from the root down to a leaf.) Edit: no this is not homework. im

Complexity of a Lucene's search

偶尔善良 提交于 2019-12-03 05:57:34
If I write and algorithm that performs a search using Lucene how can I state the computational complexity of it? I know that Lucene uses tf*idf scoring but I don't know how it is implemented. I've found that tf*idf has the following complexity: O(|D|+|T|) where D is the set of documents and T the set of all terms. However, I need someone who could check if this is correct and explain me why. Thank you Lucene basically uses a Vector Space Model (VSM) with a tf-idf scheme. So, in the standard setting we have: A collection of documents each represented as a vector A text query also represented as

What is the big-O of the function (log n)^k

﹥>﹥吖頭↗ 提交于 2019-12-03 05:17:13
What is the big-O complexity of the function (log n) k for any k? Any function whose runtime has the form (log n) k is O((log n) k ). This expression isn't reducable to any other primitive function using simple transformations, and it's fairly common to see algorithms with runtimes like O(n (log n) 2 ). Functions with this growth rate are called polylogarithmic. By the way, typically (log n) k is written as log k n, so the above algorithm would have runtime O(n log 2 n. In your case, the function log 2 n + log n would be O(log 2 n). However, any function with runtime of the form log (n k ) has